From bf45c56825e017fc354c4d69927ea8a9863301e7 Mon Sep 17 00:00:00 2001 From: Alexey Lapshin Date: Mon, 28 Oct 2024 16:28:25 +0700 Subject: [PATCH 1/3] fix(espcoredump): fix GCC-14 analyzer warnings for coredump --- components/espcoredump/src/core_dump_elf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/espcoredump/src/core_dump_elf.c b/components/espcoredump/src/core_dump_elf.c index db05493ca15..e380cd8423a 100644 --- a/components/espcoredump/src/core_dump_elf.c +++ b/components/espcoredump/src/core_dump_elf.c @@ -208,7 +208,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 @@ -241,7 +241,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; } @@ -671,7 +671,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 512b16a7bdcdd3cc79f5cce98e7c1cd2f7a72524 Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Fri, 29 Nov 2024 13:02:15 +0100 Subject: [PATCH 2/3] 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 2cd6bfb55bb..ece2af211ad 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 8bfabe711a3833122ad08bd4d931d8c486c78ad1 Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Sat, 30 Nov 2024 15:15:01 +0100 Subject: [PATCH 3/3] fix(espcoredump): prevent null pointer dereference in panic reason handling --- components/esp_system/panic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/esp_system/panic.c b/components/esp_system/panic.c index fd28c7695cb..7bb4e3328cc 100644 --- a/components/esp_system/panic.c +++ b/components/esp_system/panic.c @@ -221,7 +221,7 @@ static inline void disable_all_wdts(void) wdt_hal_write_protect_enable(&wdt0_context); #if SOC_TIMER_GROUPS >= 2 - //Interupt WDT is the Main Watchdog Timer of Timer Group 1 + //Interrupt WDT is the Main Watchdog Timer of Timer Group 1 wdt_hal_write_protect_disable(&wdt1_context); wdt_hal_disable(&wdt1_context); wdt_hal_write_protect_enable(&wdt1_context); @@ -299,7 +299,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) {