fix(callstack): guard against NULL from strchr when parsing symbols#19
Open
Rakdos8 wants to merge 1 commit into
Open
fix(callstack): guard against NULL from strchr when parsing symbols#19Rakdos8 wants to merge 1 commit into
Rakdos8 wants to merge 1 commit into
Conversation
backtrace_symbols lines without a '+' (stripped/static frames) make strchr return NULL; the code then dereferenced it via if(*plus), crashing while dumping callstacks on the POSIX/macOS path. Check the pointer before dereferencing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In the POSIX/macOS
backtrace_symbolspath,CCPCallstack::Enumerateparses each symbol line withconst char* plus = strchr( lines[i], '+' ); if( *plus ). When a line has no+(stripped binaries, static or symbol-less frames),strchrreturnsNULLand*plusdereferences it, crashing while dumping a callstack. This path is used by macOS(it is neither
_MSC_VERnor__ANDROID__), so it is a real crash risk on a primary target — triggered whencapturing and dumping callstacks (e.g. memory-tracker reports with callstack capture enabled).
Fix
Check the pointer before dereferencing:
if( plus && *plus ). One-line defensive change; lines without+are simplytreated as having no demangle-able suffix, same as the existing fallback.
Tests
No dedicated test: the parser consumes
backtrace_symbolsoutput directly and is not injectable from a unit test, sothe no-
+branch cannot be exercised deterministically without extracting the parser into a testable function (out ofscope for a one-line fix). The existing
CanDumpSymbolsIntoFileandDepthIsEqualToItemCounttests cover thenominal path and guard against regressions there. Reviewed manually; not compiled locally as the vcpkg toolchain is
unavailable in this environment.
Scope
POSIX/macOS path only. The Windows (
_MSC_VER) and Android paths are unchanged. No public API change.