From d49ad1e39bbad7ce850c27b53167ff6925434d1c Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Wed, 2 Feb 2022 17:56:48 -0800 Subject: [PATCH] Fix possible nullptr dereference. Test: Unit tests pass. Change-Id: I046c6e1665de4d941362e2f65605609e77731c97 --- libc/malloc_debug/UnwindBacktrace.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libc/malloc_debug/UnwindBacktrace.cpp b/libc/malloc_debug/UnwindBacktrace.cpp index dbaebb3cf..a7036d935 100644 --- a/libc/malloc_debug/UnwindBacktrace.cpp +++ b/libc/malloc_debug/UnwindBacktrace.cpp @@ -90,11 +90,13 @@ void UnwindLog(const std::vector& frame_info) { std::shared_ptr map_info = info->map_info; std::string line = android::base::StringPrintf(" #%0zd pc %" PAD_PTR " ", i, info->rel_pc); - if (map_info->offset() != 0) { + if (map_info != nullptr && map_info->offset() != 0) { line += android::base::StringPrintf("(offset 0x%" PRIx64 ") ", map_info->offset()); } - if (map_info->name().empty()) { + if (map_info == nullptr) { + line += ""; + } else if (map_info->name().empty()) { line += android::base::StringPrintf("", map_info->start()); } else { line += map_info->name();