]> www.infradead.org Git - mtd-utils.git/commitdiff
ubi-utils: ubirsvol: Fix integer overflow in ubirsvol.c
authorAnton Moryakov <ant.v.moryakov@gmail.com>
Tue, 10 Dec 2024 00:07:26 +0000 (03:07 +0300)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Tue, 17 Dec 2024 13:34:18 +0000 (14:34 +0100)
Report of the static analyzer:
The value of an arithmetic expression 'vol_info.leb_size * args.lebs' is a subject to overflow because its operands are not cast to a larger data type before performing arithmetic

Corrections explained:
The fix ensures values ​​are checked before multiplication.
Added casting vol_info.leb_size to long long

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubi-utils/ubirsvol.c

index 0854abc53947dde9d26f5ee95f151b2375bc70ae..73d2f68710025e15732441f6076c981cad6d7703 100644 (file)
@@ -231,7 +231,7 @@ int main(int argc, char * const argv[])
        }
 
        if (args.lebs != -1)
-               args.bytes = vol_info.leb_size * args.lebs;
+               args.bytes = (long long)vol_info.leb_size * args.lebs;
 
        err = ubi_rsvol(libubi, args.node, args.vol_id, args.bytes);
        if (err) {