aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2021-02-12 11:53:23 -0500
committerTheodore Ts'o <tytso@mit.edu>2021-02-12 11:53:23 -0500
commit10f9b11b76514794f0a868676327b8219c655364 (patch)
tree5e1978b6b9b6d0587784f58bb4d650b3c15f4a9f
parent46fcf7087b557ad3ba18af4996a1cb9ded7c43b5 (diff)
downloade2fsprogs-10f9b11b76514794f0a868676327b8219c655364.tar.gz
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 <tytso@mit.edu>
-rw-r--r--misc/badblocks.c14
1 files changed, 13 insertions, 1 deletions
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++];