public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libdwfl: fix crash when reading link map
@ 2021-06-10  0:45 Omar Sandoval
  2021-06-10  0:51 ` Omar Sandoval
  2021-06-10 10:44 ` Dmitry V. Levin
  0 siblings, 2 replies; 5+ messages in thread
From: Omar Sandoval @ 2021-06-10  0:45 UTC (permalink / raw)
  To: elfutils-devel

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libdwfl: fix crash when reading link map
  2021-06-10  0:45 [PATCH] libdwfl: fix crash when reading link map Omar Sandoval
@ 2021-06-10  0:51 ` Omar Sandoval
  2021-06-10  0:59   ` Érico Nogueira
  2021-06-10 10:44 ` Dmitry V. Levin
  1 sibling, 1 reply; 5+ messages in thread
From: Omar Sandoval @ 2021-06-10  0:51 UTC (permalink / raw)
  To: elfutils-devel

On Wed, Jun 09, 2021 at 05:45:57PM -0700, Omar Sandoval wrote:
> 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
                                                                      ^^^^
Stray word here, hopefully not too much trouble to fix up when applying.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libdwfl: fix crash when reading link map
  2021-06-10  0:51 ` Omar Sandoval
@ 2021-06-10  0:59   ` Érico Nogueira
  2021-06-10  1:02     ` Omar Sandoval
  0 siblings, 1 reply; 5+ messages in thread
From: Érico Nogueira @ 2021-06-10  0:59 UTC (permalink / raw)
  To: Omar Sandoval, elfutils-devel

Hope you don't mind my nit, then :)

On Wed Jun 9, 2021 at 9:51 PM -03, Omar Sandoval wrote:
> On Wed, Jun 09, 2021 at 05:45:57PM -0700, Omar Sandoval wrote:
> > From: Omar Sandoval <osandov@fb.com>
> > 
> > When read_addrs() was converted was converted from a nested function to
                                    ^^^^^^^^^^^^^ repeated words
> > 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
> ^^^^
> Stray word here, hopefully not too much trouble to fix up when applying.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libdwfl: fix crash when reading link map
  2021-06-10  0:59   ` Érico Nogueira
@ 2021-06-10  1:02     ` Omar Sandoval
  0 siblings, 0 replies; 5+ messages in thread
From: Omar Sandoval @ 2021-06-10  1:02 UTC (permalink / raw)
  To: Érico Nogueira; +Cc: elfutils-devel

On Wed, Jun 09, 2021 at 09:59:06PM -0300, Érico Nogueira wrote:
> Hope you don't mind my nit, then :)

Thanks, that's what I get for sending patches out right before dinner...

> On Wed Jun 9, 2021 at 9:51 PM -03, Omar Sandoval wrote:
> > On Wed, Jun 09, 2021 at 05:45:57PM -0700, Omar Sandoval wrote:
> > > From: Omar Sandoval <osandov@fb.com>
> > > 
> > > When read_addrs() was converted was converted from a nested function to
>                                     ^^^^^^^^^^^^^ repeated words
> > > 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
> > ^^^^
> > Stray word here, hopefully not too much trouble to fix up when applying.
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libdwfl: fix crash when reading link map
  2021-06-10  0:45 [PATCH] libdwfl: fix crash when reading link map Omar Sandoval
  2021-06-10  0:51 ` Omar Sandoval
@ 2021-06-10 10:44 ` Dmitry V. Levin
  1 sibling, 0 replies; 5+ messages in thread
From: Dmitry V. Levin @ 2021-06-10 10:44 UTC (permalink / raw)
  To: elfutils-devel

On Wed, Jun 09, 2021 at 05:45:57PM -0700, Omar Sandoval wrote:
> 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>

Applied, thanks.


-- 
ldv

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-10 10:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-10  0:45 [PATCH] libdwfl: fix crash when reading link map Omar Sandoval
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

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