Whamcloud - gitweb
LU-17000 coverity: llverfs: Add check for -n option 83/52583/6
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Fri, 6 Oct 2023 05:41:53 +0000 (11:11 +0530)
committerOleg Drokin <green@whamcloud.com>
Wed, 25 Oct 2023 18:08:56 +0000 (18:08 +0000)
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 <arshad.hussain@aeoncomputing.com>
Change-Id: I8c795edba0cfde80402db0f877caeb91663629a3
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52583
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/doc/llverfs.8
lustre/utils/llverfs.c

index 605902b..288bde5 100644 (file)
@@ -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
index 1d3a041..06f1292 100644 (file)
@@ -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;