Skip to content

Commit bd9ec8b

Browse files
committed
mbed_error.c: fixed the dump core function's bug of possible stack overflow.
1 parent a769b7d commit bd9ec8b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

platform/source/mbed_error.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static void print_stack_dump_core(uint32_t stack_start, uint32_t stack_size, uin
505505
mbed_error_printf("\nStack Dump: %s", postfix);
506506
uint32_t st_end = (stack_start + stack_size) & INT_ALIGN_MASK;
507507
uint32_t st = (stack_sp) & INT_ALIGN_MASK;
508-
for (; st <= st_end; st += sizeof(int) * STACK_DUMP_WIDTH) {
508+
for (; st < st_end; st += sizeof(int) * STACK_DUMP_WIDTH) {
509509
mbed_error_printf("\n0x%08" PRIX32 ":", st);
510510
for (int i = 0; i < STACK_DUMP_WIDTH; i++) {
511511
uint32_t st_cur = st + i * sizeof(int);
@@ -534,8 +534,7 @@ static void print_stack_dump(uint32_t stack_start, uint32_t stack_size, uint32_t
534534
// PSP mode. Then SP_reg is more correct.
535535
psp_sp = mfc->SP_reg;
536536
}
537-
// Do not access beyond INITIAL_SP.
538-
uint32_t msp_size = MAX(0, (int)INITIAL_SP - (int)msp_sp - (int)sizeof(int));
537+
uint32_t msp_size = MAX(0, (int)INITIAL_SP - (int)msp_sp);
539538
print_stack_dump_core(msp_sp, msp_size, msp_sp, "MSP");
540539

541540
stack_sp = psp_sp;

0 commit comments

Comments
 (0)