Skip to contentSkip to conversation

ubi-utils: ubirsvol: Fix integer overflow in ubirsvol.c

PATCH In review Anton Moryakov 2 participants 2 messages Dec 10, 2024 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ubi-utils: ubirsvol: Fix integer overflow in ubirsvol.c

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.

---
 ubi-utils/ubirsvol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ubi-utils/ubirsvol.c +1 -1
index 0854abc..73d2f68 100644
@@ -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) {
Signature · 6 lines
2.30.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Anton Moryakov

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

Quoted 7 lines

Triggers found by static analyzer Svace.

---
  ubi-utils/ubirsvol.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines
ubi-utils/ubirsvol.c +0 -0
index 0854abc..73d2f68 100644

ubi-utils/ubirsvol.c int main(int argc, char * const argv[]) · line 237

Quoted 8 lines
ubi-utils/ubirsvol.c +1 -1
@@ -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) {

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/