]> granicus.if.org Git - esp-idf/commitdiff
fatfs: check allocated workbuf pointer
authorIvan Grokhotkov <ivan@espressif.com>
Mon, 8 Jan 2018 08:21:44 +0000 (16:21 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Sun, 11 Feb 2018 05:03:36 +0000 (13:03 +0800)
components/fatfs/src/vfs_fat_sdmmc.c
components/fatfs/src/vfs_fat_spiflash.c

index f4128d68fe5f066d6de42d9d5ab3b0d9a6056df8..f31790e0f6863932261470096c2a98b0565dcfb0 100644 (file)
@@ -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;
index 3f874eda769c5cd9081f5ff7d38e445e155a8969..b676ed3a59072096291b423773ab4b846ae8484b 100644 (file)
@@ -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);