Skip to content

Commit

Permalink
Merge branch 'fix_coredump_build_error' into 'master'
Browse files Browse the repository at this point in the history
fix(coredump): fix array out of the bounds error

Closes IDFGH-13178

See merge request espressif/esp-idf!31874
  • Loading branch information
erhankur committed Jul 9, 2024
2 parents 16e586e + ee01c2c commit 9746eff
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions components/espcoredump/src/core_dump_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,16 @@ static int elf_write_note_header(core_dump_elf_t *self,
static char name_buffer[ELF_NOTE_NAME_MAX_SIZE] = { 0 };
elf_note note_hdr = { 0 };

memcpy((void*)name_buffer, (void*)name, name_len);
note_hdr.n_namesz = name_len;
memcpy(name_buffer, name, name_len);
note_hdr.n_namesz = ALIGN_UP(name_len, 4);
note_hdr.n_descsz = data_sz;
note_hdr.n_type = type;
// write note header
esp_err_t err = esp_core_dump_write_data(&self->write_data, &note_hdr, sizeof(note_hdr));
ELF_CHECK_ERR((err == ESP_OK), ELF_PROC_ERR_WRITE_FAIL,
"Write ELF note header failure (%d)", err);
// write note name
err = esp_core_dump_write_data(&self->write_data, name_buffer, name_len);
err = esp_core_dump_write_data(&self->write_data, name_buffer, note_hdr.n_namesz);
ELF_CHECK_ERR((err == ESP_OK), ELF_PROC_ERR_WRITE_FAIL,
"Write ELF note name failure (%d)", err);

Expand Down Expand Up @@ -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 = ALIGN_UP(sizeof(ELF_ESP_CORE_DUMP_PANIC_DETAILS_NOTE_NAME), 4);
uint32_t name_len = sizeof(ELF_ESP_CORE_DUMP_PANIC_DETAILS_NOTE_NAME);
core_dump_elf_opaque_t param = {
.self = self,
.total_size = 0,
Expand Down Expand Up @@ -722,7 +722,7 @@ static int elf_add_wdt_panic_details(core_dump_elf_t *self)
}
}

return ALIGN_UP(name_len + ALIGN_UP(self->note_data_size, 4) + sizeof(elf_note), 4);
return ALIGN_UP(ALIGN_UP(name_len, 4) + ALIGN_UP(self->note_data_size, 4) + sizeof(elf_note), 4);
}
#endif //CONFIG_ESP_TASK_WDT_EN

Expand Down

0 comments on commit 9746eff

Please sign in to comment.