This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] getaddrinfo: Always allocate canonical name on the heap
- From: Florian Weimer <fweimer at redhat dot com>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Fri, 2 Jun 2017 16:37:09 +0200
- Subject: Re: [PATCH] getaddrinfo: Always allocate canonical name on the heap
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6AC7991FD5
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6AC7991FD5
- References: <20170511100718.1F66A401E714A@oldenburg.str.redhat.com> <52802461-8188-52e7-eeba-9cdce0be340d@linaro.org> <2738bd73-a636-1e6e-7eb0-225c99d91b5d@redhat.com> <a065149c-7c28-4a4a-530b-4a0910ae0884@linaro.org>
On 06/02/2017 04:10 PM, Adhemerval Zanella wrote:
> I noticed on x86_64 (gcc 5.4), powerpc64le (gcc 5.4), aarch64 (gcc 4.9.2),
> and sparc64 (gcc 6.3.1). My guess is newer GCC versions are inline it.
Fair enough. What about the attached patch? I spotted one missing heap
allocation (which is not visible as a bug because the code doesn't try
to pass the pointer to free), and included that as well.
Thanks,
Florian
getaddrinfo: Fix localplt failure involving strdup
2017-06-02 Florian Weimer <fweimer@redhat.com>
* sysdeps/posix/getaddrinfo.c (gethosts): Eliminate another
strdupa.
(getcanonname): Use __strdup instead of strdup.
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index d92db70..a8b5bb5 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -286,9 +286,16 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req,
} \
*pat = addrmem; \
\
- if (localcanon != NULL && canon == NULL) \
- canon = strdupa (localcanon); \
- \
+ if (localcanon != NULL && canon == NULL) \
+ { \
+ canonbuf = __strdup (localcanon); \
+ if (canonbuf == NULL) \
+ { \
+ result = -EAI_SYSTEM; \
+ goto free_and_return; \
+ } \
+ canon = canonbuf; \
+ } \
if (_family == AF_INET6 && *pat != NULL) \
got_ipv6 = true; \
} \
@@ -330,7 +337,7 @@ getcanonname (service_user *nip, struct gaih_addrtuple *at, const char *name)
string. */
s = (char *) name;
}
- return strdup (name);
+ return __strdup (name);
}
static int