From patchwork Wed Jun 21 11:36:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 21165 Received: (qmail 55120 invoked by alias); 21 Jun 2017 11:36:19 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 55084 invoked by uid 89); 21 Jun 2017 11:36:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5E9388E766 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5E9388E766 Date: Wed, 21 Jun 2017 13:36:14 +0200 To: libc-alpha@sourceware.org Subject: [PATCH COMMITTED] getaddrinfo: Avoid stack copy of IPv6 address User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20170621113614.DB97B439942F0@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) 2017-06-21 Florian Weimer * sysdeps/posix/getaddrinfo.c (gaih_inet): Call __inet_pton_length to parse addresses with IPv6 scope IDs. diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index a8bdd9a..4ec1796 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -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)