diff mbox series

resolv: Get rid of alloca usage.

Message ID 20230921161613.3609632-1-josimmon@redhat.com
State New
Headers show
Series resolv: Get rid of alloca usage. | expand

Commit Message

Joe Simmons-Talbott Sept. 21, 2023, 4:16 p.m. UTC
Replace alloca usage with char arrays in _nss_dns_getnetbyaddr_r and
_nss_dns_getnetbyaddr_r.
---
 resolv/nss_dns/dns-network.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Andreas Schwab Sept. 21, 2023, 5:36 p.m. UTC | #1
On Sep 21 2023, Joe Simmons-Talbott wrote:

> diff --git a/resolv/nss_dns/dns-network.c b/resolv/nss_dns/dns-network.c
> index 1e6511a4f4..b67542c078 100644
> --- a/resolv/nss_dns/dns-network.c
> +++ b/resolv/nss_dns/dns-network.c
> @@ -116,6 +116,7 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
>    querybuf *orig_net_buffer;
>    int anslen;
>    enum nss_status status;
> +  char buf[1024];
>  
>    struct resolv_context *ctx = __resolv_context_get ();
>    if (ctx == NULL)
> @@ -125,7 +126,7 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
>        return NSS_STATUS_UNAVAIL;
>      }
>  
> -  net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
> +  net_buffer.buf = orig_net_buffer = (querybuf *) &buf;

The buffer should be suitably aligned for querybuf.  Since buf is an
array, it should not get an address-of operator.
Joe Simmons-Talbott Sept. 22, 2023, 2:24 p.m. UTC | #2
On Thu, Sep 21, 2023 at 07:36:08PM +0200, Andreas Schwab wrote:
> On Sep 21 2023, Joe Simmons-Talbott wrote:
> 
> > diff --git a/resolv/nss_dns/dns-network.c b/resolv/nss_dns/dns-network.c
> > index 1e6511a4f4..b67542c078 100644
> > --- a/resolv/nss_dns/dns-network.c
> > +++ b/resolv/nss_dns/dns-network.c
> > @@ -116,6 +116,7 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
> >    querybuf *orig_net_buffer;
> >    int anslen;
> >    enum nss_status status;
> > +  char buf[1024];
> >  
> >    struct resolv_context *ctx = __resolv_context_get ();
> >    if (ctx == NULL)
> > @@ -125,7 +126,7 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
> >        return NSS_STATUS_UNAVAIL;
> >      }
> >  
> > -  net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
> > +  net_buffer.buf = orig_net_buffer = (querybuf *) &buf;
> 
> The buffer should be suitably aligned for querybuf.  Since buf is an
> array, it should not get an address-of operator.
> 

I've posted a v2 which hopefully addresses this.

Thanks,
Joe
diff mbox series

Patch

diff --git a/resolv/nss_dns/dns-network.c b/resolv/nss_dns/dns-network.c
index 1e6511a4f4..b67542c078 100644
--- a/resolv/nss_dns/dns-network.c
+++ b/resolv/nss_dns/dns-network.c
@@ -116,6 +116,7 @@  _nss_dns_getnetbyname_r (const char *name, struct netent *result,
   querybuf *orig_net_buffer;
   int anslen;
   enum nss_status status;
+  char buf[1024];
 
   struct resolv_context *ctx = __resolv_context_get ();
   if (ctx == NULL)
@@ -125,7 +126,7 @@  _nss_dns_getnetbyname_r (const char *name, struct netent *result,
       return NSS_STATUS_UNAVAIL;
     }
 
-  net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
+  net_buffer.buf = orig_net_buffer = (querybuf *) &buf;
 
   anslen = __res_context_search
     (ctx, name, C_IN, T_PTR, net_buffer.buf->buf,
@@ -170,6 +171,7 @@  _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
   int cnt, anslen;
   uint32_t net2;
   int olderr = errno;
+  char buf[1024];
 
   /* No net address lookup for IPv6 yet.  */
   if (type != AF_INET)
@@ -209,7 +211,7 @@  _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
       break;
     }
 
-  net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
+  net_buffer.buf = orig_net_buffer = (querybuf *) &buf;
 
   anslen = __res_context_query (ctx, qbuf, C_IN, T_PTR, net_buffer.buf->buf,
 				1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);