nand-utils: fix integer overflow in nftldump.c
PATCH 1/1 nand-utils: fix integer overflow in nftldump.c
Report of the static analyzer:
The value of an arithmetic expression 'i * meminfo.erasesize' is a subject to overflow because its operands are not cast to a larger data type before performing arithmetic
Corrections explained:
one of the operands was cast to a wider type, such as unsigned long long, to expand the range of possible values and avoid overflow
Triggers found by static analyzer Svace.
--- nand-utils/nftldump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
nand-utils/nftldump.c +1 -1
@@ -124,7 +124,7 @@ static void dump_erase_units(void)for (i = MedHead[0 ].FirstPhysicalEUN; i < MedHead[0 ].FirstPhysicalEUN + MedHead[0 ].NumEraseUnits; i++) {/* For each Erase Unit */ - ofs = i * meminfo.erasesize; + ofs = (unsigned long long )i * meminfo.erasesize;/* read the Unit Control Information */ for (j =0 ; j <3 ; j++) {
Signature · 6 lines
2.30.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 19 lines · Anton Moryakov
Report of the static analyzer:
The value of an arithmetic expression 'i * meminfo.erasesize' is a subject to overflow because its operands are not cast to a larger data type before performing arithmeticCorrections explained:
one of the operands was cast to a wider type, such as unsigned long long, to expand the range of possible values and avoid overflowTriggers found by static analyzer Svace.
Signed-off-by Anton Moryakov <[email protected]>--- nand-utils/nftldump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)nand-utils/nftldump.c +0
-0
nand-utils/nftldump.c static void dump_erase_units(void) · line 127
Quoted 5 lines
nand-utils/nftldump.c +1
-1@@ -124,7 +124,7 @@ static void dump_erase_units(void)for (i = MedHead[0 ].FirstPhysicalEUN; i < MedHead[0 ].FirstPhysicalEUN + MedHead[0 ].NumEraseUnits; i++) {/* For each Erase Unit */ - ofs = i * meminfo.erasesize; + ofs = (unsigned long long )i * meminfo.erasesize;
This progream parses information from mtd in the 32-bit way(eg. MEMREADOOB rather than MEMREADOOB), which means that the total size of the supported mtd device is smaller than 2^32, so I think the overflow won't happen.
nand-utils/nftldump.c static void dump_erase_units(void)
Quoted 4 lines
nand-utils/nftldump.c +0
-0/* read the Unit Control Information */ for (j =0 ; j <3 ; j++) {
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/