]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
dig +bufsize=0 failed to disable EDNS as a side effect.
authorMark Andrews <marka@isc.org>
Wed, 29 Jul 2020 02:34:54 +0000 (12:34 +1000)
committerMark Andrews <marka@isc.org>
Wed, 2 Sep 2020 10:47:19 +0000 (20:47 +1000)
(cherry picked from commit 0dc04cb901197d10a7ce90fd4bc0ef228a7b3171)

CHANGES
bin/dig/dig.c
bin/dig/dig.docbook
bin/dig/dighost.c
bin/dig/include/dig/dig.h
bin/dig/nslookup.c
bin/tests/system/digdelv/tests.sh

diff --git a/CHANGES b/CHANGES
index 40a56132cedb30730fdf526061ab34fc9d82e497..28a6e478749690da425de8af20578d97621e2501 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+5497.  [bug]           dig +bufsize=0 failed to disable EDNS as a side
+                       effect. [GL #2054]
+
 5496.  [bug]           The rate limiter needs to hold a reference to its task.
                        [GL #2081]
 
index 996cbb9495ccbfd7c7905a0463b765d4c5521b35..32e5c670636d168f0ca7487085c7f184c3d8d7ce 100644 (file)
@@ -173,7 +173,7 @@ help(void) {
 "                 +[no]authority      (Control display of authority section)\n"
 "                 +[no]badcookie      (Retry BADCOOKIE responses)\n"
 "                 +[no]besteffort     (Try to parse even illegal messages)\n"
-"                 +bufsize=###        (Set EDNS0 Max UDP packet size)\n"
+"                 +bufsize[=###]      (Set EDNS0 Max UDP packet size)\n"
 "                 +[no]cdflag         (Set checking disabled flag in query)\n"
 "                 +[no]class          (Control display of class in records)\n"
 "                 +[no]cmd            (Control display of command line -\n"
@@ -895,15 +895,21 @@ plus_option(const char *option, bool is_batchfile,
                        break;
                case 'u':/* bufsize */
                        FULLCHECK("bufsize");
-                       if (value == NULL)
-                               goto need_value;
-                       if (!state)
+                       if (!state) {
                                goto invalid_option;
+                       }
+                       if (value == NULL) {
+                               lookup->udpsize = DEFAULT_EDNS_BUFSIZE;
+                               break;
+                       }
                        result = parse_uint(&num, value, COMMSIZE,
                                            "buffer size");
                        if (result != ISC_R_SUCCESS)
                                fatal("Couldn't parse buffer size");
                        lookup->udpsize = num;
+                       if (lookup->udpsize == 0) {
+                               lookup->edns = -1;
+                       }
                        break;
                default:
                        goto invalid_option;
@@ -941,8 +947,9 @@ plus_option(const char *option, bool is_batchfile,
                                break;
                        case 'o': /* cookie */
                                FULLCHECK("cookie");
-                               if (state && lookup->edns == -1)
-                                       lookup->edns = 0;
+                               if (state && lookup->edns == -1) {
+                                       lookup->edns = DEFAULT_EDNS_VERSION;
+                               }
                                lookup->sendcookie = state;
                                if (value != NULL) {
                                        n = strlcpy(hexcookie, value,
@@ -975,8 +982,9 @@ plus_option(const char *option, bool is_batchfile,
                        break;
                case 'n': /* dnssec */
                        FULLCHECK("dnssec");
-                       if (state && lookup->edns == -1)
-                               lookup->edns = 0;
+                       if (state && lookup->edns == -1) {
+                               lookup->edns = DEFAULT_EDNS_VERSION;
+                       }
                        lookup->dnssec = state;
                        break;
                case 'o': /* domain */
@@ -1019,7 +1027,8 @@ plus_option(const char *option, bool is_batchfile,
                                                        break;
                                                }
                                                if (value == NULL) {
-                                                       lookup->edns = 0;
+                                                       lookup->edns =
+                                                               DEFAULT_EDNS_VERSION;
                                                        break;
                                                }
                                                result = parse_uint(&num,
@@ -1180,8 +1189,9 @@ plus_option(const char *option, bool is_batchfile,
                        switch (cmd[2]) {
                        case 'i': /* nsid */
                                FULLCHECK("nsid");
-                               if (state && lookup->edns == -1)
-                                       lookup->edns = 0;
+                               if (state && lookup->edns == -1) {
+                                       lookup->edns = DEFAULT_EDNS_VERSION;
+                               }
                                lookup->nsid = state;
                                break;
                        case 's': /* nssearch */
@@ -1385,8 +1395,9 @@ plus_option(const char *option, bool is_batchfile,
                                }
                                break;
                        }
-                       if (lookup->edns == -1)
-                               lookup->edns = 0;
+                       if (lookup->edns == -1) {
+                               lookup->edns = DEFAULT_EDNS_VERSION;
+                       }
                        if (lookup->ecs_addr != NULL) {
                                isc_mem_free(mctx, lookup->ecs_addr);
                                lookup->ecs_addr = NULL;
@@ -1926,7 +1937,7 @@ parse_args(bool is_batchfile, bool config_only,
                debug("making new lookup");
                default_lookup = make_empty_lookup();
                default_lookup->adflag = true;
-               default_lookup->edns = 0;
+               default_lookup->edns = DEFAULT_EDNS_VERSION;
                default_lookup->sendcookie = true;
 
 #ifndef NOPOSIX
index 57ff556d49d8e0cfd53b3e0ca03258b582e063c7..456d1a88fe9331c01cb446acf2090635d8581d82 100644 (file)
          <term><option>+bufsize=B</option></term>
          <listitem>
            <para>
-             Set the UDP message buffer size advertised using EDNS0
-             to <parameter>B</parameter> bytes.  The maximum and
-             minimum sizes of this buffer are 65535 and 0 respectively.
-             Values outside this range are rounded up or down
-             appropriately.  Values other than zero will cause a
-             EDNS query to be sent.
+              This option sets the UDP message buffer size advertised
+              using EDNS0 to <parameter>B</parameter> bytes.  The
+              maximum and minimum sizes of this buffer are 65535
+              and 0, respectively.  <literal>+bufsize=0</literal>
+              disables EDNS (use <literal>+bufsize=0 +edns</literal>
+              to send a EDNS messages with a advertised size of 0
+              bytes). <literal>+bufsize</literal> restores the
+              default buffer size.
            </para>
          </listitem>
        </varlistentry>
index 8551459078cbeafa2603048ccf7ce04337bb2930..e82f176d98479977c8b1b3cce6df68934b7b6df8 100644 (file)
@@ -846,7 +846,7 @@ make_empty_lookup(void) {
        looknew->rdclass_sigchaseset = false;
 #endif
 #endif
-       looknew->udpsize = 0;
+       looknew->udpsize = -1;
        looknew->edns = -1;
        looknew->recurse = true;
        looknew->aaonly = false;
@@ -2641,10 +2641,12 @@ setup_lookup(dig_lookup_t *lookup) {
                unsigned int flags;
                unsigned int i = 0;
 
-               if (lookup->udpsize == 0)
-                       lookup->udpsize = 4096;
-               if (lookup->edns < 0)
-                       lookup->edns = 0;
+               if (lookup->udpsize < 0) {
+                       lookup->udpsize = DEFAULT_EDNS_BUFSIZE;
+               }
+               if (lookup->edns < 0) {
+                       lookup->edns = DEFAULT_EDNS_VERSION;
+               }
 
                if (lookup->nsid) {
                        INSIST(i < MAXOPTS);
index cc37c55db51c67b2f2574ce11c307efe65beea2d..1ced573a50fdc5bba4b5cab8612552f050eadd10 100644 (file)
 #define SERVER_TIMEOUT 1
 
 #define LOOKUP_LIMIT 64
+
+#define DEFAULT_EDNS_VERSION 0
+#define DEFAULT_EDNS_BUFSIZE 4096
+
 /*%
  * Lookup_limit is just a limiter, keeping too many lookups from being
  * created.  It's job is mainly to prevent the program from running away
@@ -180,7 +184,7 @@ bool        sigchase;
        dig_query_t *xfr_q;
        uint32_t retries;
        int nsfound;
-       uint16_t udpsize;
+       int16_t udpsize;
        int16_t edns;
        uint32_t ixfr_serial;
        isc_buffer_t rdatabuf;
index d8c3b380806de45df1b9af1ea0c239d2348a3dc0..8a3a84244b35b9767567611ac490a40c2f51f478 100644 (file)
@@ -808,7 +808,6 @@ addlookup(char *opt) {
        lookup->recurse = recurse;
        lookup->aaonly = aaonly;
        lookup->retries = tries;
-       lookup->udpsize = 0;
        lookup->comments = comments;
        if (lookup->rdtype == dns_rdatatype_any && !tcpmode_set)
                lookup->tcp_mode = true;
index 3d1010e1b77d0eb49751e96c92ebff499ae4019c..31107f89c829deebe8843e9153233fa24c140a83 100644 (file)
@@ -649,8 +649,34 @@ ret=0
   pat='^;-m\..*IN.*A$'
   tr -d '\r' < dig.out.test$n | grep "$pat" > /dev/null || ret=1
   grep "Dump of all outstanding memory allocations" dig.out.test$n > /dev/null && ret=1
-  if [ $ret != 0 ]; then echo_i "failed"; fi
+  if [ $ret -ne 0 ]; then echo_i "failed"; fi
+  status=`expr $status + $ret`
+
+  n=$((n+1))
+  echo_i "check that dig +bufsize=0 disables EDNS ($n)"
+  ret=0
+  $DIG $DIGOPTS @10.53.0.3 a.example +bufsize=0 +qr > dig.out.test$n 2>&1 || ret=1
+  grep "EDNS:" dig.out.test$n > /dev/null && ret=1
+  if [ $ret -ne 0 ]; then echo_i "failed"; fi
+  status=`expr $status + $ret`
+
+  n=$((n+1))
+  echo_i "check that dig +bufsize=0 +edns sends EDNS with bufsize of 0 ($n)"
+  ret=0
+  $DIG $DIGOPTS @10.53.0.3 a.example +bufsize=0 +edns +qr > dig.out.test$n 2>&1 || ret=1
+  grep -E 'EDNS:.* udp: 0\r{0,1}$' dig.out.test$n > /dev/null|| ret=1
+  if [ $ret -ne 0 ]; then echo_i "failed"; fi
   status=`expr $status + $ret`
+
+  n=$((n+1))
+  echo_i "check that dig +bufsize restores default bufsize ($n)"
+  ret=0
+  $DIG $DIGOPTS @10.53.0.3 a.example +bufsize=0 +bufsize +qr > dig.out.test$n 2>&1 || ret=1
+  lines=`grep "EDNS:.* udp: 4096" dig.out.test$n | wc -l`
+  test $lines -eq 2 || ret=1
+  if [ $ret -ne 0 ]; then echo_i "failed"; fi
+  status=`expr $status + $ret`
+
 else
   echo_i "$DIG is needed, so skipping these dig tests"
 fi