From 10115792ac061042aa173064dc8dbd78792fc967 Mon Sep 17 00:00:00 2001 From: Alexey Lapshin Date: Mon, 28 Oct 2024 16:28:25 +0700 Subject: [PATCH 1/4] fix(espcoredump): fix GCC-14 analyzer warnings for coredump --- components/esp_system/port/soc/esp32c61/system_internal.c | 5 ++--- components/espcoredump/src/core_dump_elf.c | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/components/esp_system/port/soc/esp32c61/system_internal.c b/components/esp_system/port/soc/esp32c61/system_internal.c index d5593fa9f2..94f6783b5f 100644 --- a/components/esp_system/port/soc/esp32c61/system_internal.c +++ b/components/esp_system/port/soc/esp32c61/system_internal.c @@ -8,6 +8,7 @@ #include "sdkconfig.h" #include "esp_system.h" #include "esp_private/system_internal.h" +#include "esp_macros.h" #include "esp_attr.h" #include "esp_log.h" #include "esp_rom_sys.h" @@ -114,7 +115,5 @@ void IRAM_ATTR esp_restart_noos(void) // Reset PRO CPU esp_rom_software_reset_cpu(0); - while (true) { - ; - } + ESP_INFINITE_LOOP(); } diff --git a/components/espcoredump/src/core_dump_elf.c b/components/espcoredump/src/core_dump_elf.c index 57ea48e115..cdd3420cc5 100644 --- a/components/espcoredump/src/core_dump_elf.c +++ b/components/espcoredump/src/core_dump_elf.c @@ -209,7 +209,7 @@ static int elf_write_note_header(core_dump_elf_t *self, elf_note note_hdr = { 0 }; memcpy(name_buffer, name, name_len); - note_hdr.n_namesz = ALIGN_UP(name_len, 4); + note_hdr.n_namesz = ALIGN_UP(name_len + 1, 4); note_hdr.n_descsz = data_sz; note_hdr.n_type = type; // write note header @@ -242,7 +242,7 @@ static int elf_write_note(core_dump_elf_t *self, // write segment data during second pass if (self->elf_stage == ELF_STAGE_PLACE_DATA) { ELF_CHECK_ERR(data, ELF_PROC_ERR_OTHER, "Invalid data pointer %x.", (uint32_t)data); - err = elf_write_note_header(self, name, name_len, data_sz, type); + err = elf_write_note_header(self, name, strlen(name), data_sz, type); if (err != ESP_OK) { return err; } @@ -688,7 +688,7 @@ static void elf_write_core_dump_note_cb(void *opaque, const char *data) static int elf_add_wdt_panic_details(core_dump_elf_t *self) { - uint32_t name_len = sizeof(ELF_ESP_CORE_DUMP_PANIC_DETAILS_NOTE_NAME); + uint32_t name_len = sizeof(ELF_ESP_CORE_DUMP_PANIC_DETAILS_NOTE_NAME) - 1; core_dump_elf_opaque_t param = { .self = self, .total_size = 0, From dc3c5956b1518a6d0ba0962597b64bff6d61f196 Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Fri, 29 Nov 2024 13:02:15 +0100 Subject: [PATCH 2/4] fix(espcoredump): fix incorrect pointer usage in checksum update call --- components/espcoredump/src/core_dump_flash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/espcoredump/src/core_dump_flash.c b/components/espcoredump/src/core_dump_flash.c index 2cd6bfb55b..ece2af211a 100644 --- a/components/espcoredump/src/core_dump_flash.c +++ b/components/espcoredump/src/core_dump_flash.c @@ -185,7 +185,7 @@ static esp_err_t esp_core_dump_flash_write_data(core_dump_write_data_t* wr_data, wr_data->off += COREDUMP_CACHE_SIZE; /* Update checksum with the newly written data on the flash. */ - esp_core_dump_checksum_update(&wr_data->checksum_ctx, &wr_data->cached_data, COREDUMP_CACHE_SIZE); + esp_core_dump_checksum_update(&wr_data->checksum_ctx, wr_data->cached_data, COREDUMP_CACHE_SIZE); /* Reset cache from the next use. */ wr_data->cached_bytes = 0; From 62d59751c0a901fb6e4b8688497d98e3ad716097 Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Fri, 29 Nov 2024 13:36:07 +0100 Subject: [PATCH 3/4] change(tools): enhance `expect_reg_dump` to support any or specific core values --- tools/test_apps/system/panic/pytest_panic.py | 4 ++-- .../system/panic/test_panic_util/panic_dut.py | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/test_apps/system/panic/pytest_panic.py b/tools/test_apps/system/panic/pytest_panic.py index c4b45cb31e..1b0c2f3c67 100644 --- a/tools/test_apps/system/panic/pytest_panic.py +++ b/tools/test_apps/system/panic/pytest_panic.py @@ -1077,11 +1077,11 @@ def test_tcb_corrupted(dut: PanicTestDut, target: str, config: str, test_func_na dut.run_test_func(test_func_name) if dut.is_xtensa: dut.expect_gme('LoadProhibited') - dut.expect_reg_dump(0) + dut.expect_reg_dump() dut.expect_backtrace() else: dut.expect_gme('Load access fault') - dut.expect_reg_dump(0) + dut.expect_reg_dump() dut.expect_stack_dump() dut.expect_elf_sha256() diff --git a/tools/test_apps/system/panic/test_panic_util/panic_dut.py b/tools/test_apps/system/panic/test_panic_util/panic_dut.py index ba104f4af8..ff8004cb85 100644 --- a/tools/test_apps/system/panic/test_panic_util/panic_dut.py +++ b/tools/test_apps/system/panic/test_panic_util/panic_dut.py @@ -96,9 +96,13 @@ class PanicTestDut(IdfDut): """Expect method for Guru Meditation Errors""" self.expect_exact(f"Guru Meditation Error: Core 0 panic'ed ({reason})") - def expect_reg_dump(self, core: int = 0) -> None: - """Expect method for the register dump""" - self.expect(r'Core\s+%d register dump:' % core) + def expect_reg_dump(self, core: Optional[int] = None) -> None: + if core is None: + # Match any core num + self.expect(r'Core\s+\d+\s+register dump:') + else: + # Match the exact core num provided + self.expect(r'Core\s+%d\s+register dump:' % core) def expect_cpu_reset(self) -> None: # no digital system reset for panic handling restarts (see IDF-7255) From 36ee603be9244dc396c4cdfec1aac0dade0e7b46 Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Sat, 30 Nov 2024 15:15:01 +0100 Subject: [PATCH 4/4] fix(espcoredump): prevent null pointer dereference in panic reason handling --- components/esp_system/panic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_system/panic.c b/components/esp_system/panic.c index 35f50785e4..ff9043ac31 100644 --- a/components/esp_system/panic.c +++ b/components/esp_system/panic.c @@ -301,7 +301,7 @@ void esp_panic_handler(panic_info_t *info) char *panic_reason_str = NULL; if (info->pseudo_excause) { panic_reason_str = (char *)info->reason; - } else if (g_panic_abort && strlen(g_panic_abort_details)) { + } else if (g_panic_abort) { panic_reason_str = g_panic_abort_details; } if (panic_reason_str) {