diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2023-05-25 08:14:37 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2023-05-25 09:28:23 -0300 |
commit | 95c9a6e806226cbf174c92efc021a0d464f170a4 (patch) | |
tree | 0a02ebbc928a183e2328c265494b1915f5b658b8 /stdlib/strtol_l.c | |
parent | e0189b25403f8b67e7a5513d6c33fb09cb2e5e20 (diff) | |
download | glibc-95c9a6e806226cbf174c92efc021a0d464f170a4.zip glibc-95c9a6e806226cbf174c92efc021a0d464f170a4.tar.gz glibc-95c9a6e806226cbf174c92efc021a0d464f170a4.tar.bz2 |
Fix special case for C2x strtol binary constant handling (BZ# 30371)
When the base is 0 or 2 and the first two characters are '0' and 'b',
but the rest are no binary digits. In this case this is no error,
and strtol must return 0 and ENDPTR points to the 'x' or 'b'.
Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Diffstat (limited to 'stdlib/strtol_l.c')
-rw-r--r-- | stdlib/strtol_l.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/stdlib/strtol_l.c b/stdlib/strtol_l.c index 3424c3f..548b46a 100644 --- a/stdlib/strtol_l.c +++ b/stdlib/strtol_l.c @@ -526,11 +526,15 @@ INTERNAL (__strtol_l) (const STRING_TYPE *nptr, STRING_TYPE **endptr, noconv: /* We must handle a special case here: the base is 0 or 16 and the first two characters are '0' and 'x', but the rest are no - hexadecimal digits. This is no error case. We return 0 and - ENDPTR points to the `x`. */ + hexadecimal digits. Likewise when the base is 0 or 2 and the + first two characters are '0' and 'b', but the rest are no binary + digits. This is no error case. We return 0 and ENDPTR points to + the 'x' or 'b'. */ if (endptr != NULL) { - if (save - nptr >= 2 && TOUPPER (save[-1]) == L_('X') + if (save - nptr >= 2 + && (TOUPPER (save[-1]) == L_('X') + || (bin_cst && TOUPPER (save[-1]) == L_('B'))) && save[-2] == L_('0')) *endptr = (STRING_TYPE *) &save[-1]; else |