]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fs: fat: avoid multiplication overflow
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 30 Jul 2023 14:44:04 +0000 (16:44 +0200)
committerTom Rini <trini@konsulko.com>
Mon, 14 Aug 2023 21:55:53 +0000 (17:55 -0400)
The product of two 32 bit integers is a 32 bit integer. Hence
clustcount * bytesperclust may overflow on > 4 GiB devices.

Change the type of clustcount.

Fixes: cb8af8af5ba0 ("fs: fat: support write with non-zero offset")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
fs/fat/fat_write.c

index a6294419b8d66ad914668da57a39b353c85fde9f..8b5d669b00503d0306cf62eba45f23544e4f4d85 100644 (file)
@@ -690,8 +690,8 @@ get_set_cluster(fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer,
        static u8 *tmpbuf_cluster;
        unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;
        __u32 startsect;
-       loff_t wsize;
-       int clustcount, i, ret;
+       loff_t clustcount, wsize;
+       int i, ret;
 
        *gotsize = 0;
        if (!size)