* [PATCH] nss: Get rid of alloca usage in files-network's parse_line
@ 2023-09-26 20:17 Joe Simmons-Talbott
0 siblings, 0 replies; only message in thread
From: Joe Simmons-Talbott @ 2023-09-26 20:17 UTC (permalink / raw)
To: libc-alpha; +Cc: Joe Simmons-Talbott
Replace alloca usage with a scratch_buffer.
---
nss/nss_files/files-network.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/nss/nss_files/files-network.c b/nss/nss_files/files-network.c
index c010d21fde..58072ca6b4 100644
--- a/nss/nss_files/files-network.c
+++ b/nss/nss_files/files-network.c
@@ -19,6 +19,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
+#include <scratch_buffer.h>
#include <stdint.h>
#include <nss.h>
@@ -37,6 +38,8 @@ LINE_PARSER
char *addr;
char *cp;
int n = 1;
+ struct scratch_buffer sbuf;
+ scratch_buffer_init (&sbuf);
STRING_FIELD (result->n_name, isspace, 1);
@@ -58,7 +61,11 @@ LINE_PARSER
}
if (n < 4)
{
- char *newp = (char *) alloca (strlen (addr) + (4 - n) * 2 + 1);
+ if (!scratch_buffer_set_array_size (
+ &sbuf, 1, strlen (addr) + (4 - n) * 2 + 1))
+ return -1;
+ char *newp = sbuf.data;
+
cp = stpcpy (newp, addr);
do
{
@@ -71,6 +78,7 @@ LINE_PARSER
}
result->n_net = __inet_network (addr);
result->n_addrtype = AF_INET;
+ scratch_buffer_free (&sbuf);
})
--
2.39.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-09-26 20:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-26 20:17 [PATCH] nss: Get rid of alloca usage in files-network's parse_line Joe Simmons-Talbott
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).