Blame SOURCES/glibc-rh1183545.patch

147e83
commit d5dd6189d506068ed11c8bfa1e1e9bffde04decd
147e83
Author: Andreas Schwab <schwab@suse.de>
147e83
Date:   Mon Jan 21 17:41:28 2013 +0100
147e83
147e83
    Fix parsing of numeric hosts in gethostbyname_r
147e83
147e83
diff --git glibc-2.17-c758a686/nss/Makefile glibc-2.17-c758a686/nss/Makefile
147e83
index 449a258..553eafa 100644
147e83
--- glibc-2.17-c758a686/nss/Makefile
147e83
+++ glibc-2.17-c758a686/nss/Makefile
147e83
@@ -37,7 +37,8 @@ install-bin             := getent makedb
147e83
 makedb-modules = xmalloc hash-string
147e83
 extra-objs		+= $(makedb-modules:=.o)
147e83
 
147e83
-tests			= test-netdb tst-nss-test1 bug17079 tst-nss-getpwent
147e83
+tests			= test-netdb tst-nss-test1 bug17079 tst-nss-getpwent \
147e83
+			 test-digits-dots
147e83
 xtests			= bug-erange
147e83
 
147e83
 include ../Makeconfig
147e83
diff --git glibc-2.17-c758a686/nss/digits_dots.c glibc-2.17-c758a686/nss/digits_dots.c
147e83
index 2b86295..e007ef4 100644
147e83
--- glibc-2.17-c758a686/nss/digits_dots.c
147e83
+++ glibc-2.17-c758a686/nss/digits_dots.c
147e83
@@ -46,7 +46,10 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
147e83
     {
147e83
       if (h_errnop)
147e83
 	*h_errnop = NETDB_INTERNAL;
147e83
-      *result = NULL;
147e83
+      if (buffer_size == NULL)
147e83
+	*status = NSS_STATUS_TRYAGAIN;
147e83
+      else
147e83
+	*result = NULL;
147e83
       return -1;
147e83
     }
147e83
 
147e83
@@ -83,14 +86,16 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
147e83
 	}
147e83
 
147e83
       size_needed = (sizeof (*host_addr)
147e83
-		     + sizeof (*h_addr_ptrs) + strlen (name) + 1);
147e83
+		     + sizeof (*h_addr_ptrs)
147e83
+		     + sizeof (*h_alias_ptr) + strlen (name) + 1);
147e83
 
147e83
       if (buffer_size == NULL)
147e83
         {
147e83
 	  if (buflen < size_needed)
147e83
 	    {
147e83
+	      *status = NSS_STATUS_TRYAGAIN;
147e83
 	      if (h_errnop != NULL)
147e83
-		*h_errnop = TRY_AGAIN;
147e83
+		*h_errnop = NETDB_INTERNAL;
147e83
 	      __set_errno (ERANGE);
147e83
 	      goto done;
147e83
 	    }
147e83
@@ -109,7 +114,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
147e83
 	      *buffer_size = 0;
147e83
 	      __set_errno (save);
147e83
 	      if (h_errnop != NULL)
147e83
-		*h_errnop = TRY_AGAIN;
147e83
+		*h_errnop = NETDB_INTERNAL;
147e83
 	      *result = NULL;
147e83
 	      goto done;
147e83
 	    }
147e83
@@ -149,7 +154,9 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
147e83
 		  if (! ok)
147e83
 		    {
147e83
 		      *h_errnop = HOST_NOT_FOUND;
147e83
-		      if (buffer_size)
147e83
+		      if (buffer_size == NULL)
147e83
+			*status = NSS_STATUS_NOTFOUND;
147e83
+		      else
147e83
 			*result = NULL;
147e83
 		      goto done;
147e83
 		    }
147e83
@@ -190,7 +197,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
147e83
 		  if (buffer_size == NULL)
147e83
 		    *status = NSS_STATUS_SUCCESS;
147e83
 		  else
147e83
-		   *result = resbuf;
147e83
+		    *result = resbuf;
147e83
 		  goto done;
147e83
 		}
147e83
 
147e83
@@ -201,15 +208,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
147e83
 
147e83
       if ((isxdigit (name[0]) && strchr (name, ':') != NULL) || name[0] == ':')
