chiark / gitweb /
cs_inthost*: Break out csp_intofinthost
[adns.git] / src / types.c
index 754c237253d75f6628efac8c21029b20072546b2..569962e3abd80f650612a1db4714bc58f1b80831 100644 (file)
@@ -4,7 +4,8 @@
  */
 /*
  *  This file is part of adns, which is
- *    Copyright (C) 1997-2000,2003,2006,2014  Ian Jackson
+ *    Copyright (C) 1997-2000,2003,2006,2014-2016  Ian Jackson
+ *    Copyright (C) 2014  Mark Wooding
  *    Copyright (C) 1999-2000,2003,2006  Tony Finch
  *    Copyright (C) 1991 Massachusetts Institute of Technology
  *  (See the file INSTALL for full details.)
@@ -891,6 +892,7 @@ static void icb_hostaddr(adns_query parent, adns_query child) {
 done:
   if (st) {
     adns__free_interim(parent, rrp->addrs);
+    rrp->addrs = 0;
     rrp->naddrs= (st>0 && st<=adns_s_max_tempfail) ? -1 : 0;
   }
 
@@ -1106,13 +1108,19 @@ static void mf_inthostaddr(adns_query qu, void *datap) {
   mfp_hostaddr(qu,&rrp->ha);
 }
 
-static adns_status cs_inthostaddr(vbuf *vb, const void *datap) {
-  const adns_rr_inthostaddr *rrp= datap;
+static adns_status csp_intofinthost(vbuf *vb, int i) {
   char buf[10];
 
-  sprintf(buf,"%u ",rrp->i);
+  sprintf(buf,"%u ",i);
   CSP_ADDSTR(buf);
+  return adns_s_ok;
+}
+
+static adns_status cs_inthostaddr(vbuf *vb, const void *datap) {
+  const adns_rr_inthostaddr *rrp= datap;
+  adns_status st;
 
+  st = csp_intofinthost(vb,rrp->i);  if (st) return st;
   return csp_hostaddr(vb,&rrp->ha);
 }
 
@@ -1122,10 +1130,9 @@ static adns_status cs_inthostaddr(vbuf *vb, const void *datap) {
 
 static adns_status cs_inthost(vbuf *vb, const void *datap) {
   const adns_rr_intstr *rrp= datap;
-  char buf[10];
+  adns_status st;
 
-  sprintf(buf,"%u ",rrp->i);
-  CSP_ADDSTR(buf);
+  st = csp_intofinthost(vb,rrp->i);  if (st) return st;
   return csp_domain(vb,rrp->str);
 }
 
@@ -1276,6 +1283,7 @@ static adns_status pap_mailbox822(const parseinfo *pai,
                        pai->dgram, pai->dglen, max,
                        *cbyte_io, cbyte_io);
   st= adns__findlabel_next(&fls,&lablen,&labstart);
+  if (st) return st;
   if (!lablen) {
     adns__vbuf_appendstr(vb,".");
     goto x_ok;
@@ -1368,7 +1376,7 @@ static adns_status pa_soa(const parseinfo *pai, int cbyte,
   adns_rr_soa *rrp= datap;
   const byte *dgram= pai->dgram;
   adns_status st;
-  int msw, lsw, i;
+  int i;
 
   st= pap_domain(pai, &cbyte, max, &rrp->mname,
                 pai->qu->flags & adns_qf_quoteok_anshost ? pdf_quoteok : 0);
@@ -1380,9 +1388,8 @@ static adns_status pa_soa(const parseinfo *pai, int cbyte,
   if (cbyte+20 != max) return adns_s_invaliddata;
   
   for (i=0; i<5; i++) {
-    GET_W(cbyte,msw);
-    GET_W(cbyte,lsw);
-    (&rrp->serial)[i]= (msw<<16) | lsw;
+    unsigned long v;
+    (&rrp->serial)[i]= GET_L(cbyte, v);
   }
 
   return adns_s_ok;
@@ -1692,6 +1699,10 @@ DEEP_TYPE(unknown,0, "unknown",byteblock,opaque,  0,     opaque            );
 const typeinfo *adns__findtype(adns_rrtype type) {
   const typeinfo *begin, *end, *mid;
 
+  if (type & ~(adns_rrtype)0x63ffffff)
+    /* 0x60000000 is reserved for `harmless' future expansion */
+    return 0;
+
   if (type & adns_r_unknown) return &typeinfo_unknown;
   type &= adns_rrt_reprmask;