From e02a5a70eb652064180ed13eba9e58840ef493e3 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Thu, 13 Oct 2022 16:47:28 +0800 Subject: [PATCH] fs/partiton: add sanity check mmcsd_spi don't support ioctl when blocksize is zero, will cause crash. Signed-off-by: dongjiuzhu1 --- fs/partition/fs_partition.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/partition/fs_partition.c b/fs/partition/fs_partition.c index 1c52897c9e9..cb2a3d44476 100644 --- a/fs/partition/fs_partition.c +++ b/fs/partition/fs_partition.c @@ -155,10 +155,12 @@ int parse_block_partition(FAR const char *path, state.mtd = NULL; - ret = state.blk->u.i_bops->ioctl( - state.blk, MTDIOC_GEOMETRY, (unsigned long)(uintptr_t)&mgeo); - if (ret >= 0) + if (state.blk->u.i_bops->ioctl != NULL && + state.blk->u.i_bops->ioctl(state.blk, MTDIOC_GEOMETRY, + (unsigned long)(uintptr_t)&mgeo) >= 0) { + DEBUGASSERT(mgeo.blocksize); + state.blocksize = mgeo.blocksize; state.erasesize = mgeo.erasesize; state.nblocks = mgeo.neraseblocks; @@ -171,6 +173,8 @@ int parse_block_partition(FAR const char *path, ret = state.blk->u.i_bops->geometry(state.blk, &geo); if (ret >= 0) { + DEBUGASSERT(geo.geo_sectorsize); + state.blocksize = geo.geo_sectorsize; state.erasesize = geo.geo_sectorsize; state.nblocks = geo.geo_nsectors; @@ -213,6 +217,8 @@ int parse_mtd_partition(FAR struct mtd_dev_s *mtd, return ret; } + DEBUGASSERT(mgeo.blocksize); + state.blk = NULL; state.mtd = mtd; state.blocksize = mgeo.blocksize;