]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
dnstap-read: clear buffer before expanding it
authorMichał Kępień <michal@isc.org>
Fri, 28 Jun 2019 10:12:46 +0000 (12:12 +0200)
committerMichał Kępień <michal@isc.org>
Fri, 28 Jun 2019 10:45:44 +0000 (12:45 +0200)
When printing a packet, dnstap-read checks whether its text form takes
up more than the 2048 bytes allocated for the output buffer by default.
If that is the case, the output buffer is automatically expanded, but
the truncated output is left in the buffer, resulting in malformed data
being printed.  Clear the output buffer before expanding it to prevent
this issue from occurring.

(cherry picked from commit 3549abe81df2a8a2757c37990e19db213725878e)

bin/tests/system/dnstap/README [new file with mode: 0644]
bin/tests/system/dnstap/large-answer.fstrm [new file with mode: 0644]
bin/tests/system/dnstap/tests.sh
bin/tools/dnstap-read.c
util/copyrights

diff --git a/bin/tests/system/dnstap/README b/bin/tests/system/dnstap/README
new file mode 100644 (file)
index 0000000..f4cb385
--- /dev/null
@@ -0,0 +1,20 @@
+Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+
+See COPYRIGHT in the source root or http://isc.org/copyright.html for terms.
+
+The "large-answer.fstrm" file was generated by configuring a named instance
+compiled with --enable-dnstap and --enable-fixed-rrset with the following
+directives:
+
+    minimal-responses yes;
+    rrset-order { order fixed; };
+    dnstap { auth response; };
+    dnstap-identity none;
+    dnstap-output file "large-answer.fstrm";
+
+The captured RRset from the "example." zone was created using:
+
+    $GENERATE 1-48 @ IN A 127.0.0.$
+
+A server instance set up this way was then queried non-recursively (RD=0) for
+"example/A".
diff --git a/bin/tests/system/dnstap/large-answer.fstrm b/bin/tests/system/dnstap/large-answer.fstrm
new file mode 100644 (file)
index 0000000..873b315
Binary files /dev/null and b/bin/tests/system/dnstap/large-answer.fstrm differ
index 3e3aaa918d84251e98436be6a41e25581ca93d80..b46fb929de2068d3b8a59b38ff4511b3c68cda16 100644 (file)
@@ -587,5 +587,14 @@ if [ -n "$FSTRM_CAPTURE" ] ; then
        }
 fi
 
+echo_i "checking large packet printing"
+ret=0
+# Expect one occurrence of "opcode: QUERY" below "reponse_message_data" and
+# another one below "response_message".
+lines=`$DNSTAPREAD -y large-answer.fstrm | grep -c "opcode: QUERY"`
+[ $lines -eq 2 ] || ret=1
+if [ $ret != 0 ]; then echo_i "failed"; fi
+status=`expr $status + $ret`
+
 echo_i "exit status: $status"
 [ $status -eq 0 ] || exit 1
index 49dbb9b5c0b0f2e23196859922ec8bfe4f6d8766..70ae7ebeb3a280cac398653203c722ff86763b2e 100644 (file)
@@ -127,6 +127,7 @@ print_packet(dns_dtdata_t *dt, const dns_master_style_t *style) {
 
                        result = dns_message_totext(dt->msg, style, 0, b);
                        if (result == ISC_R_NOSPACE) {
+                               isc_buffer_clear(b);
                                textlen *= 2;
                                continue;
                        } else if (result == ISC_R_SUCCESS) {
index 10ba42a46900aa3b9f0d2c2398ceda38421e98eb..7fae33a59cae74cacedafd335bd3881c0d723232 100644 (file)
 ./bin/tests/system/dnssec/signer/remove.db.in  ZONE    2016,2018,2019
 ./bin/tests/system/dnssec/signer/remove2.db.in ZONE    2016,2018,2019
 ./bin/tests/system/dnssec/tests.sh             SH      2000,2001,2002,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019
+./bin/tests/system/dnstap/README               TXT.BRIEF       2019
 ./bin/tests/system/dnstap/bad-fstrm-set-buffer-hint-max.conf   CONF-C  2016,2018,2019
 ./bin/tests/system/dnstap/bad-fstrm-set-buffer-hint-min.conf   CONF-C  2016,2018,2019
 ./bin/tests/system/dnstap/bad-fstrm-set-flush-timeout-max.conf CONF-C  2016,2018,2019
 ./bin/tests/system/dnstap/good-fstrm-set-output-queue-model-spsc.conf  CONF-C  2016,2018,2019
 ./bin/tests/system/dnstap/good-fstrm-set-output-queue-size.conf        CONF-C  2016,2018,2019
 ./bin/tests/system/dnstap/good-fstrm-set-reopen-interval.conf  CONF-C  2016,2018,2019
+./bin/tests/system/dnstap/large-answer.fstrm   X       2019
 ./bin/tests/system/dnstap/ns1/named.conf.in    CONF-C  2018,2019
 ./bin/tests/system/dnstap/ns1/root.db          ZONE    2015,2016,2018,2019
 ./bin/tests/system/dnstap/ns2/example.db       ZONE    2015,2016,2018,2019