From: Corey Hickey Date: Mon, 24 Jan 2022 01:39:33 +0000 (-0800) Subject: badblocks: fix mis-printed error from block size check X-Git-Tag: v1.46.6~17 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=513e559bfccc1a909900a47841a4367bdfff1470;p=tools%2Fe2fsprogs.git 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 Signed-off-by: Theodore Ts'o --- diff --git a/misc/badblocks.c b/misc/badblocks.c index 85a53b0..e640ead 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;