public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] grantpt: Get rid of alloca
@ 2023-06-17 23:08 Samuel Thibault
0 siblings, 0 replies; only message in thread
From: Samuel Thibault @ 2023-06-17 23:08 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=01dd2875f85213b26beefb66caad3564da89d1d1
commit 01dd2875f85213b26beefb66caad3564da89d1d1
Author: Joe Simmons-Talbott <josimmon@redhat.com>
Date: Tue Jun 13 15:16:31 2023 -0400
grantpt: Get rid of alloca
Replace alloca with a scratch_buffer to avoid potential stack overflows.
Message-Id: <20230613191631.1080455-1-josimmon@redhat.com>
Diff:
---
sysdeps/unix/grantpt.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/sysdeps/unix/grantpt.c b/sysdeps/unix/grantpt.c
index 38fce52576..226e7adb75 100644
--- a/sysdeps/unix/grantpt.c
+++ b/sysdeps/unix/grantpt.c
@@ -20,6 +20,7 @@
#include <fcntl.h>
#include <grp.h>
#include <limits.h>
+#include <scratch_buffer.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
@@ -147,10 +148,19 @@ grantpt (int fd)
/* `sysconf' does not support _SC_GETGR_R_SIZE_MAX.
Try a moderate value. */
grbuflen = 1024;
- grtmpbuf = (char *) __alloca (grbuflen);
+ struct scratch_buffer sbuf;
+ scratch_buffer_init (&sbuf);
+ if (!scratch_buffer_set_array_size (&sbuf, 1, grbuflen))
+ {
+ retval = -1;
+ goto cleanup;
+ }
+ grtmpbuf = sbuf.data;
__getgrnam_r (TTY_GROUP, &grbuf, grtmpbuf, grbuflen, &p);
if (p != NULL)
tty_gid = p->gr_gid;
+
+ scratch_buffer_free(&sbuf);
}
gid_t gid = tty_gid == -1 ? __getgid () : tty_gid;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-06-17 23:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-17 23:08 [glibc] grantpt: Get rid of alloca Samuel Thibault
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).