]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
DW:
authorwessels <>
Fri, 12 May 2000 04:20:57 +0000 (04:20 +0000)
committerwessels <>
Fri, 12 May 2000 04:20:57 +0000 (04:20 +0000)
 - Jens-S reports internal DNS code happily resolves ".foo.com" while
   external DNS gives an error.  This patch makes internal DNS return
   a "the domain name does not exist" error message.

lib/rfc1035.c
src/dns_internal.cc

index 975e4528e7f1d1ccb9ac25a06a809f843e673f31..87d56635d2d05ca65d62fcc3d5c36ea88343ca8d 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: rfc1035.c,v 1.14 2000/03/27 21:56:21 wessels Exp $
+ * $Id: rfc1035.c,v 1.15 2000/05/11 22:20:57 wessels Exp $
  *
  * Low level DNS protocol routines
  * AUTHOR: Duane Wessels
@@ -93,6 +93,11 @@ struct _rfc1035_header {
     unsigned short arcount;
 };
 
+static const char *Alphanum =
+"abcdefghijklmnopqrstuvwxyz"
+"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+"0123456789";
+
 /*
  * rfc1035HeaderPack()
  * 
@@ -362,6 +367,39 @@ rfc1035Qid(void)
     return qid;
 }
 
+static void
+rfc1035SetErrno(int n)
+{
+    switch (rfc1035_errno = n) {
+    case 0:
+       rfc1035_error_message = "No error condition";
+       break;
+    case 1:
+       rfc1035_error_message = "Format Error: The name server was "
+           "unable to interpret the query.";
+       break;
+    case 2:
+       rfc1035_error_message = "Server Failure: The name server was "
+           "unable to process this query.";
+       break;
+    case 3:
+       rfc1035_error_message = "Name Error: The domain name does "
+           "not exist.";
+       break;
+    case 4:
+       rfc1035_error_message = "Not Implemented: The name server does "
+           "not support the requested kind of query.";
+       break;
+    case 5:
+       rfc1035_error_message = "Refused: The name server refuses to "
+           "perform the specified operation.";
+       break;
+    default:
+       rfc1035_error_message = "Unknown Error";
+       break;
+    }
+}
+
 void
 rfc1035RRDestroy(rfc1035_rr * rr, int n)
 {
@@ -393,35 +431,7 @@ rfc1035AnswersUnpack(const char *buf,
     rfc1035_errno = 0;
     rfc1035_error_message = NULL;
     if (hdr.rcode) {
-       rfc1035_errno = (int) hdr.rcode;
-       switch (rfc1035_errno) {
-       case 0:
-           rfc1035_error_message = "No error condition";
-           break;
-       case 1:
-           rfc1035_error_message = "Format Error: The name server was "
-               "unable to interpret the query.";
-           break;
-       case 2:
-           rfc1035_error_message = "Server Failure: The name server was "
-               "unable to process this query.";
-           break;
-       case 3:
-           rfc1035_error_message = "Name Error: The domain name does "
-               "not exist.";
-           break;
-       case 4:
-           rfc1035_error_message = "Not Implemented: The name server does "
-               "not support the requested kind of query.";
-           break;
-       case 5:
-           rfc1035_error_message = "Refused: The name server refuses to "
-               "perform the specified operation.";
-           break;
-       default:
-           rfc1035_error_message = "Unknown Error";
-           break;
-       }
+       rfc1035SetErrno((int) hdr.rcode);
        return -rfc1035_errno;
     }
     i = (int) hdr.qdcount;
@@ -471,6 +481,11 @@ rfc1035BuildAQuery(const char *hostname, char *buf, size_t * szp)
     off_t offset = 0;
     size_t sz = *szp;
     memset(&h, '\0', sizeof(h));
+    /* the first char of hostname must be alphanmeric */
+    if (NULL == strchr(Alphanum, *buf)) {
+       rfc1035SetErrno(3);
+       return 0;
+    }
     h.id = rfc1035Qid();
     h.qr = 0;
     h.rd = 1;
index 545eb9b201924ccae7f0790715a7446e0e1f41d4..25b6464e16b24cd9591de4a465c605b0ae52fc30 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: dns_internal.cc,v 1.23 2000/05/11 03:05:24 wessels Exp $
+ * $Id: dns_internal.cc,v 1.24 2000/05/11 22:21:01 wessels Exp $
  *
  * DEBUG: section 78    DNS lookups; interacts with lib/rfc1035.c
  * AUTHOR: Duane Wessels
@@ -423,6 +423,12 @@ idnsALookup(const char *name, IDNSCB * callback, void *data)
     idns_query *q = memAllocate(MEM_IDNS_QUERY);
     q->sz = sizeof(q->buf);
     q->id = rfc1035BuildAQuery(name, q->buf, &q->sz);
+    if (0 == q->id) {
+       /* problem with query data -- query not sent */
+       callback(data, NULL, 0);
+       memFree(q, MEM_IDNS_QUERY);
+       return;
+    }
     debug(78, 3) ("idnsALookup: buf is %d bytes for %s, id = %#hx\n",
        (int) q->sz, name, q->id);
     q->callback = callback;