We checked there were enough bytes left after reading the
line_offset. Move the check before the read.
* libdw/dwarf_getmacros.c (get_table_for_offset): Check
offset_bytes before calling read_addr_unaligned_inc.
https://sourceware.org/bugzilla/show_bug.cgi?id=34382
Reported-by: Karan Kurani <karankurani3k@gmail.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
{
const unsigned char *startp = readp;
- /* Request at least 3 bytes for header. */
+ /* Request at least 3 bytes for header (version 2 bytes, flag 1 byte). */
if (readp + 3 > endp)
{
invalid_dwarf:
Dwarf_Off line_offset = (Dwarf_Off) -1;
if ((flags & 0x2) != 0)
{
- line_offset = read_addr_unaligned_inc (is_64bit ? 8 : 4, dbg, readp);
- if (readp > endp)
+ int offset_bytes = is_64bit ? 8 : 4;
+ if (readp >= endp - offset_bytes)
goto invalid_dwarf;
+ line_offset = read_addr_unaligned_inc (offset_bytes, dbg, readp);
}
else if (cudie != NULL)
{