From dad9e8ceb943c108cf0687d6de273dfec3970df6 Mon Sep 17 00:00:00 2001 From: Yikai Zhao Date: Wed, 11 Oct 2023 19:43:28 +0800 Subject: [PATCH] Fix result overflow in generic_fp stacktrace In the 'with ucontext' case, the `skip_count` would be reset to 0, and `max_depth` should not be modified. Otherwise the result array would overflow. --- src/stacktrace_generic_fp-inl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stacktrace_generic_fp-inl.h b/src/stacktrace_generic_fp-inl.h index 1412a68..91fedef 100644 --- a/src/stacktrace_generic_fp-inl.h +++ b/src/stacktrace_generic_fp-inl.h @@ -123,8 +123,6 @@ int capture(void **result, int max_depth, int skip_count, int *sizes) { int i = 0; - max_depth += skip_count; - if (initial_pc != nullptr) { // This is 'with ucontext' case. We take first pc from ucontext // and then skip_count is ignored as we assume that caller only @@ -137,6 +135,8 @@ int capture(void **result, int max_depth, int skip_count, i++; } + max_depth += skip_count; + constexpr uintptr_t kTooSmallAddr = 16 << 10; constexpr uintptr_t kFrameSizeThreshold = 128 << 10;