arch: riscv: check esf before calling z_riscv_unwind_stack

Make sure that esf is not NULL before calling
z_riscv_unwind_stack to prevent NULL pointer dereferencing.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
This commit is contained in:
Yong Cong Sin 2024-05-26 01:55:10 +08:00 committed by Chris Friedt
commit 5a35037af3
2 changed files with 1 additions and 9 deletions

View file

@ -107,7 +107,7 @@ FUNC_NORETURN void z_riscv_fatal_error_csf(unsigned int reason, const z_arch_esf
LOG_ERR("");
}
if (IS_ENABLED(CONFIG_RISCV_EXCEPTION_STACK_TRACE)) {
if (IS_ENABLED(CONFIG_RISCV_EXCEPTION_STACK_TRACE) && (esf != NULL)) {
z_riscv_unwind_stack(esf);
}

View file

@ -88,10 +88,6 @@ void z_riscv_unwind_stack(const z_arch_esf_t *esf)
uintptr_t ra;
struct stackframe *frame;
if (esf == NULL) {
return;
}
LOG_ERR("call trace:");
for (int i = 0; (i < MAX_STACK_FRAMES) && (fp != 0U) && in_stack_bound(fp);) {
@ -121,10 +117,6 @@ void z_riscv_unwind_stack(const z_arch_esf_t *esf)
uintptr_t ra;
uintptr_t *ksp = (uintptr_t *)sp;
if (esf == NULL) {
return;
}
LOG_ERR("call trace:");
for (int i = 0;