public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] time: Remove alloca() from getdate Date: Fri, 5 May 2023 14:56:23 +0000 (GMT) [thread overview] Message-ID: <20230505145623.B6F123858D33@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=21f0b087ee10391433d8279e7c6f104fb9ea0eef commit 21f0b087ee10391433d8279e7c6f104fb9ea0eef Author: Joe Simmons-Talbott <josimmon@redhat.com> Date: Wed May 3 12:40:05 2023 -0400 time: Remove alloca() from getdate Reduce the usage of alloca() to the bare minimum to avoid the potential for stack overflow. Use __strndup to simplify the code. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org> Diff: --- time/getdate.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/time/getdate.c b/time/getdate.c index c5c8378707..1dcbd77188 100644 --- a/time/getdate.c +++ b/time/getdate.c @@ -26,7 +26,6 @@ #include <unistd.h> #include <sys/stat.h> #include <ctype.h> -#include <alloca.h> #define TM_YEAR_BASE 1900 @@ -153,26 +152,14 @@ __getdate_r (const char *string, struct tm *tp) if (inlen < oldlen) { - bool using_malloc = false; - - if (__libc_use_alloca (inlen + 1)) - instr = alloca (inlen + 1); - else + instr = __strndup(string, inlen); + if (instr == NULL) { - instr = malloc (inlen + 1); - if (instr == NULL) - { - fclose (fp); - return 6; - } - using_malloc = true; + fclose(fp); + return 6; } - memcpy (instr, string, inlen); - instr[inlen] = '\0'; - string = instr; - if (!using_malloc) - instr = NULL; + string = instr; } line = NULL;
reply other threads:[~2023-05-05 14:56 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230505145623.B6F123858D33@sourceware.org \ --to=siddhesh@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).