From: Ivan Grokhotkov Date: Mon, 8 Jan 2018 08:21:44 +0000 (+0800) Subject: fatfs: check allocated workbuf pointer X-Git-Tag: v3.1-beta1~407^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bf53c8abb1f3745923d8e531335e2f693cb0029e;p=esp-idf fatfs: check allocated workbuf pointer --- diff --git a/components/fatfs/src/vfs_fat_sdmmc.c b/components/fatfs/src/vfs_fat_sdmmc.c index f4128d68fe..f31790e0f6 100644 --- a/components/fatfs/src/vfs_fat_sdmmc.c +++ b/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; diff --git a/components/fatfs/src/vfs_fat_spiflash.c b/components/fatfs/src/vfs_fat_spiflash.c index 3f874eda76..b676ed3a59 100644 --- a/components/fatfs/src/vfs_fat_spiflash.c +++ b/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);