From d72b7654048dcbaaaa203c04681a2d0a873fd02d Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Tue, 7 May 2024 00:55:17 +0200 Subject: [PATCH] fix(coredump): fix buffer overflow inside esp_core_dump_get_summary Closes https://github.com/espressif/esp-idf/issues/13754 --- components/espcoredump/src/core_dump_elf.c | 2 +- tools/test_apps/system/panic/main/test_panic.c | 5 +++++ tools/test_apps/system/panic/pytest_panic.py | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/components/espcoredump/src/core_dump_elf.c b/components/espcoredump/src/core_dump_elf.c index 2e3da6ee02..db05493ca1 100644 --- a/components/espcoredump/src/core_dump_elf.c +++ b/components/espcoredump/src/core_dump_elf.c @@ -933,7 +933,7 @@ static void elf_parse_version_info(esp_core_dump_summary_t *summary, void *data) { core_dump_elf_version_info_t *version = (core_dump_elf_version_info_t *)data; summary->core_dump_version = version->version; - memcpy(summary->app_elf_sha256, version->app_elf_sha256, ELF_APP_SHA256_SIZE); + memcpy(summary->app_elf_sha256, version->app_elf_sha256, sizeof(summary->app_elf_sha256)); ESP_COREDUMP_LOGD("Core dump version 0x%x", summary->core_dump_version); ESP_COREDUMP_LOGD("App ELF SHA2 %s", (char *)summary->app_elf_sha256); } diff --git a/tools/test_apps/system/panic/main/test_panic.c b/tools/test_apps/system/panic/main/test_panic.c index c2eeb8eb47..5603279d48 100644 --- a/tools/test_apps/system/panic/main/test_panic.c +++ b/tools/test_apps/system/panic/main/test_panic.c @@ -285,6 +285,11 @@ void test_coredump_summary(void) if (err == ESP_OK) { printf("App ELF file SHA256: %s\n", (char *)summary->app_elf_sha256); printf("Crashed task: %s\n", summary->exc_task); +#if __XTENSA__ + printf("Exception cause: %ld\n", summary->ex_info.exc_cause); +#else + printf("Exception cause: %ld\n", summary->ex_info.mcause); +#endif char panic_reason[200]; err = esp_core_dump_get_panic_reason(panic_reason, sizeof(panic_reason)); if (err == ESP_OK) { diff --git a/tools/test_apps/system/panic/pytest_panic.py b/tools/test_apps/system/panic/pytest_panic.py index 2242ec1bdb..c882ba8f9b 100644 --- a/tools/test_apps/system/panic/pytest_panic.py +++ b/tools/test_apps/system/panic/pytest_panic.py @@ -1024,6 +1024,10 @@ def _test_coredump_summary(dut: PanicTestDut, flash_encrypted: bool, coredump_en return dut.expect_elf_sha256('App ELF file SHA256: ') dut.expect_exact('Crashed task: main') + if dut.is_xtensa: + dut.expect_exact('Exception cause: 29') + else: + dut.expect_exact('Exception cause: 7') dut.expect(PANIC_ABORT_PREFIX + r'assert failed:[\s\w()]*?\s[.\w/]*\.(?:c|cpp|h|hpp):\d.*$')