]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Suppress the dig startup banner in +yaml error output
authorMartin Basti <mbasti@isc.org>
Wed, 15 Jul 2026 16:58:39 +0000 (18:58 +0200)
committerMartin Basti <mbasti@isc.org>
Tue, 21 Jul 2026 19:28:09 +0000 (21:28 +0200)
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
bin/dig/dighost.c
bin/tests/system/digdelv/tests.sh

index 0ad6cd7d0ef1f84f9526f54eb6b2a1bb29e36828..cdc925e6c8ed9f979f425ffaa491e33c7e02213b 100644 (file)
@@ -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) {
index 7cccfeb73ab4a5b3f076ce76a269d5119bf8a622..85247c17e4cf2c75baddf232b978e4cbdf1310b2 100644 (file)
@@ -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 <yamlget.out.test$n
+    [ "$value" = "DIG_ERROR" ] || ret=1
+    if [ $ret -ne 0 ]; then echo_i "failed"; fi
+    status=$((status + ret))
   fi
 
   n=$((n + 1))