From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 923A83858D33; Wed, 21 Feb 2024 19:03:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 923A83858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1708542190; bh=hl9+nYZHSgb39A69nrMbZ/NnX6XXnmez1vNy3I4gPLo=; h=From:To:Subject:Date:From; b=tlIx54m3cCWz2C6DxFCyc2fzn0fXracbfLmK2ZWg61/KaSjnXEbv+70bk7rykzy// 1ivAFBJp2MVjv02+AwRMkP6RgbAiPjN7x6qnSBUcgBsuAlhemxAyzhaWwYeAv7zXwz 2RqfbDrzVpLl1iRSfQCREtJABM/1CUODSRaraIp0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_5-branch] Cygwin: strptime: make sure to fail on invalid input digits X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/cygwin-3_5-branch X-Git-Oldrev: 12b85bec0e4db176cb5c6534f01bef62fb15c44b X-Git-Newrev: f0ab27c0954e9529109e00c905be2d1ea88a749a Message-Id: <20240221190310.923A83858D33@sourceware.org> Date: Wed, 21 Feb 2024 19:03:10 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Df0ab27c0954= e9529109e00c905be2d1ea88a749a commit f0ab27c0954e9529109e00c905be2d1ea88a749a Author: Corinna Vinschen AuthorDate: Wed Feb 21 19:39:37 2024 +0100 Commit: Corinna Vinschen CommitDate: Wed Feb 21 20:00:59 2024 +0100 Cygwin: strptime: make sure to fail on invalid input digits =20 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. =20 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. =20 Signed-off-by: Corinna Vinschen 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; } =20 -/* 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) =20 -static const unsigned char *conv_num(const unsigned char *, int *, uint, u= int, +#define conv_num(_b,_d,_l,_u,_a) \ + ({ \ + const unsigned char *_ret; \ + _ret =3D __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 *__res= trict fmt, } =20 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 =3D 0;