diff mbox series

log: Handle dladdr failure

Message ID 20240508143844.42060-1-steve.schrock@getcruise.com (mailing list archive)
State Accepted
Commit cef344ccf05e9ffbdae8830b44c2b5668bfcd38f
Headers show
Series log: Handle dladdr failure | expand

Commit Message

Steve Schrock May 8, 2024, 2:38 p.m. UTC
If unit/test-qmimodem-qmi times out while running under valgrind,
valgrind complains about an uninitialized value being printed during
abort signal logging. dladdr fails on the valgrind address
(0x580BCE37 in the example below) but print_backtrace still tries to
access the Dl_info structure which is not initialized. The fix is to
handle the dladdr failure gracefully.

==36318== Conditional jump or move depends on uninitialised value(s)
==36318==    at 0x4A862F8: __printf_buffer (vfprintf-process-arg.c:408)
==36318==    by 0x4AA8067: __vsnprintf_internal (vsnprintf.c:96)
==36318==    by 0x4B1D62B: __vsyslog_internal (syslog.c:220)
==36318==    by 0x4B1DB83: vsyslog (syslog.c:100)
==36318==    by 0x407C3F: ofono_error (log.c:92)
==36318==    by 0x407FEB: print_backtrace (log.c:201)
==36318==    by 0x40816B: signal_handler (log.c:228)
==36318==    by 0x580BCE37: ??? (in /usr/libexec/valgrind/memcheck-arm64-linux)
---
 src/log.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

patchwork-bot+ofono@kernel.org May 8, 2024, 3:50 p.m. UTC | #1
Hello:

This patch was applied to ofono.git (master)
by Denis Kenzior <denkenz@gmail.com>:

On Wed,  8 May 2024 14:38:44 +0000 you wrote:
> If unit/test-qmimodem-qmi times out while running under valgrind,
> valgrind complains about an uninitialized value being printed during
> abort signal logging. dladdr fails on the valgrind address
> (0x580BCE37 in the example below) but print_backtrace still tries to
> access the Dl_info structure which is not initialized. The fix is to
> handle the dladdr failure gracefully.
> 
> [...]

Here is the summary with links:
  - log: Handle dladdr failure
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=cef344ccf05e

You are awesome, thank you!
diff mbox series

Patch

diff --git a/src/log.c b/src/log.c
index a8b4ef10eaae..fdfad362cfd1 100644
--- a/src/log.c
+++ b/src/log.c
@@ -171,11 +171,13 @@  static void print_backtrace(unsigned int offset)
 
 	for (i = offset; i < n_ptrs - 1; i++) {
 		Dl_info info;
+		const char *fname = "???";
 		char addr[20], buf[PATH_MAX * 2];
 		int len, written;
 		char *ptr, *pos;
 
-		dladdr(frames[i], &info);
+		if (dladdr(frames[i], &info))
+			fname = info.dli_fname;
 
 		len = snprintf(addr, sizeof(addr), "%p\n", frames[i]);
 		if (len < 0)
@@ -199,7 +201,7 @@  static void print_backtrace(unsigned int offset)
 
 		if (strcmp(buf, "??") == 0) {
 			ofono_error("#%-2u %p in %s", i - offset,
-						frames[i], info.dli_fname);
+						frames[i], fname);
 			continue;
 		}