From: Martin Basti Date: Wed, 15 Jul 2026 16:58:39 +0000 (+0200) Subject: Suppress the dig startup banner in +yaml error output X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4d164b148c6eb78d420908fb7718f3df4354573a;p=thirdparty%2Fbind9.git Suppress the dig startup banner in +yaml error output The two "no servers could be reached" error paths printed the lookup's startup banner (";"-prefixed "<<>> DiG ..." lines) ahead of the "- type: DIG_ERROR" block. Those lines are not valid YAML, so with +yaml the whole output failed to parse whenever every server was unreachable. Guard the banner with the existing yaml flag, matching how the successful path in printmessage() already gates it. Assisted-by: Claude:claude-opus-4-8 --- diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 0ad6cd7d0ef..cdc925e6c8e 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -3308,6 +3308,17 @@ try_next_server(dig_lookup_t *lookup) { return true; } +/* + * Print the lookup's startup banner. It is skipped in +yaml mode, where + * the ";"-prefixed banner is not valid YAML and would corrupt the output. + */ +static void +print_cmdline(const dig_lookup_t *l) { + if (!yaml) { + printf("%s", l->cmdline); + } +} + static void force_next(dig_query_t *query) { dig_lookup_t *l = NULL; @@ -3350,7 +3361,7 @@ force_next(dig_query_t *query) { dighost_error("no response from %s", buf); } else { - printf("%s", l->cmdline); + print_cmdline(l); dighost_error("no servers could be reached"); } @@ -4018,7 +4029,7 @@ recv_done(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region, * Otherwise, print the cmdline and an error message, * and cancel the lookup. */ - printf("%s", l->cmdline); + print_cmdline(l); dighost_error("no servers could be reached"); if (exitcode < 9) { diff --git a/bin/tests/system/digdelv/tests.sh b/bin/tests/system/digdelv/tests.sh index 7cccfeb73ab..85247c17e4c 100644 --- a/bin/tests/system/digdelv/tests.sh +++ b/bin/tests/system/digdelv/tests.sh @@ -1229,6 +1229,23 @@ if [ -x "$DIG" ]; then [ "$value" = "d.example. 300 IN AAAA fd92:7065:b8e:ffff::0" ] || ret=1 if [ $ret -ne 0 ]; then echo_i "failed"; fi status=$((status + ret)) + + # When all servers fail (here: a UDP query that times out with no + # response), dig must not emit the ";"-prefixed startup banner ahead of + # the "- type: DIG_ERROR" block, as that would make the +yaml output + # invalid YAML. The query name is deliberately placed before +yaml on the + # command line: that is what makes dig build the banner (while +cmd is + # still in effect) before switching to YAML output, which is the ordering + # that regressed. + n=$((n + 1)) + echo_i "check that dig +yaml produces valid YAML when no servers could be reached ($n)" + ret=0 + dig_with_opts silent.example @10.53.0.7 +notcp +timeout=1 +tries=1 +yaml >dig.out.test$n 2>&1 && ret=1 + $PYTHON yamlget.py dig.out.test$n 0 type >yamlget.out.test$n 2>&1 || ret=1 + read -r value