fs/fat/fs_fat32util.c: fix potential exception due to dividing zero during mounting when fat is corrupted

Check fs_fatsecperclus' value when read from eMMC device. Return an error if it is zero.

Signed-off-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
Reviewed-by: Jacky Cao <Jacky.Cao@sony.com>
Tested-by: Yinzhe Wu <Yinzhe.Wu@sony.com>
This commit is contained in:
Windrow14 2024-12-13 09:33:06 +08:00 committed by Xiang Xiao
parent 15250540eb
commit 5cdc6c77cf

View file

@ -213,6 +213,11 @@ static int fat_checkbootrecord(struct fat_mountpt_s *fs)
/* Get the sectors per cluster */
fs->fs_fatsecperclus = FBR_GETSECPERCLUS(fs->fs_buffer);
if (fs->fs_fatsecperclus == 0)
{
fwarn("WARNING: sectors per cluster cannot be 0\n");
return -EINVAL;
}
/* Calculate the number of clusters */