fix(coredump): increase sanity check before get summary

Closes https://github.com/espressif/esp-idf/issues/13594
This commit is contained in:
Erhan Kurubas 2024-04-24 06:04:55 +03:00
parent 5bac46d996
commit e6effa2be3
2 changed files with 12 additions and 28 deletions

View File

@ -900,38 +900,22 @@ typedef struct {
void *n_ptr;
} elf_note_content_t;
esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size);
/* Below are the helper function to parse the core dump ELF stored in flash */
static esp_err_t elf_core_dump_image_mmap(esp_partition_mmap_handle_t* core_data_handle, const void **map_addr)
{
size_t out_size;
const esp_partition_t *core_part = NULL;
uint32_t out_size;
assert(core_data_handle);
assert(map_addr);
/* Find the partition that could potentially contain a (previous) core dump. */
const esp_partition_t *core_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
ESP_PARTITION_SUBTYPE_DATA_COREDUMP,
NULL);
if (!core_part) {
ESP_COREDUMP_LOGE("Core dump partition not found!");
return ESP_ERR_NOT_FOUND;
}
if (core_part->size < sizeof(uint32_t)) {
ESP_COREDUMP_LOGE("Core dump partition too small!");
return ESP_ERR_INVALID_SIZE;
}
/* Data read from the mmapped core dump partition will be garbage if flash
* encryption is enabled in hardware and core dump partition is not encrypted
*/
if (esp_flash_encryption_enabled() && !core_part->encrypted) {
ESP_COREDUMP_LOGE("Flash encryption enabled in hardware and core dump partition is not encrypted!");
return ESP_ERR_NOT_SUPPORTED;
}
/* Read the size of the core dump file from the partition */
esp_err_t ret = esp_partition_read(core_part, 0, &out_size, sizeof(uint32_t));
if (ret != ESP_OK) {
ESP_COREDUMP_LOGE("Failed to read core dump data size");
return ret;
/* Retrieve the partition and size. */
esp_err_t err = esp_core_dump_partition_and_size_get(&core_part, &out_size);
if (err != ESP_OK) {
return err;
}
/* map the full core dump partition, including the checksum. */
return esp_partition_mmap(core_part, 0, out_size, ESP_PARTITION_MMAP_DATA,
map_addr, core_data_handle);

View File

@ -55,7 +55,7 @@ esp_err_t esp_core_dump_write_data(core_dump_write_data_t *wr_data, void *data,
#define ESP_COREDUMP_FLASH_ERASE(_off_, _len_) esp_flash_erase_region(esp_flash_default_chip, _off_, _len_)
esp_err_t esp_core_dump_image_check(void);
static esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size);
esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size);
static void esp_core_dump_flash_print_write_start(void)
{
@ -258,7 +258,7 @@ static esp_err_t esp_core_dump_flash_write_prepare(core_dump_write_data_t *wr_da
padding = COREDUMP_CACHE_SIZE - modulo;
}
/* Now we can check whether we have enough space in our core dump parition
/* Now we can check whether we have enough space in our core dump partition
* or not. */
if ((*data_len + padding + cs_len) > s_core_flash_config.partition.size) {
ESP_COREDUMP_LOGE("Not enough space to save core dump!");
@ -488,7 +488,7 @@ esp_err_t esp_core_dump_image_erase(void)
return err;
}
static esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size)
esp_err_t esp_core_dump_partition_and_size_get(const esp_partition_t **partition, uint32_t* size)
{
uint32_t core_size = 0;
const esp_partition_t *core_part = NULL;