Skip to contentSkip to conversation

jffsX-utils: fix integer overflow in jffs2dump.c

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jffsX-utils: fix integer overflow in jffs2dump.c

Report of the static analyzer:
The value of an arithmetic expression 'datsize + oobsize' is a subject to overflow because its operands are not cast to a larger data type before performing arithmetic

Corrections explained:
Fixed potential overflow in arithmetic operation datsize + oobsize by casting operands to unsigned long long to ensure safe computation.

Triggers found by static analyzer Svace.

---
 jffsX-utils/jffs2dump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
jffsX-utils/jffs2dump.c +1 -1
index 30455ea..5be7a5b 100644
@@ -783,7 +783,7 @@ int main(int argc, char **argv)
 			read_nocheck (fd, oob, oobsize);
 			idx += datsize;
 			imglen -= oobsize;
-			len -= datsize + oobsize;
+			len -= (unsigned long long)datsize + (unsigned long long)oobsize;
 		}
 
 	} else {
Signature · 6 lines
2.30.2


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

Report of the static analyzer:
The value of an arithmetic expression 'datsize + oobsize' is a subject to overflow because its operands are not cast to a larger data type before performing arithmetic

Corrections explained:
Fixed potential overflow in arithmetic operation datsize + oobsize by casting operands to unsigned long long to ensure safe computation.

Triggers found by static analyzer Svace.

---
  jffsX-utils/jffs2dump.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
jffsX-utils/jffs2dump.c +0 -0
index 30455ea..5be7a5b 100644

jffsX-utils/jffs2dump.c int main(int argc, char **argv) · line 786

Quoted 5 lines
jffsX-utils/jffs2dump.c +1 -1
@@ -783,7 +783,7 @@ int main(int argc, char **argv)
  			read_nocheck (fd, oob, oobsize);
  			idx += datsize;
  			imglen -= oobsize;
-			len -= datsize + oobsize;
+			len -= (unsigned long long)datsize + (unsigned long long)oobsize;

The 'datsize' and 'oobsize' are parsed from user arguments, 'datsize' and 'oobsize' could be negative, so I think we need more checking items.

jffsX-utils/jffs2dump.c int main(int argc, char **argv) · line 789

Quoted 4 lines
jffsX-utils/jffs2dump.c +0 -0
  		}
 
  	} else {

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