]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: Add an argument-check for nbds_max in rbd-nbd 7337/head
authorKongming <wu.kongming@h3c.com>
Sat, 23 Jan 2016 14:37:25 +0000 (22:37 +0800)
committerKongming Wu <wu.kongming@h3c.com>
Wed, 27 Jan 2016 01:37:23 +0000 (09:37 +0800)
Fixes: #14482
This modification adds several checks to the argument of nbds_max in the module of rbd-nbd. The value of nbds_max is strictly limited to non-negative integer now.

Signed-off-by: Kongming Wu <wu.kongming@h3c.com>
src/tools/rbd_nbd/rbd-nbd.cc

index 41fcfc25e6b1d8f8162baceae66591000afb2ded..e0c0284021c55c842da1b4dad47504e1fc7bfdde 100644 (file)
@@ -751,13 +751,22 @@ static int rbd_nbd(int argc, const char *argv[])
               CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS);
 
   std::vector<const char*>::iterator i;
+  std::ostringstream err;
 
   for (i = args.begin(); i != args.end(); ) {
     if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) {
       usage();
       return 0;
     } else if (ceph_argparse_witharg(args, i, &devpath, "--device", (char *)NULL)) {
-    } else if (ceph_argparse_witharg(args, i, &nbds_max, cerr, "--nbds_max", (char *)NULL)) {
+    } else if (ceph_argparse_witharg(args, i, &nbds_max, err, "--nbds_max", (char *)NULL)) {
+      if (!err.str().empty()) {
+        cerr << err.str() << std::endl;
+        return EXIT_FAILURE;
+      }
+      if (nbds_max < 0) {
+        cerr << "rbd-nbd: Invalid argument for nbds_max!" << std::endl;
+        return EXIT_FAILURE;
+      }
     } else if (ceph_argparse_flag(args, i, "--read-only", (char *)NULL)) {
       readonly = true;
     } else {