public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: elfutils-devel@sourceware.org
Subject: [PATCH] libdwfl: fix crash when reading link map
Date: Wed,  9 Jun 2021 17:45:57 -0700	[thread overview]
Message-ID: <9d6fa5673b548c600c23005388bb5e909983acb1.1623285930.git.osandov@fb.com> (raw)

From: Omar Sandoval <osandov@fb.com>

When read_addrs() was converted was converted from a nested function to
a normal function, there was a mistake in converting "buffer" from a
closure variable to a parameter: we are checking whether the pointer
argument is NULL, not whether the buffer itself is NULL. This causes a
NULL pointer dereference when we try to use the NULL buffer later.

Fixes: 3bf41d458fb6 ("link_map: Pull read_addrs() into file scope") made
Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 libdwfl/ChangeLog  | 4 ++++
 libdwfl/link_map.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index fedf65a4..c57c7708 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,7 @@
+2021-06-09  Omar Sandoval  <osandov@fb.com>
+
+	* link_map.c (read_addrs): Fix crash.
+
 2021-04-19  Martin Liska  <mliska@suse.cz>
 
 	* dwfl_frame.c (dwfl_attach_state): Use startswith.
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 0d8d1c17..1e7d4502 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -254,7 +254,7 @@ read_addrs (struct memory_closure *closure,
   Dwfl *dwfl = closure->dwfl;
 
   /* Read a new buffer if the old one doesn't cover these words.  */
-  if (buffer == NULL
+  if (*buffer == NULL
       || vaddr < *read_vaddr
       || vaddr - (*read_vaddr) + nb > *buffer_available)
     {
-- 
2.32.0


             reply	other threads:[~2021-06-10  0:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-10  0:45 Omar Sandoval [this message]
2021-06-10  0:51 ` Omar Sandoval
2021-06-10  0:59   ` Érico Nogueira
2021-06-10  1:02     ` Omar Sandoval
2021-06-10 10:44 ` Dmitry V. Levin

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=9d6fa5673b548c600c23005388bb5e909983acb1.1623285930.git.osandov@fb.com \
    --to=osandov@osandov.com \
    --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).