[uClibc-cvs] CVS update of uClibc/libc/inet (resolv.c)

Manuel Novoa III mjn3 at codepoet.org
Tue Aug 10 15:12:50 UTC 2004


    Date: Tuesday, August 10, 2004 @ 09:12:50
  Author: mjn3
    Path: /var/cvs/uClibc/libc/inet

Modified: resolv.c (1.53 -> 1.54)

On Monday 02 August 2004 08:44 am, Mike Frysinger wrote:
> the gethostbyname_r() call itself is not segfaulting, but the memory
> returned in the h_aliases array seems to be wrong ...

was playing around with the source today and eventually the obvious answer hit
me ... while read_etc_hosts_r() generatings an array of strings fo h_aliases
and populates it, the dns path does not :)

find attached a patch that'll actually generate the h_aliases list in the
normal dns code path ... i used the etc_hosts_r() code as a template for some
of it ...

note that this is just a simple fix ... it fills the alias list with just the
hostname gethostbyname_r was passed ... the proper fix i think would be to
parse the dns packet down in __dns_lookup() and pass the info back via the
resolv_answer struct ...
but this fix is better than the current state of things ... that is, h_aliases
currently is never initailized in the dns code path :)


Index: uClibc/libc/inet/resolv.c
diff -u uClibc/libc/inet/resolv.c:1.53 uClibc/libc/inet/resolv.c:1.54
--- uClibc/libc/inet/resolv.c:1.53	Wed Mar 10 13:43:23 2004
+++ uClibc/libc/inet/resolv.c	Tue Aug 10 09:12:48 2004
@@ -1846,6 +1846,7 @@
 {
 	struct in_addr *in;
 	struct in_addr **addr_list;
+	char **alias;
 	unsigned char *packet;
 	struct resolv_answer a;
 	int i;
@@ -1899,17 +1900,27 @@
 
 	addr_list[0] = in;
 	addr_list[1] = 0;
-	
+
+	if (buflen < sizeof(char *)*(ALIAS_DIM))
+		return ERANGE;
+	alias=(char **)buf;
+	buf+=sizeof(char **)*(ALIAS_DIM);
+	buflen-=sizeof(char **)*(ALIAS_DIM);
+
 	if (buflen<256)
 		return ERANGE;
 	strncpy(buf, name, buflen);
 
+	alias[0] = buf;
+	alias[1] = NULL;
+
 	/* First check if this is already an address */
 	if (inet_aton(name, in)) {
 	    result_buf->h_name = buf;
 	    result_buf->h_addrtype = AF_INET;
 	    result_buf->h_length = sizeof(*in);
 	    result_buf->h_addr_list = (char **) addr_list;
+	    result_buf->h_aliases = alias;
 	    *result=result_buf;
 	    *h_errnop = NETDB_SUCCESS;
 	    return NETDB_SUCCESS;
@@ -1954,6 +1965,10 @@
 			result_buf->h_addrtype = AF_INET;
 			result_buf->h_length = sizeof(*in);
 			result_buf->h_addr_list = (char **) addr_list;
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO -- generate the full list
+#endif
+			result_buf->h_aliases = alias; /* TODO: generate the full list */
 			free(packet);
 			break;
 		} else {



More information about the uClibc-cvs mailing list