diff mbox series

[v2] resolv/nss_dns/dns-host: Get rid of alloca.

Message ID 20230810155738.2645097-1-josimmon@redhat.com
State New
Headers show
Series [v2] resolv/nss_dns/dns-host: Get rid of alloca. | expand

Commit Message

Joe Simmons-Talbott Aug. 10, 2023, 3:57 p.m. UTC
Since the alloca is a small constant size use an array instead.
---
Changes to v1:
  * Use sizeof (tmp) rather than NS_MAXDNAME
 resolv/nss_dns/dns-host.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Siddhesh Poyarekar Aug. 11, 2023, 5:38 p.m. UTC | #1
On 2023-08-10 11:57, Joe Simmons-Talbott via Libc-alpha wrote:
> Since the alloca is a small constant size use an array instead.
> ---
> Changes to v1:
>    * Use sizeof (tmp) rather than NS_MAXDNAME
>   resolv/nss_dns/dns-host.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
> index 1d60c51f5e..c8b77bbc35 100644
> --- a/resolv/nss_dns/dns-host.c
> +++ b/resolv/nss_dns/dns-host.c
> @@ -378,6 +378,7 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
>   			   int *herrnop, int32_t *ttlp)
>   {
>     enum nss_status status = check_name (name, herrnop);
> +  char tmp[NS_MAXDNAME];
>     if (status != NSS_STATUS_SUCCESS)
>       return status;
>     struct resolv_context *ctx = __resolv_context_get ();
> @@ -395,8 +396,7 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
>      */
>     if (strchr (name, '.') == NULL)
>       {
> -      char *tmp = alloca (NS_MAXDNAME);

You could keep tmp here, it doesn't have to go into the higher scope.

> -      const char *cp = __res_context_hostalias (ctx, name, tmp, NS_MAXDNAME);
> +      const char *cp = __res_context_hostalias (ctx, name, tmp, sizeof (tmp));
>         if (cp != NULL)
>   	name = cp;
>       }
Joe Simmons-Talbott Aug. 14, 2023, 2:14 p.m. UTC | #2
On Fri, Aug 11, 2023 at 01:38:43PM -0400, Siddhesh Poyarekar wrote:
> 
> 
> On 2023-08-10 11:57, Joe Simmons-Talbott via Libc-alpha wrote:
> > Since the alloca is a small constant size use an array instead.
> > ---
> > Changes to v1:
> >    * Use sizeof (tmp) rather than NS_MAXDNAME
> >   resolv/nss_dns/dns-host.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
> > index 1d60c51f5e..c8b77bbc35 100644
> > --- a/resolv/nss_dns/dns-host.c
> > +++ b/resolv/nss_dns/dns-host.c
> > @@ -378,6 +378,7 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
> >   			   int *herrnop, int32_t *ttlp)
> >   {
> >     enum nss_status status = check_name (name, herrnop);
> > +  char tmp[NS_MAXDNAME];
> >     if (status != NSS_STATUS_SUCCESS)
> >       return status;
> >     struct resolv_context *ctx = __resolv_context_get ();
> > @@ -395,8 +396,7 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
> >      */
> >     if (strchr (name, '.') == NULL)
> >       {
> > -      char *tmp = alloca (NS_MAXDNAME);
> 
> You could keep tmp here, it doesn't have to go into the higher scope.

I moved it back in v3[1].

[1] https://sourceware.org/pipermail/libc-alpha/2023-August/150901.html

Thanks,
Joe
> 
> > -      const char *cp = __res_context_hostalias (ctx, name, tmp, NS_MAXDNAME);
> > +      const char *cp = __res_context_hostalias (ctx, name, tmp, sizeof (tmp));
> >         if (cp != NULL)
> >   	name = cp;
> >       }
>
diff mbox series

Patch

diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index 1d60c51f5e..c8b77bbc35 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -378,6 +378,7 @@  _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
 			   int *herrnop, int32_t *ttlp)
 {
   enum nss_status status = check_name (name, herrnop);
+  char tmp[NS_MAXDNAME];
   if (status != NSS_STATUS_SUCCESS)
     return status;
   struct resolv_context *ctx = __resolv_context_get ();
@@ -395,8 +396,7 @@  _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
    */
   if (strchr (name, '.') == NULL)
     {
-      char *tmp = alloca (NS_MAXDNAME);
-      const char *cp = __res_context_hostalias (ctx, name, tmp, NS_MAXDNAME);
+      const char *cp = __res_context_hostalias (ctx, name, tmp, sizeof (tmp));
       if (cp != NULL)
 	name = cp;
     }