From: Kongming Date: Sat, 23 Jan 2016 14:37:25 +0000 (+0800) Subject: rbd: Add an argument-check for nbds_max in rbd-nbd X-Git-Tag: v10.0.4~146^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=39e7fcdb8c11f259ec8a5541144a34fd3fcf74f4;p=ceph.git rbd: Add an argument-check for nbds_max in rbd-nbd 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 --- diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index 41fcfc25e6b1..e0c0284021c5 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -751,13 +751,22 @@ static int rbd_nbd(int argc, const char *argv[]) CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS); std::vector::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 {