From: wessels <> Date: Fri, 12 May 2000 04:20:57 +0000 (+0000) Subject: DW: X-Git-Tag: SQUID_3_0_PRE1~1983 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76cb2b26d5d0f4f84e6596b1e2b16fbd74a15fba;p=thirdparty%2Fsquid.git DW: - 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. --- diff --git a/lib/rfc1035.c b/lib/rfc1035.c index 975e4528e7..87d56635d2 100644 --- a/lib/rfc1035.c +++ b/lib/rfc1035.c @@ -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; diff --git a/src/dns_internal.cc b/src/dns_internal.cc index 545eb9b201..25b6464e16 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -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;