]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
getnameinfo: Avoid calling strnlen on uninitialized buffer
authorFlorian Weimer <fweimer@redhat.com>
Wed, 4 May 2016 12:35:23 +0000 (14:35 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 4 May 2016 12:48:01 +0000 (14:48 +0200)
In the numeric AF_INET/AF_INET6 case, if inet_ntop fails
as the result of a short host buffer, we used to call strnlen
on the uninitialized host buffer.

ChangeLog
inet/getnameinfo.c

index 9d2ab7c8e02c37ae3fc6c6f0aef55e512e815741..833cc64b5c3b167efd7e79cc8e3424fa867ea871 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-05-04  Florian Weimer  <fweimer@redhat.com>
+
+       * inet/getnameinfo.c (gni_host_inet_numeric): Return EAI_OVERFLOW
+       in case of inet_ntop failure.
+
 2016-05-04  Florian Weimer  <fweimer@redhat.com>
 
        * inet/getnameinfo.c (gni_host_inet_name): Use temporaries to
index c649c493953fabe2bb7f11afb590a412f95b6f18..c8de1630f30c3efea881408e5d20ac7c5aa8e2fa 100644 (file)
@@ -303,12 +303,12 @@ gni_host_inet_numeric (struct scratch_buffer *tmpbuf,
                       const struct sockaddr *sa, socklen_t addrlen,
                       char *host, socklen_t hostlen, int flags)
 {
-  const char *c;
   if (sa->sa_family == AF_INET6)
     {
       const struct sockaddr_in6 *sin6p = (const struct sockaddr_in6 *) sa;
-      c = inet_ntop (AF_INET6,
-                    (const void *) &sin6p->sin6_addr, host, hostlen);
+      if (inet_ntop (AF_INET6, &sin6p->sin6_addr, host, hostlen) == NULL)
+       return EAI_OVERFLOW;
+
       uint32_t scopeid = sin6p->sin6_scope_id;
       if (scopeid != 0)
        {
@@ -344,7 +344,7 @@ gni_host_inet_numeric (struct scratch_buffer *tmpbuf,
          if (real_hostlen + scopelen + 1 > hostlen)
            /* Signal the buffer is too small.  This is
               what inet_ntop does.  */
-           c = NULL;
+           return EAI_OVERFLOW;
          else
            memcpy (host + real_hostlen, scopebuf, scopelen + 1);
        }
@@ -352,10 +352,9 @@ gni_host_inet_numeric (struct scratch_buffer *tmpbuf,
   else
     {
       const struct sockaddr_in *sinp = (const struct sockaddr_in *) sa;
-      c = inet_ntop (AF_INET, &sinp->sin_addr, host, hostlen);
+      if (inet_ntop (AF_INET, &sinp->sin_addr, host, hostlen) == NULL)
+       return EAI_OVERFLOW;
     }
-  if (c == NULL)
-    return EAI_OVERFLOW;
   return 0;
 }