From: Mark Wielaard Date: Mon, 11 Jun 2018 09:22:36 +0000 (+0200) Subject: readelf: Return correct readp (or readendp) from print_form_data. X-Git-Tag: elfutils-0.172~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7aa8e239229cfbd0b230b4a095d0624fbb553055;p=thirdparty%2Felfutils.git readelf: Return correct readp (or readendp) from print_form_data. print_form_data returns the new readp (or readendp on error) to show how much data was consumed. But when reading the .debug_str_offsets section we would reuse readp and readendp. This meant the wrong readp would be returned to the caller. Signed-off-by: Mark Wielaard --- diff --git a/src/ChangeLog b/src/ChangeLog index 6484b9a5c..fd45405f0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2018-06-11 Mark Wielaard + + * readelf.c (print_form_data): Don't reuse readp and readendp when + reading str_offsets section. + 2018-06-10 Mark Wielaard * readelf.c (print_form_data): Don't cast value to ptrdiff_t, cast diff --git a/src/readelf.c b/src/readelf.c index fbda6c17e..f18589711 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -7986,17 +7986,17 @@ print_form_data (Dwarf *dbg, int form, const unsigned char *readp, str = "???"; else { - readp = data->d_buf + str_offsets_base + val; - readendp = data->d_buf + data->d_size; - if ((size_t) (readendp - readp) < offset_len) + const unsigned char *strreadp = data->d_buf + str_offsets_base + val; + const unsigned char *strreadendp = data->d_buf + data->d_size; + if ((size_t) (strreadendp - strreadp) < offset_len) str = "???"; else { Dwarf_Off idx; if (offset_len == 8) - idx = read_8ubyte_unaligned_inc (dbg, readp); + idx = read_8ubyte_unaligned_inc (dbg, strreadp); else - idx = read_4ubyte_unaligned_inc (dbg, readp); + idx = read_4ubyte_unaligned_inc (dbg, strreadp); data = dbg->sectiondata[IDX_debug_str]; if (data == NULL || idx >= data->d_size