diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2024-02-21 19:39:37 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2024-02-21 19:39:37 +0100 |
commit | 343a2a558153318b37de5fa6afc2d656739f0eed (patch) | |
tree | 3a89786f99b089e25bbfab5699152cb26c756ae2 /winsup | |
parent | acf176104fc5410bfec0635ed2c5a21971b9c938 (diff) | |
download | newlib-343a2a558153318b37de5fa6afc2d656739f0eed.zip newlib-343a2a558153318b37de5fa6afc2d656739f0eed.tar.gz newlib-343a2a558153318b37de5fa6afc2d656739f0eed.tar.bz2 |
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>
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/libc/strptime.cc | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/winsup/cygwin/libc/strptime.cc b/winsup/cygwin/libc/strptime.cc index dc55723..353b800 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; |