Skip to content

Commit bd8d7ea

Browse files
committed
fix(coredump): increase sanity check before get summary
Closes espressif#13594
1 parent ea010f8 commit bd8d7ea

File tree

2 files changed

+13
-29
lines changed

2 files changed

+13
-29
lines changed

components/espcoredump/src/core_dump_elf.c

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -762,39 +762,23 @@ typedef struct {
762762
void *n_ptr;
763763
} elf_note_content_t;
764764

765+
esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size);
766+
765767
/* Below are the helper function to parse the core dump ELF stored in flash */
766768
static esp_err_t elf_core_dump_image_mmap(esp_partition_mmap_handle_t* core_data_handle, const void **map_addr)
767769
{
768-
size_t out_size;
770+
const esp_partition_t *core_part = NULL;
771+
uint32_t out_size;
769772
assert(core_data_handle);
770773
assert(map_addr);
771774

772-
/* Find the partition that could potentially contain a (previous) core dump. */
773-
const esp_partition_t *core_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
774-
ESP_PARTITION_SUBTYPE_DATA_COREDUMP,
775-
NULL);
776-
if (!core_part) {
777-
ESP_COREDUMP_LOGE("Core dump partition not found!");
778-
return ESP_ERR_NOT_FOUND;
779-
}
780-
if (core_part->size < sizeof(uint32_t)) {
781-
ESP_COREDUMP_LOGE("Core dump partition too small!");
782-
return ESP_ERR_INVALID_SIZE;
783-
}
784-
/* Data read from the mmapped core dump partition will be garbage if flash
785-
* encryption is enabled in hardware and core dump partition is not encrypted
786-
*/
787-
if (esp_flash_encryption_enabled() && !core_part->encrypted) {
788-
ESP_COREDUMP_LOGE("Flash encryption enabled in hardware and core dump partition is not encrypted!");
789-
return ESP_ERR_NOT_SUPPORTED;
790-
}
791-
/* Read the size of the core dump file from the partition */
792-
esp_err_t ret = esp_partition_read(core_part, 0, &out_size, sizeof(uint32_t));
793-
if (ret != ESP_OK) {
794-
ESP_COREDUMP_LOGE("Failed to read core dump data size");
795-
return ret;
775+
/* Retrieve the partition and size. */
776+
esp_err_t err = esp_core_dump_partition_and_size_get(&core_part, &out_size);
777+
if (err != ESP_OK) {
778+
return err;
796779
}
797-
/* map the full core dump parition, including the checksum. */
780+
781+
/* map the full core dump partition, including the checksum. */
798782
return esp_partition_mmap(core_part, 0, out_size, ESP_PARTITION_MMAP_DATA,
799783
map_addr, core_data_handle);
800784
}

components/espcoredump/src/core_dump_flash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ esp_err_t esp_core_dump_write_data(core_dump_write_data_t *wr_data, void *data,
5555
#define ESP_COREDUMP_FLASH_ERASE(_off_, _len_) esp_flash_erase_region(esp_flash_default_chip, _off_, _len_)
5656

5757
esp_err_t esp_core_dump_image_check(void);
58-
static esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size);
58+
esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size);
5959

6060
static void esp_core_dump_flash_print_write_start(void)
6161
{
@@ -258,7 +258,7 @@ static esp_err_t esp_core_dump_flash_write_prepare(core_dump_write_data_t *wr_da
258258
padding = COREDUMP_CACHE_SIZE - modulo;
259259
}
260260

261-
/* Now we can check whether we have enough space in our core dump parition
261+
/* Now we can check whether we have enough space in our core dump partition
262262
* or not. */
263263
if ((*data_len + padding + cs_len) > s_core_flash_config.partition.size) {
264264
ESP_COREDUMP_LOGE("Not enough space to save core dump!");
@@ -488,7 +488,7 @@ esp_err_t esp_core_dump_image_erase(void)
488488
return err;
489489
}
490490

491-
static esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size)
491+
esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size)
492492
{
493493
uint32_t core_size = 0;
494494
const esp_partition_t *core_part = NULL;

0 commit comments

Comments
 (0)