Browse code

dns: fix selecting neg. cname entry

- do not select a neg. cache cname entry as a response, unless
the request is for a cname.
This fixes an unlikely bug: someone makes a specific cname
request (from ser) for a name that doesn't resolve and then later when
a normal non-cname request is made (e.g. A) the empty negative cname
entry is selected, leading to a coredump. So far there is no
code in ser that could trigger this bug. Only dns.lookup cname
... from sip-router could trigger it.

Andrei Pelinescu-Onciul authored on 31/03/2009 18:11:25
Showing 1 changed files
... ...
@@ -580,8 +580,11 @@ again:
580 580
 #endif
581 581
 #endif
582 582
 			return e;
583
-		}else if ((e->type==T_CNAME) && (e->name_len==name->len) &&
584
-			(strncasecmp(e->name, name->s, e->name_len)==0)){
583
+		}else if ((e->type==T_CNAME) && !((e->rr_lst==0) || e->err_flags) &&
584
+					(e->name_len==name->len) &&
585
+					(strncasecmp(e->name, name->s, e->name_len)==0)){
586
+			/*if CNAME matches and CNAME is entry is not a neg. cache entry
587
+			  (could be produced by a specific CNAME lookup)*/
585 588
 			e->last_used=now;
586 589
 #ifdef DNS_LU_LST
587 590
 			/* add it at the end */