diff options
author | Corey Hickey <bugfood-c@fatooh.org> | 2022-01-23 17:39:33 -0800 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2023-02-01 11:37:18 -0500 |
commit | 513e559bfccc1a909900a47841a4367bdfff1470 (patch) | |
tree | ea7b2cad800b5bfa5534b1a1ab47dfb6e08b8b32 | |
parent | 5c04fdf8ce4dfc35cd36084d7feeca1a11dfedab (diff) | |
download | e2fsprogs-513e559bfccc1a909900a47841a4367bdfff1470.tar.gz |
badblocks: fix mis-printed error from block size check
block_size is parsed as an unsigned int from parse_uint(), so retain it
as such until _after_ it has been constrained to a size within INT_MAX.
Lower level code still requires this to be an int, so cast to int for
anything below main().
Before:
$ misc/badblocks -w -b 4294967295 -c 1 /tmp/testfile.bin
misc/badblocks: Invalid block size: -1
After:
$ misc/badblocks -w -b 4294967295 -c 1 /tmp/testfile.bin
misc/badblocks: Invalid block size: 4294967295
Signed-off-by: Corey Hickey <bugfood-c@fatooh.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r-- | misc/badblocks.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/misc/badblocks.c b/misc/badblocks.c index 85a53b01..e640eadd 100644 --- a/misc/badblocks.c +++ b/misc/badblocks.c @@ -1055,7 +1055,7 @@ int main (int argc, char ** argv) char * input_file = NULL; char * output_file = NULL; FILE * in = NULL; - int block_size = 1024; + unsigned int block_size = 1024; unsigned int blocks_at_once = 64; blk64_t last_block, first_block; int num_passes = 0; @@ -1205,9 +1205,9 @@ int main (int argc, char ** argv) exit(1); } } - if ((block_size <= 0) || (block_size > (1 << 24)) || + if ((block_size == 0) || (block_size > (1 << 24)) || (block_size & (block_size - 1))) { - com_err(program_name, 0, _("Invalid block size: %d\n"), + com_err(program_name, 0, _("Invalid block size: %u\n"), block_size); exit(1); } @@ -1223,7 +1223,7 @@ int main (int argc, char ** argv) device_name = argv[optind++]; if (optind > argc - 1) { errcode = ext2fs_get_device_size2(device_name, - block_size, + (int) block_size, &last_block); if (errcode == EXT2_ET_UNIMPLEMENTED) { com_err(program_name, 0, "%s", @@ -1353,7 +1353,7 @@ int main (int argc, char ** argv) do { unsigned int bb_count; - bb_count = test_func(dev, last_block, block_size, + bb_count = test_func(dev, last_block, (int) block_size, first_block, blocks_at_once); if (bb_count) passes_clean = 0; |