From 8ac45bb391fe6d68ae5b6ebd84825e9f9b8df8fc Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 30 Mar 2026 15:51:14 -0700 Subject: [PATCH] utils: Safely handle NULL pointers returned by dladdr --- libs/utils/src/CallStack.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libs/utils/src/CallStack.cpp b/libs/utils/src/CallStack.cpp index 94c70ba259..798fd64285 100644 --- a/libs/utils/src/CallStack.cpp +++ b/libs/utils/src/CallStack.cpp @@ -149,14 +149,16 @@ io::ostream& operator<<(io::ostream& stream, CallStack const& UTILS_UNUSED calls void* pc = (void*)callstack[i]; #if HAS_DLADDR if (::dladdr(pc, &info)) { - char const* exe = strrchr(info.dli_fname, '/'); + char const* fname = info.dli_fname ? info.dli_fname : ""; + char const* sname = info.dli_sname ? info.dli_sname : ""; + char const* exe = strrchr(fname, '/'); snprintf(buf, sizeof(buf), "#%u\t%-31s %*p %s + %zd\n", unsigned(i), - exe ? exe + 1 : info.dli_fname, + exe ? exe + 1 : fname, int(2 + sizeof(void*)*2), pc, - CallStack::demangle(info.dli_sname).c_str(), - (char *)callstack[i] - (char *)info.dli_saddr); + CallStack::demangle(sname).c_str(), + (char *)callstack[i] - (char *)(info.dli_saddr ? info.dli_saddr : pc)); stream << buf; } else #endif