diff mbox series

resolv/nss_dns/dns-host: Note the usage of alloca is safe.

Message ID 20230705185835.1474212-1-josimmon@redhat.com
State New
Headers show
Series resolv/nss_dns/dns-host: Note the usage of alloca is safe. | expand

Commit Message

Joe Simmons-Talbott July 5, 2023, 6:58 p.m. UTC
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(+)

Comments

Joe Simmons-Talbott Aug. 10, 2023, 1:46 p.m. UTC | #1
On Wed, Jul 05, 2023 at 02:58:35PM -0400, Joe Simmons-Talbott wrote:
> Since the size is relatively small and constant add a comment that the
> usage of alloca is safe.

Ping.

Thanks,
Joe
> ---
>  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);
>        const char *cp = __res_context_hostalias (ctx, name, tmp, NS_MAXDNAME);
>        if (cp != NULL)
> -- 
> 2.39.2
>
Andreas Schwab Aug. 10, 2023, 2:02 p.m. UTC | #2
On Jul 05 2023, 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);

Since this is a constant allocation, I think it would be better to just
declare it as a regular array in the enclosing block.
Xi Ruoyao Aug. 10, 2023, 2:07 p.m. UTC | #3
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)
Joe Simmons-Talbott Aug. 10, 2023, 3:16 p.m. UTC | #4
On Thu, Aug 10, 2023 at 10:07:34PM +0800, Xi Ruoyao wrote:
> 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?
> 
Dropped in favor of
https://sourceware.org/pipermail/libc-alpha/2023-August/150819.html

Thanks,
Joe
> >        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
>
diff mbox series

Patch

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);
       const char *cp = __res_context_hostalias (ctx, name, tmp, NS_MAXDNAME);
       if (cp != NULL)