YAML escape EDNS EDE option EXTRA-TEXT value

The description in the EXTRA-TEXT field of the EDE option needs
to be escaped to ensure that the emitted message is valid YAML.
This commit is contained in:
Mark Andrews
2025-02-26 15:22:58 +11:00
parent f2da76bbb5
commit 494e4b3250
2 changed files with 32 additions and 6 deletions
+13
View File
@@ -748,6 +748,19 @@ if [ -x "$DIG" ]; then
if [ $ret -ne 0 ]; then echo_i "failed"; fi
status=$((status + ret))
if [ $HAS_PYYAML -ne 0 ]; then
n=$((n + 1))
echo_i "check that Extended DNS Error 0 is printed correctly +yaml ($n)"
ret=0
# add specials '"' and '\'
dig_with_opts @10.53.0.3 +yaml +ednsopt=ede:0000666f6f225c a.example +qr >dig.out.test$n 2>&1 || ret=1
$PYTHON yamlget.py dig.out.test$n 0 message query_message_data OPT_PSEUDOSECTION EDNS EDE EXTRA-TEXT >yamlget.out.test$n 2>&1 || ret=1
read -r value <yamlget.out.test$n
[ "$value" = 'foo"\' ] || ret=1
if [ $ret -ne 0 ]; then echo_i "failed"; fi
status=$((status + ret))
fi
n=$((n + 1))
echo_i "check that Extended DNS Error 24 is printed correctly ($n)"
ret=0
+19 -6
View File
@@ -3900,19 +3900,32 @@ dns_message_pseudosectiontoyaml(dns_message_t *msg, dns_pseudosection_t section,
} else {
ADD_STRING(target, "\"");
}
if (isc_buffer_availablelength(target) < optlen)
{
result = ISC_R_NOSPACE;
goto cleanup;
}
for (i = 0; i < optlen; i++) {
if (isprint(optdata[i]) ||
(utf8ok && optdata[i] > 127))
{
/*
* We are emitting a yaml '"'
* delimited string so we need
* to escape '"' and '\'.
*/
if (extra_text &&
(optdata[i] == '"' ||
optdata[i] == '\\'))
{
ADD_STRING(target,
"\\");
}
if (isc_buffer_availablelength(
target) < 1)
{
result = ISC_R_NOSPACE;
goto cleanup;
}
isc_buffer_putmem(
target, &optdata[i], 1);
} else {
isc_buffer_putstr(target, ".");
ADD_STRING(target, ".");
}
}
if (!extra_text) {