From 10f9b11b76514794f0a868676327b8219c655364 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 12 Feb 2021 11:53:23 -0500 Subject: [PATCH] badblocks: add error checking for command-line arguments for -b and -c Also remove a dead assignment (the value of try is overwritten after the continue statement). Addresses-Coverity-Bug: 1297515 Addresses-Coverity-Bug: 1464573 Signed-off-by: Theodore Ts'o --- misc/badblocks.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/misc/badblocks.c b/misc/badblocks.c index b48d490..afeb3da 100644 --- a/misc/badblocks.c +++ b/misc/badblocks.c @@ -892,7 +892,6 @@ static unsigned int test_nd (int dev, blk_t last_block, test_ptr += got * block_size; currently_testing += got; if (got != try) { - try = 1; if (recover_block == ~0U) recover_block = currently_testing - got + blocks_at_once; @@ -1201,6 +1200,19 @@ int main (int argc, char ** argv) exit(1); } } + if ((block_size <= 0) || (block_size > (1 << 24)) || + (block_size & (block_size - 1))) { + com_err(program_name, 0, _("Invalid block size: %d\n"), + block_size); + exit(1); + } + if ((blocks_at_once <= 0) || + (((unsigned long long) block_size * blocks_at_once) > 0xFFFFFFFF)) { + com_err(program_name, 0, _("Invalid blocks_at_once: %d\n"), + blocks_at_once); + exit(1); + } + if (optind > argc - 1) usage(); device_name = argv[optind++]; -- 1.8.3.1