[Bug middle-end/114540] Use of atoi in varasm.cc (decode_reg_name_and_count) allows invalid registers

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Dec 3 08:48:46 GMT 2024


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114540

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:4acab372d31a9fe9184ccc247780940821cda367

commit r15-5877-g4acab372d31a9fe9184ccc247780940821cda367
Author: Heiko Eißfeldt <heiko@hexco.de>
Date:   Tue Dec 3 09:47:59 2024 +0100

    replace atoi with strtoul in varasm.cc (decode_reg_name_and_count)
[PR114540]

    The function uses atoi, which can silently return valid numbers even for
    some too large numbers in the string.

    Furthermore, the verification that all the characters in asmspec are
    decimal digits can be simplified when using strotoul, we can check just
    the first digit and whether the end pointer points to '\0'.

    2024-12-03  Heiko Eißfeldt  <heiko@hexco.de>

            PR middle-end/114540
            * varasm.cc (decode_reg_name_and_count): Use strtoul instead of
atoi
            and simplify verification that the whole asmspec contains just
decimal
            digits.

            * gcc.dg/pr114540.c: New test.

    Signed-off-by: Heiko Eißfeldt <heiko@hexco.de>
    Co-authored-by: Jakub Jelinek <jakub@redhat.com>


More information about the Gcc-bugs mailing list