getaddrinfo: Always allocate canonical name on the heap
Commit Message
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
Comments
On 02/06/2017 11:37, Florian Weimer wrote:
> 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
>
LGTM, thanks.
I'm still seeing a localplt failure for strdup even after commit
6257fcfd58479f6b7ae0fdde045b9ff144d543da.
https://sourceware.org/ml/libc-testresults/2017-q2/msg00276.html
(The strdup@plt reference is from gaih_inet.constprop.6, at least on
x86_64. It seems there is one plain strdup reference in
sysdeps/posix/getaddrinfo.c.)
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.
@@ -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