[uClibc-cvs] uClibc/libc/inet resolv.c,1.52,1.53

Manuel Novoa III mjn3 at uclibc.org
Wed Mar 10 20:43:26 UTC 2004


Update of /var/cvs/uClibc/libc/inet
In directory nail:/tmp/cvs-serv24136

Modified Files:
	resolv.c 
Log Message:
Bug fix: gethostbyname2_r would fail if /etc/host was missing.
Bug fix: gethostbyname_r checked errno without first setting it to a
         known value.


Index: resolv.c
===================================================================
RCS file: /var/cvs/uClibc/libc/inet/resolv.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- a/resolv.c	24 Jan 2004 08:33:39 -0000	1.52
+++ b/resolv.c	10 Mar 2004 20:43:23 -0000	1.53
@@ -1860,20 +1860,26 @@
 		return EINVAL;
 
 	/* do /etc/hosts first */
-	if ((i=__get_hosts_byname_r(name, AF_INET, result_buf,
-				  buf, buflen, result, h_errnop))==0)
-		return i;
-	switch (*h_errnop) {
-		case HOST_NOT_FOUND:
-		case NO_ADDRESS:
-			break;
-		case NETDB_INTERNAL:
-			if (errno == ENOENT) {
-			    break;
-			}
-			/* else fall through */
-		default:
+	{
+		int old_errno = errno;	/* Save the old errno and reset errno */
+		__set_errno(0);			/* to check for missing /etc/hosts. */
+
+		if ((i=__get_hosts_byname_r(name, AF_INET, result_buf,
+									buf, buflen, result, h_errnop))==0)
 			return i;
+		switch (*h_errnop) {
+			case HOST_NOT_FOUND:
+			case NO_ADDRESS:
+				break;
+			case NETDB_INTERNAL:
+				if (errno == ENOENT) {
+					break;
+				}
+				/* else fall through */
+			default:
+				return i;
+		}
+		__set_errno(old_errno);
 	}
 
 	DPRINTF("Nothing found in /etc/hosts\n");
@@ -1996,15 +2002,26 @@
 		return EINVAL;
 
 	/* do /etc/hosts first */
-	if ((i=__get_hosts_byname_r(name, family, result_buf,
-				  buf, buflen, result, h_errnop))==0)
-		return i;
-	switch (*h_errnop) {
-		case HOST_NOT_FOUND:
-		case NO_ADDRESS:
-			break;
-		default:
+	{
+		int old_errno = errno;	/* Save the old errno and reset errno */
+		__set_errno(0);			/* to check for missing /etc/hosts. */
+
+		if ((i=__get_hosts_byname_r(name, AF_INET, result_buf,
+									buf, buflen, result, h_errnop))==0)
 			return i;
+		switch (*h_errnop) {
+			case HOST_NOT_FOUND:
+			case NO_ADDRESS:
+				break;
+			case NETDB_INTERNAL:
+				if (errno == ENOENT) {
+					break;
+				}
+				/* else fall through */
+			default:
+				return i;
+		}
+		__set_errno(old_errno);
 	}
 
 	DPRINTF("Nothing found in /etc/hosts\n");




More information about the uClibc-cvs mailing list