aws-c-common icon indicating copy to clipboard operation
aws-c-common copied to clipboard

memtrace: Fix underflow when stack_depth < FRAMES_TO_SKIP

Open zhaofengli opened this issue 2 years ago • 4 comments

Issue #, if available: N/A

Description of changes:

An underflow occurs on line 160 when stack_depth is smaller than FRAMES_TO_SKIP (i.e., stack_depth = 1). This occurs on riscv64 where the library fails to obtain a valid trace, which is a separate issue.

                memcpy(
                    (void **)&stack->frames[0],
                    &stack_frames[FRAMES_TO_SKIP],
                    (stack_depth - FRAMES_TO_SKIP) * sizeof(void *)); // <-- underflow

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

zhaofengli avatar Dec 06 '21 04:12 zhaofengli

I applied your patch and I still got a slightly different test failure when building on and targeting riscv64-linux-gnu. Is this related or another issue?

270/388 Test #257: test_memtrace_stacks .................................................Subprocess aborted***Exception:   0.62 sec
Fatal error condition occurred in /home/oxa/tmp/aws-c-common-build/source/source/memtrace.c:207: stack_item
Exiting Application
################################################################################
Stack trace:
################################################################################

oxalica avatar Dec 29 '21 21:12 oxalica

Yes, that test needs to be skipped at the moment since memtrace cannot obtain a valid trace on riscv64. See https://github.com/zhaofengli/nixpkgs/commit/9e7cbec888e2817f64df9913362f941e59c7e0be

zhaofengli avatar Dec 29 '21 22:12 zhaofengli

Yes, that test needs to be skipped at the moment since memtrace cannot obtain a valid trace on riscv64. See zhaofengli/nixpkgs@9e7cbec

That's unfortunate. Could you elaborate the issue of backtrace? Is that something related to DWARF info?

oxalica avatar Dec 29 '21 22:12 oxalica

Yes, that test needs to be skipped at the moment since memtrace cannot obtain a valid trace on riscv64. See zhaofengli/nixpkgs@9e7cbec

That's unfortunate. Could you elaborate the issue of backtrace? Is that something related to DWARF info?

Sorry, I haven't had a chance to peel off the abstractions and look at that part yet.

zhaofengli avatar Dec 31 '21 18:12 zhaofengli