Whamcloud - gitweb
badblocks: add error checking for command-line arguments for -b and -c
authorTheodore Ts'o <tytso@mit.edu>
Fri, 12 Feb 2021 16:53:23 +0000 (11:53 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 12 Feb 2021 16:53:23 +0000 (11:53 -0500)
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 <tytso@mit.edu>
misc/badblocks.c

index b48d490..afeb3da 100644 (file)
@@ -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++];