[PATCH] resolv/nss_dns/dns-host: Note the usage of alloca is safe.
Xi Ruoyao
xry111@xry111.site
Thu Aug 10 14:07:34 GMT 2023
On Wed, 2023-07-05 at 14:58 -0400, Joe Simmons-Talbott via Libc-alpha wrote:
> Since the size is relatively small and constant add a comment that the
> usage of alloca is safe.
> ---
> resolv/nss_dns/dns-host.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
> index 1d60c51f5e..d3aaeec293 100644
> --- a/resolv/nss_dns/dns-host.c
> +++ b/resolv/nss_dns/dns-host.c
> @@ -395,6 +395,7 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
> */
> if (strchr (name, '.') == NULL)
> {
> + /* alloca is safe here since the size is small and constant. */
> char *tmp = alloca (NS_MAXDNAME);
But then why don't we simply say "char tmp[NS_MAXDNAME];" here?
> const char *cp = __res_context_hostalias (ctx, name, tmp, NS_MAXDNAME);
> if (cp != NULL)
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
More information about the Libc-alpha
mailing list