Subject: Problem with resolver code
To: None <current-users@NetBSD.ORG>
From: Aaron Brown <>
List: current-users
Date: 01/29/1997 23:12:43
Hi all,

There seems to be a problem with the resolver code in -current. In
/usr/src/lib/libc/net/gethostnamadr.c, near the top, MAXADDRS is defined
to be 35. However, nowhere does the code check the number of returned
addresses. Thus if the server returns more than 35 (try, for example,, then the resolver code happily writes garbage
all over its automatic variables, returns it to the calling program,
which promptly coredumps. This is not good.

The simplistic solution (attached below) is to just discard all addresses
after MAXADDRS addresses have been found. Do people think this is the 
right thing to do? If so, let me know and I'll commit it.

Has this problem come up before anywhere?


Index: gethostnamadr.c
RCS file: /cvsroot/src/lib/libc/net/gethostnamadr.c,v
retrieving revision 1.18
diff -c -r1.18 gethostnamadr.c
*** gethostnamadr.c	1997/01/23 14:02:04	1.18
--- gethostnamadr.c	1997/01/30 04:15:40
*** 175,180 ****
--- 175,182 ----
  	*hap = NULL;
  	host.h_addr_list = h_addr_ptrs;
  	haveanswer = 0;
+ 	if (ancount > MAXADDRS)
+ 		ancount = MAXADDRS;
  	while (--ancount >= 0 && cp < eom) {
  		if ((n = dn_expand((u_char *)answer->buf, (u_char *)eom,
  		    (u_char *)cp, (u_char *)bp, buflen)) < 0)