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: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-alpha at sourceware dot org
- Date: Fri, 2 Jun 2017 10:56:40 -0300
- Subject: Re: [PATCH] getaddrinfo: Always allocate canonical name on the heap
- Authentication-results: sourceware.org; auth=none
- References: <20170511100718.1F66A401E714A@oldenburg.str.redhat.com>
On 11/05/2017 07:07, Florian Weimer wrote:
> A further simplification could eliminate the canon variable in
> gaih_inet and replace it with canonbuf. However, canonbuf is
> used as a flag in the nscd code, which makes this somewhat
> non-straightforward.
>
> 2017-05-11 Florian Weimer <fweimer@redhat.com>
>
> * sysdeps/posix/getaddrinfo.c (getcanonname): New function.
> (gaih_inet): Remove malloc_canonbuf variable. Call getcanonname.
>
> diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
> index dc02b11..d92db70 100644
> --- a/sysdeps/posix/getaddrinfo.c
> +++ b/sysdeps/posix/getaddrinfo.c
> @@ -308,6 +308,30 @@ typedef enum nss_status (*nss_getcanonname_r)
> int *errnop, int *h_errnop);
> extern service_user *__nss_hosts_database attribute_hidden;
>
> +/* This function is called if a canonical name is requested, but if
> + the service function did not provide it. It tries to obtain the
> + name using getcanonname_r from the same service NIP. If the name
> + cannot be canonicalized, return a copy of NAME. Return NULL on
> + memory allocation failure. The returned string is allocated on the
> + heap; the caller has to free it. */
> +static char *
> +getcanonname (service_user *nip, struct gaih_addrtuple *at, const char *name)
> +{
> + nss_getcanonname_r cfct = __nss_lookup_function (nip, "getcanonname_r");
> + char *s = (char *) name;
> + if (cfct != NULL)
> + {
> + char buf[256];
> + int herrno;
> + int rc;
> + if (DL_CALL_FCT (cfct, (at->name ?: name, buf, sizeof (buf),
> + &s, &rc, &herrno)) != NSS_STATUS_SUCCESS)
> + /* If the canonical name cannot be determined, use the passed
> + string. */
> + s = (char *) name;
> + }
> + return strdup (name);
> +}
I think you need to use __strdup here, I am seeing check-local-plt failures on
master.