[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Error out on invalid locexpr length



On 07-03-19 08:12, Tom de Vries wrote:
> Hi,
> 
> When invoking dwz with a file containing an invalid locexpr length, we can run
> into this assertion:
> ...
> dwz: dwz.c:1722: read_loclist: Assertion `ptr + len <= endsec' failed.
> Aborted (core dumped)
> ...
> 

To address your questions about origin of test-cases, in this case it's
dw2-skip-prologue.S (
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/testsuite/gdb.dwarf2/dw2-skip-prologue.S;h=cef6e6df12940744c1bc19c9e76fbeb762f80087;hb=HEAD
).

AFAIU, the invalid dwarf is hand-coded, and fixed by:
...
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-skip-prologue.S
b/gdb/testsuite/gdb.dwarf2/dw2-skip-prologue.S
index cef6e6df12..a55699fdc6 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-skip-prologue.S
+++ b/gdb/testsuite/gdb.dwarf2/dw2-skip-prologue.S
@@ -123,7 +123,7 @@
        .section        .debug_loc
 loclist:
        /* Reset the location list base address first.  */
-       .4byte          -1, 0
+       PTRBYTE         -1, 0

        PTRBYTE         func_start, func_end
        .2byte          2f-1f
...

Thanks,
- Tom

> Change the assert into an error:
> ...
> dwz: a.out: locexpr length 0x4ef exceeds .debug_loc section
> ...
> 
> OK for trunk?
> 
> Thanks,
> - Tom
> 
> Error out on invalid locexpr length
> 
> 2019-02-14  Tom de Vries  <tdevries@suse.de>
> 
> 	PR dwz/24172
> 	* dwz.c (read_loclist): Change assert (ptr + len <= endsec) into an
> 	error.
> 
> ---
>  dwz.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/dwz.c b/dwz.c
> index 4ef8657..a876ab2 100644
> --- a/dwz.c
> +++ b/dwz.c
> @@ -1719,7 +1719,13 @@ read_loclist (DSO *dso, dw_die_ref die, GElf_Addr offset)
>  	continue;
>  
>        len = read_16 (ptr);
> -      assert (ptr + len <= endsec);
> +      if (!(ptr + len <= endsec))
> +	{
> +	  error (0, 0,
> +		 "%s: locexpr length 0x%Lx exceeds .debug_loc section",
> +		 dso->filename, (long long) len);
> +	  return 1;
> +	}
>  
>        if (read_exprloc (dso, die, ptr, len, &need_adjust))
>  	return 1;
>