diff options
author | Pedro Alves <pedro@palves.net> | 2022-04-07 18:01:12 +0100 |
---|---|---|
committer | Pedro Alves <pedro@palves.net> | 2022-04-08 16:19:15 +0100 |
commit | 01772c548b91499272dcb0f6864ba990e2abf873 (patch) | |
tree | ea4bf0aad239a0dbb8e2a2876ae9e59cae501a00 /gdb/f-exp.y | |
parent | 7d41169b6d4dbc3950516d0cdf0d8ca462b52bbb (diff) | |
download | gdb-01772c548b91499272dcb0f6864ba990e2abf873.zip gdb-01772c548b91499272dcb0f6864ba990e2abf873.tar.gz gdb-01772c548b91499272dcb0f6864ba990e2abf873.tar.bz2 |
Fix undefined behavior in the Fortran, Go and Pascal number parsers
This commit ports these two fixes to the C parser:
commit ebf13736b42af47c9907b5157c8e80c78dbe00e1
CommitDate: Thu Sep 4 21:46:28 2014 +0100
parse_number("0") reads uninitialized memory
commit 20562150d8a894bc91657c843ee88c508188e32e
CommitDate: Wed Oct 3 15:19:06 2018 -0600
Avoid undefined behavior in parse_number
... to the Fortran, Go, and Fortran number parsers, fixing the same
problems there.
Also add a new testcase that exercises printing 0xffffffffffffffff
(max 64-bit) in all languages, which crashes a GDB built with UBsan
without the fix.
I moved get_set_option_choices out of all-architectures.exp.tcl to
common code to be able to extract all the supported languages. I did
a tweak to it to generalize it a bit -- you now have to pass down the
"set" part of the command as well. This is so that the proc can be
used with "maintenance set" commands as well in future.
Change-Id: I8e8f2fdc1e8407f63d923c26fd55d98148b9e16a
Diffstat (limited to 'gdb/f-exp.y')
-rw-r--r-- | gdb/f-exp.y | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/gdb/f-exp.y b/gdb/f-exp.y index f9622e6..ae5cc4e 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -837,8 +837,8 @@ static int parse_number (struct parser_state *par_state, const char *p, int len, int parsed_float, YYSTYPE *putithere) { - LONGEST n = 0; - LONGEST prevn = 0; + ULONGEST n = 0; + ULONGEST prevn = 0; int c; int base = input_radix; int unsigned_p = 0; @@ -869,7 +869,7 @@ parse_number (struct parser_state *par_state, } /* Handle base-switching prefixes 0x, 0t, 0d, 0 */ - if (p[0] == '0') + if (p[0] == '0' && len > 1) switch (p[1]) { case 'x': @@ -929,7 +929,7 @@ parse_number (struct parser_state *par_state, /* If range checking enabled, portably test for unsigned overflow. */ if (RANGE_CHECK && n != 0) { - if ((unsigned_p && (unsigned)prevn >= (unsigned)n)) + if ((unsigned_p && prevn >= n)) range_error (_("Overflow on numeric constant.")); } prevn = n; |