chiark / gitweb /
+ * Better checking of long domain names and labels in queries.
authorian <ian>
Wed, 1 Mar 2000 23:50:05 +0000 (23:50 +0000)
committerian <ian>
Wed, 1 Mar 2000 23:50:05 +0000 (23:50 +0000)
@@ -2,6 +2,8 @@
+  * Better checking of long domain names and labels in queries.
+  * Unfortunately, answer->owner may be null on error.  Documented.

changelog
client/adh-query.c
client/adnshost.h
src/adns.h
src/general.c
src/transmit.c

index f41efb663ad6f5ef02fc419a808f5b9710c664a6..155d177ae1373095edf9dacc3eded1809fe07318 100644 (file)
--- a/changelog
+++ b/changelog
@@ -2,6 +2,8 @@ adns (0.7) BETA; urgency=medium
 
   * README updated (from www home page).
   * Better reporting of unexpected or weird replies from nameserver.
 
   * README updated (from www home page).
   * Better reporting of unexpected or weird replies from nameserver.
+  * Better checking of long domain names and labels in queries.
+  * Unfortunately, answer->owner may be null on error.  Documented.
 
  --
 
 
  --
 
index bae71f42728c666fc805a507ff405dc5cde17409..cc5dc122f2846f194aaee48244063b43b9e7b0d7 100644 (file)
@@ -89,6 +89,7 @@ void of_ptr(const struct optioninfo *oi, const char *arg) {
   if (!inet_aton(arg,&sa.sin_addr)) usageerr("invalid IP address %s",arg);
 
   prep_query(&qun,&quflags);
   if (!inet_aton(arg,&sa.sin_addr)) usageerr("invalid IP address %s",arg);
 
   prep_query(&qun,&quflags);
+  qun->owner= xstrsave(arg);
   r= adns_submit_reverse(ads,
                         (struct sockaddr*)&sa,
                         ov_type == adns_r_none ? adns_r_ptr : ov_type,
   r= adns_submit_reverse(ads,
                         (struct sockaddr*)&sa,
                         ov_type == adns_r_none ? adns_r_ptr : ov_type,
@@ -105,6 +106,7 @@ void query_do(const char *domain) {
   int quflags, r;
 
   prep_query(&qun,&quflags);
   int quflags, r;
 
   prep_query(&qun,&quflags);
+  qun->owner= xstrsave(domain);
   r= adns_submit(ads, domain,
                 ov_type == adns_r_none ? adns_r_addr : ov_type,
                 quflags,
   r= adns_submit(ads, domain,
                 ov_type == adns_r_none ? adns_r_addr : ov_type,
                 quflags,
@@ -145,8 +147,12 @@ static void print_ttl(struct query_node *qun, adns_answer *answer) {
   if (printf("%lu ",ttl) == EOF) outerr();
 }
 
   if (printf("%lu ",ttl) == EOF) outerr();
 }
 
+static const char *owner_show(struct query_node *qun, adns_answer *answer) {
+  return answer->owner ? answer->owner : qun->owner;
+}
+
 static void print_owner_ttl(struct query_node *qun, adns_answer *answer) {
 static void print_owner_ttl(struct query_node *qun, adns_answer *answer) {
-  if (qun->pqfr.show_owner) print_withspace(answer->owner);
+  if (qun->pqfr.show_owner) print_withspace(owner_show(qun,answer));
   print_ttl(qun,answer);
 }
 
   print_ttl(qun,answer);
 }
 
@@ -195,15 +201,15 @@ static void print_dnsfail(adns_status st, struct query_node *qun, adns_answer *a
   }
   assert(ov_format == fmt_simple);
   if (st == adns_s_nxdomain) {
   }
   assert(ov_format == fmt_simple);
   if (st == adns_s_nxdomain) {
-    r= fprintf(stderr,"%s does not exist\n", answer->owner);
+    r= fprintf(stderr,"%s does not exist\n", owner_show(qun,answer));
   } else {
     ist= adns_rr_info(answer->type, &typename, 0,0,0,0);
     if (st == adns_s_nodata) {
   } else {
     ist= adns_rr_info(answer->type, &typename, 0,0,0,0);
     if (st == adns_s_nodata) {
-      r= fprintf(stderr,"%s has no %s record\n", answer->owner, typename);
+      r= fprintf(stderr,"%s has no %s record\n", owner_show(qun,answer), typename);
     } else {
       statusstring= adns_strerror(st);
       r= fprintf(stderr,"Error during DNS %s lookup for %s: %s\n",
     } else {
       statusstring= adns_strerror(st);
       r= fprintf(stderr,"Error during DNS %s lookup for %s: %s\n",
-                typename, answer->owner, statusstring);
+                typename, owner_show(qun,answer), statusstring);
     }
   }
   if (r == EOF) sysfail("write error message to stderr",errno);
     }
   }
   if (r == EOF) sysfail("write error message to stderr",errno);
@@ -233,7 +239,7 @@ void query_done(struct query_node *qun, adns_answer *answer) {
     }
   }
   if (qun->pqfr.show_owner) {
     }
   }
   if (qun->pqfr.show_owner) {
-    realowner= answer->cname ? answer->cname : answer->owner;
+    realowner= answer->cname ? answer->cname : owner_show(qun,answer);
     assert(realowner);
   } else {
     realowner= 0;
     assert(realowner);
   } else {
     realowner= 0;
index 8b459b35c070b185f63f780b45a85b17e0f571d9..93a7608b11bfc8213684c009df1bb4daf5da2430 100644 (file)
@@ -90,7 +90,7 @@ void opt_do(const struct optioninfo *oip, const char *arg, int invert);
 struct query_node {
   struct query_node *next, *back;
   struct perqueryflags_remember pqfr;
 struct query_node {
   struct query_node *next, *back;
   struct perqueryflags_remember pqfr;
-  char *id;
+  char *id, *owner;
   adns_query qu;
 };
 
   adns_query qu;
 };
 
index feb9f9db276a61583342c5d908818e5ec1d8934b..6643864eb377d0e944c5e1f6f048723d3fc68f74 100644 (file)
@@ -284,7 +284,7 @@ typedef struct {
 typedef struct {
   adns_status status;
   char *cname; /* always NULL if query was for CNAME records */
 typedef struct {
   adns_status status;
   char *cname; /* always NULL if query was for CNAME records */
-  char *owner; /* only set if requested in query flags */
+  char *owner; /* only set if requested in query flags, and may be 0 on error anyway */
   adns_rrtype type; /* guaranteed to be same as in query */
   time_t expires; /* expiry time, defined only if _s_ok, nxdomain or nodata. NOT TTL! */
   int nrrs, rrsz; /* nrrs is 0 if an error occurs */
   adns_rrtype type; /* guaranteed to be same as in query */
   time_t expires; /* expiry time, defined only if _s_ok, nxdomain or nodata. NOT TTL! */
   int nrrs, rrsz; /* nrrs is 0 if an error occurs */
index 87937627bf5329ada53d00d2da24caf6d0b82eb8..d5bdcb089739847cd67f6bc365167537ccffa8db 100644 (file)
@@ -244,7 +244,7 @@ static const struct sinfo {
 
   SINFO(  querydomainwrong,    "Domain invalid for particular DNS query type"  ),
   SINFO(  querydomaininvalid,  "Domain name is syntactically invalid"          ),
 
   SINFO(  querydomainwrong,    "Domain invalid for particular DNS query type"  ),
   SINFO(  querydomaininvalid,  "Domain name is syntactically invalid"          ),
-  SINFO(  querydomaintoolong,  "Domain name is too long"                       ),
+  SINFO(  querydomaintoolong,  "Domain name or component is too long"          ),
 
   SINFO(  nxdomain,            "No such domain"                                ),
   SINFO(  nodata,              "No such data"                                  )
 
   SINFO(  nxdomain,            "No such domain"                                ),
   SINFO(  nodata,              "No such data"                                  )
index c669af6f797cff804aab68ca693a28a31d637806..b97ffc65a59a04c724b28bde12a6cd5b1b1baf0a 100644 (file)
@@ -77,7 +77,7 @@ static adns_status mkquery_footer(vbuf *vb, adns_rrtype type) {
 adns_status adns__mkquery(adns_state ads, vbuf *vb, int *id_r,
                          const char *owner, int ol,
                          const typeinfo *typei, adns_queryflags flags) {
 adns_status adns__mkquery(adns_state ads, vbuf *vb, int *id_r,
                          const char *owner, int ol,
                          const typeinfo *typei, adns_queryflags flags) {
-  int ll, c, nlabs;
+  int ll, c, nbytes;
   byte label[255], *rqp;
   const char *p, *pe;
   adns_status st;
   byte label[255], *rqp;
   const char *p, *pe;
   adns_status st;
@@ -87,7 +87,7 @@ adns_status adns__mkquery(adns_state ads, vbuf *vb, int *id_r,
   MKQUERY_START(vb);
 
   p= owner; pe= owner+ol;
   MKQUERY_START(vb);
 
   p= owner; pe= owner+ol;
-  nlabs= 0;
+  nbytes= 0;
   while (p!=pe) {
     ll= 0;
     while (p!=pe && (c= *p++)!='.') {
   while (p!=pe) {
     ll= 0;
     while (p!=pe && (c= *p++)!='.') {
@@ -115,7 +115,9 @@ adns_status adns__mkquery(adns_state ads, vbuf *vb, int *id_r,
       label[ll++]= c;
     }
     if (!ll) return adns_s_querydomaininvalid;
       label[ll++]= c;
     }
     if (!ll) return adns_s_querydomaininvalid;
-    if (nlabs++ > 63) return adns_s_querydomaintoolong;
+    if (ll > 63) return adns_s_querydomaintoolong;
+    nbytes+= ll+1;
+    if (nbytes > 254) return adns_s_querydomaintoolong;
     MKQUERY_ADDB(ll);
     memcpy(rqp,label,ll); rqp+= ll;
   }
     MKQUERY_ADDB(ll);
     memcpy(rqp,label,ll); rqp+= ll;
   }