This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] libdwfl: Correct nested asprintf result check in report_kernel_archive.


Because of wrongly placed parens the result of only one asprintf call
was checked correctly. Causing dwfl_linux_kernel_report_offline to return
ENOMEM. Rewrite nested if unlikely check into separate if statements to
make clear what is actually being checked and what the actual unlikely
condition is.

Reported against systemtap "build-id difficulties with hand-built kernels"
https://sourceware.org/bugzilla/show_bug.cgi?id=16358

Reported-by: Crestez Dan Leonard <lcrestez@ixiacom.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libdwfl/ChangeLog              |    5 +++++
 libdwfl/linux-kernel-modules.c |   10 +++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index c3569aa..fa605bd 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
+2013-12-20  Mark Wielaard  <mjw@redhat.com>
+
+	* linux-kernel-modules.c (report_kernel_archive): Correct nested
+	asprintf result check for debug.a.
+
 2013-12-18  Mark Wielaard  <mjw@redhat.com>
 
 	* derelocate.c (__libdwfl_find_section_ndx): New internal function.
diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
index fe01028..a6d1084 100644
--- a/libdwfl/linux-kernel-modules.c
+++ b/libdwfl/linux-kernel-modules.c
@@ -251,9 +251,13 @@ report_kernel_archive (Dwfl *dwfl, const char **release,
     return result;
 
   char *archive;
-  if (unlikely ((*release)[0] == '/'
-		? asprintf (&archive, "%s/debug.a", *release)
-		: asprintf (&archive, MODULEDIRFMT "/debug.a", *release) < 0))
+  int res;
+  if ((*release)[0] == '/')
+    res = asprintf (&archive, "%s/debug.a", *release);
+  else
+    res = asprintf (&archive, MODULEDIRFMT "/debug.a", *release);
+
+  if (unlikely (res < 0))
     return ENOMEM;
 
   int fd = try_kernel_name (dwfl, &archive, false);
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]