]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Make DNS report failure on all packet construction errors
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 5 Mar 2011 06:00:08 +0000 (23:00 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 5 Mar 2011 06:00:08 +0000 (23:00 -0700)
The attached patch alters the DNS lookup behaviour to abort with an error
in ALL cases where the rfc1035 library generates an error (negative result).

I'm not sure there is any noticable effect other than better code. The
error case *should* in old code be picked up on the initial packet
construction rather than the repeat packet. This may have been incorrect
given that the packet type is changing between A/AAAA.

src/dns_internal.cc

index 3efcdb97f667a02051cff88f6763f29bd97ffc47..0ae75991bf74feb9f17f0197de4b4cf1d297b2e7 100644 (file)
@@ -124,7 +124,7 @@ struct _idns_query {
     char buf[RESOLV_BUFSZ];
     char name[NS_MAXDNAME + 1];
     char orig[NS_MAXDNAME + 1];
-    size_t sz;
+    ssize_t sz;
     unsigned short msg_id; /// random query ID sent to server; changes with every query sent
     InstanceId<idns_query> xact_id; /// identifies our "transaction", stays constant when query is retried
 
@@ -1145,6 +1145,14 @@ idnsGrokReply(const char *buf, size_t sz, int from_ns)
                 // see EDNS notes at top of file why this sends 0
                 q->sz = rfc3596BuildAQuery(q->name, q->buf, sizeof(q->buf), 0, &q->query, 0);
             }
+
+            if (q->sz < 0) {
+                /* problem with query data -- query not sent */
+                idnsCallback(q->callback_data, NULL, 0, "Internal error");
+                cbdataFree(q);
+                return;
+            }
+
             idnsCacheQuery(q);
             idnsSendQuery(q);
             return;
@@ -1181,6 +1189,14 @@ idnsGrokReply(const char *buf, size_t sz, int from_ns)
         // see EDNS notes at top of file why this sends 0
         q->sz = rfc3596BuildAQuery(q->name, q->buf, sizeof(q->buf), 0, &q->query, 0);
         q->need_A = false;
+
+        if (q->sz < 0) {
+            /* problem with query data -- query not sent */
+            idnsCallback(q->callback_data, NULL, 0, "Internal error");
+            cbdataFree(q);
+            return;
+        }
+
         idnsCacheQuery(q);
         idnsSendQuery(q);
         return;