public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Arjun Shankar <arjun@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] time: Fix use-after-free in getdate Date: Tue, 6 Jun 2023 19:18:19 +0000 (GMT) [thread overview] Message-ID: <20230606191819.7CA483858C5F@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=85e6d8b4175fcb195011a0a1bad37d6f3b2355db commit 85e6d8b4175fcb195011a0a1bad37d6f3b2355db Author: Arjun Shankar <arjun@redhat.com> Date: Tue Jun 6 19:20:31 2023 +0200 time: Fix use-after-free in getdate getdate would free the buffer pointed to by the result of its call to strptime, then reference the same buffer later on -- leading to a use-after-free. This commit fixes that. Reported-by: Martin Coufal <mcoufal@redhat.com> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> Diff: --- time/getdate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/time/getdate.c b/time/getdate.c index 1dcbd77188..ca058394a3 100644 --- a/time/getdate.c +++ b/time/getdate.c @@ -114,6 +114,7 @@ __getdate_r (const char *string, struct tm *tp) struct tm tm; struct __stat64_t64 st; bool mday_ok = false; + bool found = false; datemsk = getenv ("DATEMSK"); if (datemsk == NULL || *datemsk == '\0') @@ -181,7 +182,7 @@ __getdate_r (const char *string, struct tm *tp) tp->tm_gmtoff = 0; tp->tm_zone = NULL; result = strptime (string, line, tp); - if (result && *result == '\0') + if ((found = (result && *result == '\0'))) break; } while (!__feof_unlocked (fp)); @@ -201,7 +202,7 @@ __getdate_r (const char *string, struct tm *tp) /* Close template file. */ fclose (fp); - if (result == NULL || *result != '\0') + if (!found) return 7; /* Get current time. */
reply other threads:[~2023-06-06 19:18 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=20230606191819.7CA483858C5F@sourceware.org \ --to=arjun@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).