public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libdwfl: Fix some GCC10 -Wnull-dereference issues.
@ 2020-01-24 22:28 Mark Wielaard
  2020-02-06 20:31 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2020-01-24 22:28 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

GCC10 on some arches will warn about possible NULL derefences.
In the libdwfl linux-kernel-modules.c cases it might be caught already
by earlier calls to get_release (). But it is hard to see that will
really always happen. So do an explicit NULL check just in case.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libdwfl/ChangeLog              |  6 ++++++
 libdwfl/linux-kernel-modules.c | 13 ++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index b36a7ca6..0b95490a 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,9 @@
+2020-01-24  Mark Wielaard  <mark@klomp.org>
+
+	* linux-kernel-modules.c (find_kernel_elf): Check release isn't NULL.
+	(report_kernel): Check release and *release aren't NULL.
+	(report_kernel_archive): Likewise.
+
 2019-12-11  Omar Sandoval  <osandov@fb.com>
 
 	* libdwflP.h (Dwfl_Module): Remove coalescing state.
diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
index 48fb1ff0..0434f1e5 100644
--- a/libdwfl/linux-kernel-modules.c
+++ b/libdwfl/linux-kernel-modules.c
@@ -176,9 +176,10 @@ find_kernel_elf (Dwfl *dwfl, const char *release, char **fname)
 {
   /* First try to find an uncompressed vmlinux image.  Possibly
      including debuginfo.  */
-  if ((release[0] == '/'
-       ? asprintf (fname, "%s/vmlinux", release)
-       : asprintf (fname, "/boot/vmlinux-%s", release)) < 0)
+  if (release == NULL
+      || ((release[0] == '/'
+	   ? asprintf (fname, "%s/vmlinux", release)
+	   : asprintf (fname, "/boot/vmlinux-%s", release)) < 0))
     return -1;
 
   int fd = try_kernel_name (dwfl, fname, true);
@@ -241,6 +242,9 @@ report_kernel (Dwfl *dwfl, const char **release,
   if (unlikely (result != 0))
     return result;
 
+  if (release == NULL || *release == NULL)
+    return EINVAL;
+
   char *fname;
   int fd = find_kernel_elf (dwfl, *release, &fname);
 
@@ -296,6 +300,9 @@ report_kernel_archive (Dwfl *dwfl, const char **release,
   if (unlikely (result != 0))
     return result;
 
+  if (release == NULL || *release == NULL)
+    return EINVAL;
+
   char *archive;
   int res = (((*release)[0] == '/')
 	     ? asprintf (&archive, "%s/debug.a", *release)
-- 
2.18.1

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

* Re: [PATCH] libdwfl: Fix some GCC10 -Wnull-dereference issues.
  2020-01-24 22:28 [PATCH] libdwfl: Fix some GCC10 -Wnull-dereference issues Mark Wielaard
@ 2020-02-06 20:31 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2020-02-06 20:31 UTC (permalink / raw)
  To: elfutils-devel

On Fri, 2020-01-24 at 23:28 +0100, Mark Wielaard wrote:
> GCC10 on some arches will warn about possible NULL derefences.
> In the libdwfl linux-kernel-modules.c cases it might be caught already
> by earlier calls to get_release (). But it is hard to see that will
> really always happen. So do an explicit NULL check just in case.

I pushed this to master.

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

end of thread, other threads:[~2020-02-06 20:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-24 22:28 [PATCH] libdwfl: Fix some GCC10 -Wnull-dereference issues Mark Wielaard
2020-02-06 20:31 ` Mark Wielaard

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