From 3549abe81df2a8a2757c37990e19db213725878e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Fri, 28 Jun 2019 12:12:46 +0200 Subject: [PATCH] dnstap-read: clear buffer before expanding it 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. --- bin/tests/system/dnstap/README | 20 ++++++++++++++++++++ bin/tests/system/dnstap/large-answer.fstrm | Bin 0 -> 981 bytes bin/tests/system/dnstap/tests.sh | 9 +++++++++ bin/tools/dnstap-read.c | 1 + util/copyrights | 2 ++ 5 files changed, 32 insertions(+) create mode 100644 bin/tests/system/dnstap/README create mode 100644 bin/tests/system/dnstap/large-answer.fstrm diff --git a/bin/tests/system/dnstap/README b/bin/tests/system/dnstap/README new file mode 100644 index 0000000000..f4cb38569a --- /dev/null +++ b/bin/tests/system/dnstap/README @@ -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 index 0000000000000000000000000000000000000000..873b3159c079e1039c5d5862674d1ee1bbe5370a GIT binary patch literal 981 zcmZY8yG{a85P;#cyWCk7QE*j6T=4>|D7)-raLD+jeQwF1feCkQ!4B#f%Mi{1qktZ&LhxRky@pI9O{}>&>&8sC4_!Z~pq- z;K6cxf&SOcwfwv&cPPJ4!HoF2EMN2HWsD rEDs|0b4w`^5k@DzKY09j+Q=52^ikryTQ1jM4hkK;?H#TcKAGA#%=~y| literal 0 HcmV?d00001 diff --git a/bin/tests/system/dnstap/tests.sh b/bin/tests/system/dnstap/tests.sh index 1396995026..83877b102f 100644 --- a/bin/tests/system/dnstap/tests.sh +++ b/bin/tests/system/dnstap/tests.sh @@ -736,5 +736,14 @@ EOF status=`expr $status + $ret` 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 diff --git a/bin/tools/dnstap-read.c b/bin/tools/dnstap-read.c index 2548bf0fac..94fc49a01c 100644 --- a/bin/tools/dnstap-read.c +++ b/bin/tools/dnstap-read.c @@ -155,6 +155,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) { diff --git a/util/copyrights b/util/copyrights index aa2f95cee5..835d7db1aa 100644 --- a/util/copyrights +++ b/util/copyrights @@ -558,7 +558,9 @@ ./bin/tests/system/dnssec/signer/general/bogus-ksk.key X 2018,2019 ./bin/tests/system/dnssec/signer/general/bogus-zsk.key X 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/clean.sh SH 2015,2016,2017,2018,2019 +./bin/tests/system/dnstap/large-answer.fstrm X 2019 ./bin/tests/system/dnstap/setup.sh SH 2018,2019 ./bin/tests/system/dnstap/tests.sh SH 2015,2016,2017,2018,2019 ./bin/tests/system/dnstap/ydump.py PYTHON 2016,2017,2018,2019