]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
getaddrinfo: Avoid stack copy of IPv6 address
authorFlorian Weimer <fweimer@redhat.com>
Wed, 21 Jun 2017 11:35:37 +0000 (13:35 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 4 Jan 2018 10:28:44 +0000 (11:28 +0100)
(cherry picked from commit 76b8266f990a2912f42d1b7050840e8c7f14f2c2)

ChangeLog
sysdeps/posix/getaddrinfo.c

index 1a8f74a6d6f06c625ca2842a303da9f47f2f0725..16da468b63f110fc53893b5ae6fa157bcb71d6a4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-06-21  Florian Weimer  <fweimer@redhat.com>
+
+       * sysdeps/posix/getaddrinfo.c (gaih_inet): Call __inet_pton_length
+       to parse addresses with IPv6 scope IDs.
+
 2017-06-21  Florian Weimer  <fweimer@redhat.com>
 
        Add the __inet_pton_length helper function.
index e0c53936cb3da037ec9f50683050acd234392100..611abc2338ae34d0bd4baaf3e20deae2efdeea75 100644 (file)
@@ -539,46 +539,11 @@ gaih_inet (const char *name, const struct gaih_service *service,
        {
          char *scope_delim = strchr (name, SCOPE_DELIMITER);
          int e;
-
-         {
-           bool malloc_namebuf = false;
-           char *namebuf = (char *) name;
-
-           if (__glibc_unlikely (scope_delim != NULL))
-             {
-               if (malloc_name)
-                 *scope_delim = '\0';
-               else
-                 {
-                   if (__libc_use_alloca (alloca_used
-                                          + scope_delim - name + 1))
-                     {
-                       namebuf = alloca_account (scope_delim - name + 1,
-                                                 alloca_used);
-                       *((char *) __mempcpy (namebuf, name,
-                                             scope_delim - name)) = '\0';
-                     }
-                   else
-                     {
-                       namebuf = strndup (name, scope_delim - name);
-                       if (namebuf == NULL)
-                         {
-                           assert (!malloc_name);
-                           return -EAI_MEMORY;
-                         }
-                       malloc_namebuf = true;
-                     }
-                 }
-             }
-
-           e = inet_pton (AF_INET6, namebuf, at->addr);
-
-           if (malloc_namebuf)
-             free (namebuf);
-           else if (scope_delim != NULL && malloc_name)
-             /* Undo what we did above.  */
-             *scope_delim = SCOPE_DELIMITER;
-         }
+         if (scope_delim == NULL)
+           e = inet_pton (AF_INET6, name, at->addr);
+         else
+           e = __inet_pton_length (AF_INET6, name, scope_delim - name,
+                                   at->addr);
          if (e > 0)
            {
              if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)