olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone
ce426f
commit 7cbcdb3699584db8913ca90f705d6337633ee10f
ce426f
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
ce426f
Date:   Fri Oct 25 10:22:12 2013 +0530
ce426f
ce426f
    Fix stack overflow due to large AF_INET6 requests
ce426f
    
ce426f
    Resolves #16072 (CVE-2013-4458).
ce426f
    
ce426f
    This patch fixes another stack overflow in getaddrinfo when it is
ce426f
    called with AF_INET6.  The AF_UNSPEC case was fixed as CVE-2013-1914,
ce426f
    but the AF_INET6 case went undetected back then.
ce426f
ce426f
diff --git glibc-2.17-c758a686/sysdeps/posix/getaddrinfo.c glibc-2.17-c758a686/sysdeps/posix/getaddrinfo.c
ce426f
index e6ce4cf..8ff74b4 100644
ce426f
--- glibc-2.17-c758a686/sysdeps/posix/getaddrinfo.c
ce426f
+++ glibc-2.17-c758a686/sysdeps/posix/getaddrinfo.c
ce426f
@@ -197,7 +197,22 @@ gaih_inet_serv (const char *servicename, const struct gaih_typeproto *tp,
ce426f
 				&rc, &herrno, NULL, &localcanon));	      \
ce426f
     if (rc != ERANGE || herrno != NETDB_INTERNAL)			      \
ce426f
       break;								      \
ce426f
-    tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen);		      \
ce426f
+    if (!malloc_tmpbuf && __libc_use_alloca (alloca_used + 2 * tmpbuflen))    \
ce426f
+      tmpbuf = extend_alloca_account (tmpbuf, tmpbuflen, 2 * tmpbuflen,	      \
ce426f
+				      alloca_used);			      \
ce426f
+    else								      \
ce426f
+      {									      \
ce426f
+	char *newp = realloc (malloc_tmpbuf ? tmpbuf : NULL,		      \
ce426f
+			      2 * tmpbuflen);				      \
ce426f
+	if (newp == NULL)						      \
ce426f
+	  {								      \
ce426f
+	    result = -EAI_MEMORY;					      \
ce426f
+	    goto free_and_return;					      \
ce426f
+	  }								      \
ce426f
+	tmpbuf = newp;							      \
ce426f
+	malloc_tmpbuf = true;						      \
ce426f
+	tmpbuflen = 2 * tmpbuflen;					      \
ce426f
+      }									      \
ce426f
   }									      \
ce426f
   if (status == NSS_STATUS_SUCCESS && rc == 0)				      \
ce426f
     h = &th;								      \
ce426f
@@ -209,7 +224,8 @@ gaih_inet_serv (const char *servicename, const struct gaih_typeproto *tp,
ce426f
 	{								      \
ce426f
 	  __set_h_errno (herrno);					      \
ce426f
 	  _res.options |= old_res_options & RES_USE_INET6;		      \
ce426f
-	  return -EAI_SYSTEM;						      \
ce426f
+	  result = -EAI_SYSTEM;						      \
ce426f
+	  goto free_and_return;						      \
ce426f
 	}								      \
ce426f
       if (herrno == TRY_AGAIN)						      \
ce426f
 	no_data = EAI_AGAIN;						      \