Просмотр исходного кода

fatfs: check allocated workbuf pointer

Ivan Grokhotkov 8 лет назад
Родитель
Сommit
bf53c8abb1
2 измененных файлов с 9 добавлено и 1 удалено
  1. 5 1
      components/fatfs/src/vfs_fat_sdmmc.c
  2. 4 0
      components/fatfs/src/vfs_fat_spiflash.c

+ 5 - 1
components/fatfs/src/vfs_fat_sdmmc.c

@@ -113,8 +113,12 @@ esp_err_t esp_vfs_fat_sdmmc_mount(const char* base_path,
             goto fail;
         }
         ESP_LOGW(TAG, "partitioning card");
-        DWORD plist[] = {100, 0, 0, 0};
         workbuf = malloc(workbuf_size);
+        if (workbuf == NULL) {
+            err = ESP_ERR_NO_MEM;
+            goto fail;
+        }
+        DWORD plist[] = {100, 0, 0, 0};
         res = f_fdisk(s_pdrv, plist, workbuf);
         if (res != FR_OK) {
             err = ESP_FAIL;

+ 4 - 0
components/fatfs/src/vfs_fat_spiflash.c

@@ -79,6 +79,10 @@ esp_err_t esp_vfs_fat_spiflash_mount(const char* base_path,
             goto fail;
         }
         workbuf = malloc(workbuf_size);
+        if (workbuf == NULL) {
+            result = ESP_ERR_NO_MEM;
+            goto fail;
+        }
         size_t alloc_unit_size = esp_vfs_fat_get_allocation_unit_size(
                 CONFIG_WL_SECTOR_SIZE,
                 mount_config->allocation_unit_size);