From: Sami Kerola Date: Tue, 7 Feb 2012 20:10:33 +0000 (+0100) Subject: mkfs.cramfs: check blocksize user input [cppcheck] X-Git-Tag: v2.21~44 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2e24868683ad405ed73aac7654730bbf1038087d;p=thirdparty%2Futil-linux.git mkfs.cramfs: check blocksize user input [cppcheck] Enhance user input checking and error messaging, while fixing cppcheck warning. [disk-utils/mkfs.cramfs.c:729]: (style) Checking if unsigned variable 'blksize' is less than zero. [kzak@redhat.com: fix coding style] Signed-off-by: Sami Kerola Signed-off-by: Karel Zak --- diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c index 2fe95bf82f..37895a380d 100644 --- a/disk-utils/mkfs.cramfs.c +++ b/disk-utils/mkfs.cramfs.c @@ -725,10 +725,15 @@ int main(int argc, char **argv) case 'h': usage(MKFS_OK); case 'b': - blksize = strtoll_or_err(optarg, _("failed to parse blocksize argument")); - if (blksize <= 0) - usage(MKFS_USAGE); + { + long long tmp = strtoll_or_err(optarg, + _("failed to parse blocksize argument")); + + if (tmp <= 0 || UINT_MAX < tmp) + errx(MKFS_USAGE, _("invalid block size")); + blksize = tmp; break; + } case 'E': opt_errors = 1; break;