]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Make DNS report failure on all packet construction errors
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 3 Apr 2011 11:04:25 +0000 (05:04 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 3 Apr 2011 11:04:25 +0000 (05:04 -0600)
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 aa7f187f5c8bdad6f78945648f6951f0eb52d323..4bd88db07d8257bc3df7aa6b75723fdb1e6d1b51 100644 (file)
@@ -103,7 +103,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 id;
     int nsends;
     int need_vc;
@@ -1050,6 +1050,14 @@ idnsGrokReply(const char *buf, size_t sz)
                 debugs(78, 3, "idnsGrokReply: Trying A Query for " << q->name);
                 q->sz = rfc3596BuildAQuery(q->name, q->buf, sizeof(q->buf), q->id, &q->query);
             }
+
+            if (q->sz < 0) {
+                /* problem with query data -- query not sent */
+                idnsCallback(static_cast<idns_query *>(q->callback_data), NULL, 0, "Internal error");
+                cbdataFree(q);
+                return;
+            }
+
             idnsCacheQuery(q);
             idnsSendQuery(q);
             return;
@@ -1088,6 +1096,14 @@ idnsGrokReply(const char *buf, size_t sz)
         rfc1035SetQueryID(q->buf, q->id);
         q->sz = rfc3596BuildAQuery(q->name, q->buf, sizeof(q->buf), q->id, &q->query);
         q->need_A = false;
+
+        if (q->sz < 0) {
+            /* problem with query data -- query not sent */
+            idnsCallback(static_cast<idns_query *>(q->callback_data), NULL, 0, "Internal error");
+            cbdataFree(q);
+            return;
+        }
+
         idnsCacheQuery(q);
         idnsSendQuery(q);
         return;