From: Mark Wielaard Date: Fri, 20 Dec 2013 23:04:21 +0000 (+0100) Subject: libdwfl: Correct nested asprintf result check in report_kernel_archive. X-Git-Tag: elfutils-0.158~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=641a4f62f1f1940540f1202c1e1aa5ce8c508234;p=thirdparty%2Felfutils.git 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 Signed-off-by: Mark Wielaard --- diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index c3569aa4b..fa605bd85 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2013-12-20 Mark Wielaard + + * linux-kernel-modules.c (report_kernel_archive): Correct nested + asprintf result check for debug.a. + 2013-12-18 Mark Wielaard * derelocate.c (__libdwfl_find_section_ndx): New internal function. diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index fe0102829..530751836 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -1,5 +1,5 @@ /* Standard libdwfl callbacks for debugging the running Linux kernel. - Copyright (C) 2005-2011 Red Hat, Inc. + Copyright (C) 2005-2011, 2013 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -251,9 +251,10 @@ 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 = (((*release)[0] == '/') + ? asprintf (&archive, "%s/debug.a", *release) + : asprintf (&archive, MODULEDIRFMT "/debug.a", *release)); + if (unlikely (res < 0)) return ENOMEM; int fd = try_kernel_name (dwfl, &archive, false);