]> granicus.if.org Git - pdns/commitdiff
rec: Treat requestor's payload size lower than 512 as equal to 512
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 22 Jun 2017 08:25:47 +0000 (10:25 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 22 Jun 2017 13:04:10 +0000 (15:04 +0200)
(cherry picked from commit 320157487ec1cd0a9c4bcfd5309d9d651c26eb72)

pdns/pdns_recursor.cc

index 67c9aedd461b66d75475e8c50f3dcf94227a6c5f..0b7bbd44d45b1b9588ac8433cf3cb3d3387a5645 100644 (file)
@@ -694,12 +694,16 @@ void startDoResolve(void *p)
     if (t_queryring)
       t_queryring->push_back(make_pair(dc->d_mdp.d_qname, dc->d_mdp.d_qtype));
 
-    uint32_t maxanswersize= dc->d_tcp ? 65535 : min((uint16_t) 512, g_udpTruncationThreshold);
+    uint16_t maxanswersize = dc->d_tcp ? 65535 : min(static_cast<uint16_t>(512), g_udpTruncationThreshold);
     EDNSOpts edo;
     bool haveEDNS=false;
     if(getEDNSOpts(dc->d_mdp, &edo)) {
-      if(!dc->d_tcp)
-       maxanswersize = min(edo.d_packetsize, g_udpTruncationThreshold);
+      if(!dc->d_tcp) {
+        /* rfc6891 6.2.3:
+           "Values lower than 512 MUST be treated as equal to 512."
+        */
+        maxanswersize = min(static_cast<uint16_t>(edo.d_packetsize >= 512 ? edo.d_packetsize : 512), g_udpTruncationThreshold);
+      }
       dc->d_ednsOpts = edo.d_options;
       haveEDNS=true;
 
@@ -1086,7 +1090,7 @@ void startDoResolve(void *p)
        if(i->d_type != QType::OPT) // their TTL ain't real
          minTTL = min(minTTL, i->d_ttl);
        i->d_content->toPacket(pw);
-       if(pw.size() > maxanswersize) {
+       if(pw.size() > static_cast<size_t>(maxanswersize)) {
          pw.rollback();
          if(i->d_place==DNSResourceRecord::ANSWER)  // only truncate if we actually omitted parts of the answer
             {