public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: strptime: make sure to fail on invalid input digits Date: Wed, 21 Feb 2024 18:54:30 +0000 (GMT) [thread overview] Message-ID: <20240221185430.7105A3858419@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=343a2a558153318b37de5fa6afc2d656739f0eed commit 343a2a558153318b37de5fa6afc2d656739f0eed Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Wed Feb 21 19:39:37 2024 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Wed Feb 21 19:39:37 2024 +0100 Cygwin: strptime: make sure to fail on invalid input digits conv_num returns NULL if the input is invalid, e. g., the numbers are out of range. However, the code fails to test this in a lot of places. Rather than adding checks all over the place, rename conv_num to __conv_num and create a wrapper macro conv_num to perform the task of error checking. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/libc/strptime.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/libc/strptime.cc b/winsup/cygwin/libc/strptime.cc index dc557231012d..353b8008a1c9 100644 --- a/winsup/cygwin/libc/strptime.cc +++ b/winsup/cygwin/libc/strptime.cc @@ -301,10 +301,19 @@ first_day (int year) return ret; } -/* This simplifies the calls to conv_num enormously. */ +/* This simplifies the calls to __conv_num enormously. */ #define ALT_DIGITS ((alt_format & ALT_O) ? *alt_digits : NULL) -static const unsigned char *conv_num(const unsigned char *, int *, uint, uint, +#define conv_num(_b,_d,_l,_u,_a) \ + ({ \ + const unsigned char *_ret; \ + _ret = __conv_num((_b),(_d),(_l),(_u),(_a)); \ + if (!_ret) \ + return NULL; \ + _ret; \ + }) + +static const unsigned char *__conv_num(const unsigned char *, int *, uint, uint, alt_digits_t *); static const unsigned char *find_string(const unsigned char *, int *, const char * const *, @@ -842,7 +851,7 @@ strptime (const char *__restrict buf, const char *__restrict fmt, } static const unsigned char * -conv_num(const unsigned char *buf, int *dest, uint llim, uint ulim, +__conv_num(const unsigned char *buf, int *dest, uint llim, uint ulim, alt_digits_t *alt_digits) { uint result = 0;
reply other threads:[~2024-02-21 18:54 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=20240221185430.7105A3858419@sourceware.org \ --to=corinna@sourceware.org \ --cc=cygwin-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).