This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix getaddrinfo


Hi!

https://bugzilla.redhat.com/bugzilla/attachment.cgi?id=91234&action=view
has a testcase. If the caller manages to leave -1 on the stack in the place
which becomes herrno, then gaih_inet will eat all the stack and die.
Fixed thusly:

2003-04-23  Jakub Jelinek  <jakub at redhat dot com>

	* sysdeps/posix/getaddrinfo.c (gaih_inet): Check for rc == ERANGE,
	not rc == errno.  Use extend_alloca.

--- libc/sysdeps/posix/getaddrinfo.c.jj	2002-12-20 07:36:31.000000000 -0500
+++ libc/sysdeps/posix/getaddrinfo.c	2003-04-23 05:15:51.000000000 -0400
@@ -677,13 +677,11 @@ gaih_inet (const char *name, const struc
 	    int herrno;
 	    struct hostent th;
 	    size_t tmpbuflen = 512;
-	    char *tmpbuf;
+	    char *tmpbuf = NULL;
 
 	    do
 	      {
-		tmpbuflen *= 2;
-		tmpbuf = __alloca (tmpbuflen);
-
+		tmpbuf = extend_alloca (tmpbuf, tmpbuflen, tmpbuflen * 2);
 		rc = __gethostbyaddr_r (at2->addr,
 					((at2->family == AF_INET6)
 					 ? sizeof(struct in6_addr)
@@ -692,7 +690,7 @@ gaih_inet (const char *name, const struc
 					&h, &herrno);
 
 	      }
-	    while (rc == errno && herrno == NETDB_INTERNAL);
+	    while (rc == ERANGE && herrno == NETDB_INTERNAL);
 
 	    if (rc != 0 && herrno == NETDB_INTERNAL)
 	      {

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]