chiark / gitweb /
If server sends answer with TC set via TCP, bail
[adns.git] / src / reply.c
index bd2d0e8efc6f99ec19a54a3d4641caaf31498550..fbe4c95ecdde5ccaa52f638293253b80e3629d4a 100644 (file)
@@ -35,7 +35,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
   int flg_ra, flg_rd, flg_tc, flg_qr, opcode;
   int rrtype, rrclass, rdlength, rdstart;
   int anstart, nsstart;
-  int ownermatched, l, nrrs;
+  int ownermatched, l, nrrs, restartfrom;
   unsigned long ttl, soattl;
   const typeinfo *typei;
   adns_query qu, nqu;
@@ -162,6 +162,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
    * If it has any CNAMEs we stuff them in the answer.
    */
   wantedrrs= 0;
+  restartfrom= -1;
   cbyte= anstart;
   for (rri= 0; rri<ancount; rri++) {
     rrstart= cbyte;
@@ -229,6 +230,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
         */
       }
     } else if (rrtype == (qu->answer->type & adns_rrt_typemask)) {
+      if (restartfrom==-1) restartfrom= rri;
       wantedrrs++;
     } else {
       adns__debug(ads,serv,qu,"ignoring answer RR"
@@ -331,13 +333,15 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
   pai.arcount= arcount;
   pai.now= now;
 
+  assert(restartfrom>=0);
   for (rri=0, nrrs=0; rri<ancount; rri++) {
     st= adns__findrr(qu,serv, dgram,dglen,&cbyte,
                     &rrtype,&rrclass,&ttl, &rdlength,&rdstart,
                     &ownermatched);
     assert(!st); assert(rrtype != -1);
-    if (rrclass != DNS_CLASS_IN ||
+    if (rri < restartfrom ||
        rrtype != (qu->answer->type & adns_rrt_typemask) ||
+       rrclass != DNS_CLASS_IN ||
        !ownermatched)
       continue;
     adns__update_expires(qu,ttl,now);
@@ -366,6 +370,11 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
     adns__query_fail(qu,adns_s_invalidresponse);
     return;
   }
+  if (qu->flags & adns_qf_usevc) {
+    adns__diag(ads,serv,qu,"server sent datagram with TC over TCP");
+    adns__query_fail(qu,adns_s_invalidresponse);
+    return;
+  }
   qu->flags |= adns_qf_usevc;
   
  x_restartquery: