libdw: Add sanity check to store_implicit_value
Commit Message
Don't just skip the block length, but check it is equal to the
op->number that we are going to use as length.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
libdw/ChangeLog | 4 ++++
libdw/dwarf_getlocation.c | 5 ++++-
2 files changed, 8 insertions(+), 1 deletion(-)
Comments
Hi,
On Mon, May 09, 2022 at 06:48:58PM +0200, Mark Wielaard wrote:
> Don't just skip the block length, but check it is equal to the
> op->number that we are going to use as length.
Pushed.
Cheers,
Mark
@@ -1,3 +1,7 @@
+2022-05-09 Mark Wielaard <mark@klomp.org>
+
+ * dwarf_getlocation.c (store_implicit_value): Check block length.
+
2022-04-16 Mark Wielaard <mark@klomp.org>
* libdwP.h: Remove atomics.h include.
@@ -147,7 +147,10 @@ store_implicit_value (Dwarf *dbg, void **cache, Dwarf_Op *op)
sizeof (struct loc_block_s), 1);
const unsigned char *data = (const unsigned char *) (uintptr_t) op->number2;
/* Skip the block length. */
- __libdw_get_uleb128_unchecked (&data);
+ Dwarf_Word length;
+ get_uleb128_unchecked (length, data);
+ if (length != op->number)
+ return -1;
block->addr = op;
block->data = (unsigned char *) data;
block->length = op->number;