summaryrefslogtreecommitdiff
path: root/binutils/dwarf.h
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2021-07-10 09:34:30 +0930
committerAlan Modra <amodra@gmail.com>2021-07-10 13:23:54 +0930
commit9039747fb4863c13eaf07f84bb28d50660fb8d85 (patch)
tree1d5385789086f82eb6db07ccbb2a12e18eaf5eba /binutils/dwarf.h
parent34c54daa337da9fadf87d2706d6a590ae1f88f4d (diff)
downloadbinutils-gdb-9039747fb4863c13eaf07f84bb28d50660fb8d85.tar.gz
PR28069, assertion fail in dwarf.c:display_discr_list
We shouldn't be asserting on anything to do with leb128 values, or reporting file and line numbers when something unexpected happens. leb128 data is of indeterminate length, perfect for fuzzer mayhem. It would only make sense to assert or report dwarf.c/readelf.c source lines if the code had already sized and sanity checked the leb128 values. After removing the assertions, the testcase then gave: <37> DW_AT_discr_list : 5 byte block: 0 0 0 0 0 (label 0, label 0, label 0, label 0, <corrupt> readelf: Warning: corrupt discr_list - unrecognized discriminant byte 0x5 <3d> DW_AT_encoding : 0 (void) <3e> DW_AT_identifier_case: 0 (case_sensitive) <3f> DW_AT_virtuality : 0 (none) <40> DW_AT_decimal_sign: 5 (trailing separate) So the DW_AT_discr_list was showing more data than just the 5 byte block. That happened due to "end" pointing a long way past the end of block, and uvalue decrementing past zero on one of the leb128 bytes. PR 28069 * dwarf.c (display_discr_list): Remove assertions. Delete "end" parameter, use initial "data" pointer as the end. Formatting. Don't count down bytes as they are read. (read_and_display_attr_value): Adjust display_discr_list call. (read_and_print_leb128): Don't pass __FILE__ and __LINE__ to report_leb_status. * dwarf.h (report_leb_status): Don't report file and line numbers. Delete file and lnum parameters, (READ_ULEB, READ_SLEB): Adjust.
Diffstat (limited to 'binutils/dwarf.h')
-rw-r--r--binutils/dwarf.h10
1 files changed, 5 insertions, 5 deletions
diff --git a/binutils/dwarf.h b/binutils/dwarf.h
index 2070c6f3daf..887b720f632 100644
--- a/binutils/dwarf.h
+++ b/binutils/dwarf.h
@@ -264,12 +264,12 @@ extern unsigned char * get_build_id (void *);
#endif
static inline void
-report_leb_status (int status, const char *file, unsigned long lnum)
+report_leb_status (int status)
{
if ((status & 1) != 0)
- error (_("%s:%lu: end of data encountered whilst reading LEB\n"), file, lnum);
+ error (_("end of data encountered whilst reading LEB\n"));
else if ((status & 2) != 0)
- error (_("%s:%lu: read LEB value is too large to store in destination variable\n"), file, lnum);
+ error (_("read LEB value is too large to store in destination variable\n"));
}
#define SKIP_ULEB(start, end) \
@@ -302,7 +302,7 @@ report_leb_status (int status, const char *file, unsigned long lnum)
(var) = _val; \
if ((var) != _val) \
_status |= 2; \
- report_leb_status (_status, __FILE__, __LINE__); \
+ report_leb_status (_status); \
} \
while (0)
@@ -318,6 +318,6 @@ report_leb_status (int status, const char *file, unsigned long lnum)
(var) = _val; \
if ((var) != _val) \
_status |= 2; \
- report_leb_status (_status, __FILE__, __LINE__); \
+ report_leb_status (_status); \
} \
while (0)