From 5cdc6c77cfcecc162b74b1bcc902fde978384352 Mon Sep 17 00:00:00 2001 From: Windrow14 <90297720+Windrow14@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:33:06 +0800 Subject: [PATCH] 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 Reviewed-by: Jacky Cao Tested-by: Yinzhe Wu --- fs/fat/fs_fat32util.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/fat/fs_fat32util.c b/fs/fat/fs_fat32util.c index c03df449c07e8..923a808bea1f0 100644 --- a/fs/fat/fs_fat32util.c +++ b/fs/fat/fs_fat32util.c @@ -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 */