From 39e7fcdb8c11f259ec8a5541144a34fd3fcf74f4 Mon Sep 17 00:00:00 2001 From: Kongming Date: Sat, 23 Jan 2016 22:37:25 +0800 Subject: [PATCH] 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 --- src/tools/rbd_nbd/rbd-nbd.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index 41fcfc25e6b..e0c0284021c 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 { -- 2.47.3