Whamcloud - gitweb
LU-14535 utils: fix FORWARD_NULL issue from Coverity 27/54827/4
authorHongchao Zhang <hongchao@whamcloud.com>
Sun, 14 Apr 2024 23:13:57 +0000 (07:13 +0800)
committerOleg Drokin <green@whamcloud.com>
Tue, 21 May 2024 18:39:24 +0000 (18:39 +0000)
Fixing the possible NULL pointer issued reported from Coverity

   case 'e':
CID 424708:    (FORWARD_NULL)
Passing null pointer "optarg" to "strtoul", which dereferences it.
      end_qid = strtoul(optarg, NULL, 0);
      break;

CoverityID: 424708 ("FORWARD NULL")

Signed-off-by: Hongchao Zhang <hongchao@whamcloud.com>
Change-Id: Idfb5cb4c6fe63ec08dd9048742f3f280b125eb8a
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54827
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/utils/lfs.c

index c85a572..b40d7f2 100644 (file)
@@ -9502,6 +9502,13 @@ static int lfs_quota(int argc, char **argv)
                        qctl->qc_cmd = LUSTRE_Q_ITERQUOTA;
                        break;
                case 'e':
+                       if (optarg == NULL || *optarg == '\0') {
+                               fprintf(stderr,
+                                       "%s quota: invalid start quota ID\n",
+                               progname);
+                               rc = CMD_HELP;
+                               goto out;
+                       }
                        end_qid = strtoul(optarg, NULL, 0);
                        break;
                case 'G':
@@ -9592,6 +9599,13 @@ static int lfs_quota(int argc, char **argv)
                        quiet = 1;
                        break;
                case 's':
+                       if (optarg == NULL || *optarg == '\0') {
+                               fprintf(stderr,
+                                       "%s quota: invalid start quota ID\n",
+                               progname);
+                               rc = CMD_HELP;
+                               goto out;
+                       }
                        start_qid = strtoul(optarg, NULL, 0);
                        break;
                case 't':