Skip to content

Commit

Permalink
fs/fat/fs_fat32util.c: fix potential exception due to dividing zero d…
Browse files Browse the repository at this point in the history
…uring 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 <[email protected]>
Reviewed-by: Jacky Cao <[email protected]>
Tested-by: Yinzhe Wu <[email protected]>
  • Loading branch information
Windrow14 authored and jerpelea committed Dec 13, 2024
1 parent 98ccba2 commit f84e3fd
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fs/fat/fs_fat32util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down

0 comments on commit f84e3fd

Please sign in to comment.