Skip to content

Commit

Permalink
fix: Prevent crash when using sdcard and partition filesystems together
Browse files Browse the repository at this point in the history
Check that `partition` is defined before accessing
  • Loading branch information
nebkat authored and BrianPugh committed Jun 19, 2024
1 parent de8117f commit 002ae3e
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/esp_littlefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,12 +735,12 @@ static esp_err_t esp_littlefs_by_partition(const esp_partition_t* part, int * in

for (i = 0; i < CONFIG_LITTLEFS_MAX_PARTITIONS; i++) {
p = _efs[i];
if (p) {
if (part->address == p->partition->address) {
*index = i;
ESP_LOGV(ESP_LITTLEFS_TAG, "Found existing filesystem \"0x%08"PRIX32"\" at index %d", part->address, *index);
return ESP_OK;
}
if (!p) continue;
if (!p->partition) continue;
if (part->address == p->partition->address) {
*index = i;
ESP_LOGV(ESP_LITTLEFS_TAG, "Found existing filesystem \"0x%08"PRIX32"\" at index %d", part->address, *index);
return ESP_OK;
}
}

Expand All @@ -758,12 +758,12 @@ static esp_err_t esp_littlefs_by_label(const char* label, int * index){

for (i = 0; i < CONFIG_LITTLEFS_MAX_PARTITIONS; i++) {
p = _efs[i];
if (p) {
if (strncmp(label, p->partition->label, 17) == 0) {
*index = i;
ESP_LOGV(ESP_LITTLEFS_TAG, "Found existing filesystem \"%s\" at index %d", label, *index);
return ESP_OK;
}
if (!p) continue;
if (!p->partition) continue;
if (strncmp(label, p->partition->label, 17) == 0) {
*index = i;
ESP_LOGV(ESP_LITTLEFS_TAG, "Found existing filesystem \"%s\" at index %d", label, *index);
return ESP_OK;
}
}

Expand All @@ -781,12 +781,11 @@ static esp_err_t esp_littlefs_by_sdmmc_handle(sdmmc_card_t *handle, int *index)
for (int i = 0; i < CONFIG_LITTLEFS_MAX_PARTITIONS; i++) {
esp_littlefs_t *p = _efs[i];
if (!p) continue;
if (p->sdcard) {
if (p->sdcard == handle) {
*index = i;
ESP_LOGV(ESP_LITTLEFS_TAG, "Found existing filesystem %p at index %d", handle, *index);
return ESP_OK;
}
if (!p->sdcard) continue;
if (p->sdcard == handle) {
*index = i;
ESP_LOGV(ESP_LITTLEFS_TAG, "Found existing filesystem %p at index %d", handle, *index);
return ESP_OK;
}
}

Expand Down

0 comments on commit 002ae3e

Please sign in to comment.