From 494e4b32502a9232cc429cde08dc9879c56786ff Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 29 Oct 2024 16:45:41 +1100 Subject: [PATCH] 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. --- bin/tests/system/digdelv/tests.sh | 13 +++++++++++++ lib/dns/message.c | 25 +++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/bin/tests/system/digdelv/tests.sh b/bin/tests/system/digdelv/tests.sh index cc26d8e0bc..8a0293f32d 100644 --- a/bin/tests/system/digdelv/tests.sh +++ b/bin/tests/system/digdelv/tests.sh @@ -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 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) {