From 5eaa7e8905c1d98373acf6e4db729fe7f6e6fa3d Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Fri, 6 Oct 2023 11:11:53 +0530 Subject: [PATCH] LU-17000 coverity: llverfs: Add check for -n option CID: 397833 (Uninitialized scalar variable): llverfs.c This patch also add missing "-n" opiton under man page Test-Parameters: trivial testlist=sanity,conf-sanity Signed-off-by: Arshad Hussain Change-Id: I8c795edba0cfde80402db0f877caeb91663629a3 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52583 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Timothy Day Reviewed-by: Oleg Drokin Reviewed-by: Andreas Dilger --- lustre/doc/llverfs.8 | 3 +++ lustre/utils/llverfs.c | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lustre/doc/llverfs.8 b/lustre/doc/llverfs.8 index 605902b..288bde5 100644 --- a/lustre/doc/llverfs.8 +++ b/lustre/doc/llverfs.8 @@ -48,6 +48,9 @@ Display a brief help message. .BR -l | --long | --full Run a full check, 4GB files with 4k blocks .TP +.BR -n | --num_dirs " \fICOUNT" +\fICOUNT\fR number of sub-directories to create. (\fICOUNT\fR must be >0 and <= INT_MAX) +.TP .BR -o | --offset " \fIOFFSET_KB" offset of IO start in kilobytes (default=0), with optional KMGTP suffix. .TP diff --git a/lustre/utils/llverfs.c b/lustre/utils/llverfs.c index 1d3a041..06f1292 100644 --- a/lustre/utils/llverfs.c +++ b/lustre/utils/llverfs.c @@ -702,6 +702,8 @@ int main(int argc, char **argv) progname = strrchr(argv[0], '/') ? strrchr(argv[0], '/') + 1 : argv[0]; while ((c = getopt_long(argc, argv, "c:hln:o:pqrs:t:vw", long_opts, NULL)) != -1) { + unsigned long val; /* Staging value for num_dirs */ + switch (c) { case 'c': chunksize = strtoul(optarg, NULL, 0) * ONE_MB; @@ -715,8 +717,19 @@ int main(int argc, char **argv) full = 1; break; case 'n': - num_dirs = strtoul(optarg, NULL, 0); + /* num_dirs cannot be negative */ + if (optarg[0] == '-') + goto out_num_dirs; + val = strtoul(optarg, NULL, 0); + if (val == 0 || val > INT_MAX || errno == ERANGE) + goto out_num_dirs; + num_dirs = val; break; +out_num_dirs: + fprintf(stderr, "%s: bad directory count '%s'", optarg, + progname); + usage(1); + return -1; case 'o': /* offset */ dir_num = strtoul(optarg, NULL, 0); break; -- 1.8.3.1