public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] libdw: Add sanity check to store_implicit_value
Date: Mon,  9 May 2022 18:48:58 +0200	[thread overview]
Message-ID: <20220509164858.26359-1-mark@klomp.org> (raw)

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(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 631f2f2a..b254d9cd 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -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.
diff --git a/libdw/dwarf_getlocation.c b/libdw/dwarf_getlocation.c
index 5db3cf97..d0d78163 100644
--- a/libdw/dwarf_getlocation.c
+++ b/libdw/dwarf_getlocation.c
@@ -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;
-- 
2.18.4


             reply	other threads:[~2022-05-09 16:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-09 16:48 Mark Wielaard [this message]
2022-05-14 13:40 ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220509164858.26359-1-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).