aboutsummaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@blueri.se>2018-11-26 15:56:57 +0100
committerTom Rini <trini@konsulko.com>2018-12-06 23:26:31 -0500
commitcd80a4fe611d7cb4153a6ed39d1e5052c702fb12 (patch)
treebb1f596d2c8e74a0744c6999159ab293cf07a50a /fs
parent16462a35728039aa173a02982643c551dc94ba20 (diff)
downloadu-boot-cd80a4fe611d7cb4153a6ed39d1e5052c702fb12.zip
u-boot-cd80a4fe611d7cb4153a6ed39d1e5052c702fb12.tar.gz
u-boot-cd80a4fe611d7cb4153a6ed39d1e5052c702fb12.tar.bz2
fs: check FAT cluster size
The cluster size specifies how many sectors make up a cluster. A cluster size of zero makes no sense, as it would mean that the cluster is made up of no sectors. This will later lead into a division by zero in sect_to_clust(), so better take care of that early. The MAX_CLUSTSIZE define can reduced using a define to make some room in low-memory system. Unfortunately if the code reads a filesystem with a bigger cluster size it will overflow the buffer. Signed-off-by: Patrick Wildt <patrick@blueri.se>
Diffstat (limited to 'fs')
-rw-r--r--fs/fat/fat.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 4bc3030..e0c0767 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -571,6 +571,17 @@ static int get_fs_info(fsdata *mydata)
mydata->sect_size, cur_part_info.blksz);
return -1;
}
+ if (mydata->clust_size == 0) {
+ printf("Error: FAT cluster size not set\n");
+ return -1;
+ }
+ if ((unsigned int)mydata->clust_size * mydata->sect_size >
+ MAX_CLUSTSIZE) {
+ printf("Error: FAT cluster size too big (cs=%u, max=%u)\n",
+ (unsigned int)mydata->clust_size * mydata->sect_size,
+ MAX_CLUSTSIZE);
+ return -1;
+ }
if (mydata->fatsize == 32) {
mydata->data_begin = mydata->rootdir_sect -