[PATCH] libc_fatal: Add comment regarding alloca usage.

Joe Simmons-Talbott josimmon@redhat.com
Tue Jun 20 18:41:54 GMT 2023


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(+)

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



More information about the Libc-alpha mailing list