From: Theodore Ts'o Date: Fri, 12 Feb 2021 16:53:23 +0000 (-0500) Subject: badblocks: add error checking for command-line arguments for -b and -c X-Git-Tag: v1.46.2~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10f9b11b76514794f0a868676327b8219c655364;p=thirdparty%2Fe2fsprogs.git 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 --- diff --git a/misc/badblocks.c b/misc/badblocks.c index b48d490c9..afeb3da9d 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++];