147e83
 	{
147e83
-	  const char *cp;
147e83
-	  char *hostname;
147e83
-	  typedef unsigned char host_addr_t[16];
147e83
-	  host_addr_t *host_addr;
147e83
-	  typedef char *host_addr_list_t[2];
147e83
-	  host_addr_list_t *h_addr_ptrs;
147e83
-	  size_t size_needed;
147e83
-	  int addr_size;
147e83
-
147e83
 	  switch (af)
147e83
 	    {
147e83
 	    default:
147e83
@@ -225,7 +223,10 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
147e83
 	      /* This is not possible.  We cannot represent an IPv6 address
147e83
 		 in an `struct in_addr' variable.  */
147e83
 	      *h_errnop = HOST_NOT_FOUND;
147e83
-	      *result = NULL;
147e83
+	      if (buffer_size == NULL)
147e83
+		*status = NSS_STATUS_NOTFOUND;
147e83
+	      else
147e83
+		*result = NULL;
147e83
 	      goto done;
147e83
 
147e83
 	    case AF_INET6:
147e83
@@ -233,42 +234,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
147e83
 	      break;
147e83
 	    }
147e83
 
147e83
-	  size_needed = (sizeof (*host_addr)
147e83
-			 + sizeof (*h_addr_ptrs) + strlen (name) + 1);
147e83
-
147e83
-	  if (buffer_size == NULL && buflen < size_needed)
147e83
-	    {
147e83
-	      if (h_errnop != NULL)
147e83
-		*h_errnop = TRY_AGAIN;
147e83
-	      __set_errno (ERANGE);
147e83
-	      goto done;
147e83
-	    }
147e83
-	  else if (buffer_size != NULL && *buffer_size < size_needed)
147e83
-	    {
147e83
-	      char *new_buf;
147e83
-	      *buffer_size = size_needed;
147e83
-	      new_buf = realloc (*buffer, *buffer_size);
147e83
-
147e83
-	      if (new_buf == NULL)
147e83
-		{
147e83
-		  save = errno;
147e83
-		  free (*buffer);
147e83
-		  __set_errno (save);
147e83
-		  *buffer = NULL;
147e83
-		  *buffer_size = 0;
147e83
-		  *result = NULL;
147e83
-		  goto done;
147e83
-		}
147e83
-	      *buffer = new_buf;
147e83
-	    }
147e83
-
147e83
-	  memset (*buffer, '\0', size_needed);
147e83
-
147e83
-	  host_addr = (host_addr_t *) *buffer;
147e83
-	  h_addr_ptrs = (host_addr_list_t *)
147e83
-	    ((char *) host_addr + sizeof (*host_addr));
147e83
-	  hostname = (char *) h_addr_ptrs + sizeof (*h_addr_ptrs);
147e83
-
147e83
 	  for (cp = name;; ++cp)
147e83
 	    {
147e83
 	      if (!*cp)
147e83
@@ -281,7 +246,9 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
147e83
 		  if (inet_pton (AF_INET6, name, host_addr) <= 0)
147e83
 		    {
147e83
 		      *h_errnop = HOST_NOT_FOUND;
147e83
-		      if (buffer_size)
147e83
+		      if (buffer_size == NULL)
147e83
+			*status = NSS_STATUS_NOTFOUND;
147e83
+		      else
147e83
 			*result = NULL;
147e83
 		      goto done;
147e83
 		    }
147e83
diff --git glibc-2.17-c758a686/nss/getXXbyYY_r.c glibc-2.17-c758a686/nss/getXXbyYY_r.c
147e83
index 1067744..44d00f4 100644
147e83
--- glibc-2.17-c758a686/nss/getXXbyYY_r.c
147e83
+++ glibc-2.17-c758a686/nss/getXXbyYY_r.c
147e83
@@ -179,6 +179,9 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
147e83
     case -1:
147e83
       return errno;
147e83
     case 1:
147e83
+#ifdef NEED_H_ERRNO
147e83
+      any_service = true;
147e83
+#endif
147e83
       goto done;
147e83
     }
147e83
 #endif
147e83
@@ -288,7 +291,7 @@ done:
147e83
     /* This happens when we weren't able to use a service for reasons other
147e83
        than the module not being found.  In such a case, we'd want to tell the
147e83
        caller that errno has the real reason for failure.  */
147e83
-      *h_errnop = NETDB_INTERNAL;
147e83
+    *h_errnop = NETDB_INTERNAL;
147e83
   else if (status != NSS_STATUS_SUCCESS && !any_service)
147e83
     /* We were not able to use any service.  */
147e83
     *h_errnop = NO_RECOVERY;
147e83
diff --git glibc-2.17-c758a686/nss/test-digits-dots.c glibc-2.17-c758a686/nss/test-digits-dots.c
147e83
new file mode 100644
147e83
index 0000000..1efa344
147e83
--- /dev/null
147e83
+++ glibc-2.17-c758a686/nss/test-digits-dots.c
147e83
@@ -0,0 +1,38 @@
147e83
+/* Copyright (C) 2013 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+/* Testcase for BZ #15014 */
147e83
+
147e83
+#include <stdlib.h>
147e83
+#include <netdb.h>
147e83
+#include <errno.h>
147e83
+
147e83
+static int
147e83
+do_test (void)
147e83
+{
147e83
+  char buf[32];
147e83
+  struct hostent *result = NULL;
147e83
+  struct hostent ret;
147e83
+  int h_err = 0;
147e83
+  int err;
147e83
+
147e83
+  err = gethostbyname_r ("1.2.3.4", &ret, buf, sizeof (buf), &result, &h_err);
147e83
+  return err == ERANGE && h_err == NETDB_INTERNAL ? EXIT_SUCCESS : EXIT_FAILURE;
147e83
+}
147e83
+
147e83
+#define TEST_FUNCTION do_test ()
147e83
+#include "../test-skeleton.c"