ubifs-utils: mkfs.ubifs: fix integer overflow in mkfs.ubifs.c
PATCH 1/1 ubifs-utils: mkfs.ubifs: fix integer overflow in mkfs.ubifs.c
Report of the static analyzer:
The value of an arithmetic expression '4 * c->leb_size' is a subject to overflow because its operands are not cast to a larger data type before performing arithmetic
Corrections explained:
To avoid overflow, we cast one of the operands (in this case c->leb_size) to type long long, which has a larger range.
Triggers found by static analyzer Svace.
--- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +2 -2
@@ -858,8 +858,8 @@ static int get_options(int argc, char**argv)/* Make the max journal size 8MiB */ if (c->max_bud_bytes >8 *1024 *1024 ) c->max_bud_bytes =8 *1024 *1024 ; -if (c->max_bud_bytes <4 * c->leb_size) - c->max_bud_bytes =4 * c->leb_size; +if (c->max_bud_bytes <4 * (long long )c->leb_size) + c->max_bud_bytes =4 * (long long )c->leb_size; }if (c->log_lebs ==-1 ) {
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 '4 *c->leb_size' is a subject to overflow because its operands are not cast to a larger data type before performing arithmeticCorrections explained:
To avoid overflow, we cast one of the operands (in this casec->leb_size) to type long long, which has a larger range.Triggers found by static analyzer Svace.
Signed-off-by Anton Moryakov <[email protected]>--- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +0
-0
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c static int get_options(int argc, char**argv) · line 863
Quoted 8 lines
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +2
-2@@ -858,8 +858,8 @@ static int get_options(int argc, char**argv)/* Make the max journal size 8MiB */ if (c->max_bud_bytes >8 *1024 *1024 ) c->max_bud_bytes =8 *1024 *1024 ; -if (c->max_bud_bytes <4 * c->leb_size) - c->max_bud_bytes =4 * c->leb_size; +if (c->max_bud_bytes <4 * (long long )c->leb_size) + c->max_bud_bytes =4 * (long long )c->leb_size; }
The '4 * c->leb_size' could trigger an overflow, because 'c->leb_size' is initialized by user option '-e'. However, function validate_options() checks 'c->leb_size' and terminates the program if it exceeds UBIFS_MAX_LEB_SZ[2M], so there will be no effects.
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c static int get_options(int argc, char**argv) · line 865
Quoted 3 lines
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +0
-0if (c->log_lebs ==-1 ) {
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/