diff mbox series

libc_fatal: Add comment regarding alloca usage.

Message ID 20230620184154.3804141-1-josimmon@redhat.com
State New
Headers show
Series libc_fatal: Add comment regarding alloca usage. | expand

Commit Message

Joe Simmons-Talbott June 20, 2023, 6:41 p.m. UTC
Since __libc_message is only used in a few places and always with a
const char * format string and a small fixed-sized struct the usage of
alloca here is safe.  Add a comment explaining this for both alloca
usages.
---
 sysdeps/posix/libc_fatal.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Joe Simmons-Talbott July 5, 2023, 3:16 p.m. UTC | #1
On Tue, Jun 20, 2023 at 02:41:54PM -0400, Joe Simmons-Talbott wrote:
> Since __libc_message is only used in a few places and always with a
> const char * format string and a small fixed-sized struct the usage of
> alloca here is safe.  Add a comment explaining this for both alloca
> usages.

Ping.

Thanks,
Joe
> ---
>  sysdeps/posix/libc_fatal.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c
> index 70edcc10c1..caa01bcbf6 100644
> --- a/sysdeps/posix/libc_fatal.c
> +++ b/sysdeps/posix/libc_fatal.c
> @@ -100,6 +100,9 @@ __libc_message (const char *fmt, ...)
>  	  cp = next;
>  	}
>  
> +      /* alloca is safe here since the current usage of __libc_message uses
> +         relatively short const char * format strings and a small fixed size
> +         struct. */
>        struct str_list *newp = alloca (sizeof (struct str_list));
>        newp->str = str;
>        newp->len = len;
> @@ -110,6 +113,9 @@ __libc_message (const char *fmt, ...)
>  
>    if (nlist > 0)
>      {
> +      /* alloca is safe here since the current usage of __libc_message uses
> +         relatively short const char * format strings and a small fixed size
> +         struct. */
>        struct iovec *iov = alloca (nlist * sizeof (struct iovec));
>        ssize_t total = 0;
>  
> -- 
> 2.39.2
>
diff mbox series

Patch

diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c
index 70edcc10c1..caa01bcbf6 100644
--- a/sysdeps/posix/libc_fatal.c
+++ b/sysdeps/posix/libc_fatal.c
@@ -100,6 +100,9 @@  __libc_message (const char *fmt, ...)
 	  cp = next;
 	}
 
+      /* alloca is safe here since the current usage of __libc_message uses
+         relatively short const char * format strings and a small fixed size
+         struct. */
       struct str_list *newp = alloca (sizeof (struct str_list));
       newp->str = str;
       newp->len = len;
@@ -110,6 +113,9 @@  __libc_message (const char *fmt, ...)
 
   if (nlist > 0)
     {
+      /* alloca is safe here since the current usage of __libc_message uses
+         relatively short const char * format strings and a small fixed size
+         struct. */
       struct iovec *iov = alloca (nlist * sizeof (struct iovec));
       ssize_t total = 0;