From e7f277b86720df5b2d2fa8e80ab8d58b273f194b Mon Sep 17 00:00:00 2001 From: qiankunzheng Date: Fri, 25 Sep 2015 01:47:28 -0400 Subject: [PATCH] rgw/rgw_admin: Checking the legality of the params There is no messages When some params are invalid. so the Program should be added the function which checks params, if the params are invalid, the program will give some messages. Fixes: #13018 Signed-off-by: Qiankun Zheng --- src/rgw/rgw_admin.cc | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 1140cbdbbc5f..8b2ca4e4b1b0 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1229,9 +1229,17 @@ int main(int argc, char **argv) } else if (ceph_argparse_witharg(args, i, &val, "--min-rewrite-stripe-size", (char*)NULL)) { min_rewrite_stripe_size = (uint64_t)atoll(val.c_str()); } else if (ceph_argparse_witharg(args, i, &val, "--max-buckets", (char*)NULL)) { - max_buckets = atoi(val.c_str()); + max_buckets = (int)strict_strtol(val.c_str(), 10, &err); + if (!err.empty()) { + cerr << "ERROR: failed to parse max buckets: " << err << std::endl; + return EINVAL; + } } else if (ceph_argparse_witharg(args, i, &val, "--max-entries", (char*)NULL)) { - max_entries = atoi(val.c_str()); + max_entries = (int)strict_strtol(val.c_str(), 10, &err); + if (!err.empty()) { + cerr << "ERROR: failed to parse max entries: " << err << std::endl; + return EINVAL; + } } else if (ceph_argparse_witharg(args, i, &val, "--max-size", (char*)NULL)) { max_size = (int64_t)strict_strtoll(val.c_str(), 10, &err); if (!err.empty()) { @@ -1255,13 +1263,29 @@ int main(int argc, char **argv) } else if (ceph_argparse_witharg(args, i, &val, "--end-date", "--end-time", (char*)NULL)) { end_date = val; } else if (ceph_argparse_witharg(args, i, &val, "--num-shards", (char*)NULL)) { - num_shards = atoi(val.c_str()); + num_shards = (int)strict_strtol(val.c_str(), 10, &err); + if (!err.empty()) { + cerr << "ERROR: failed to parse num shards: " << err << std::endl; + return EINVAL; + } } else if (ceph_argparse_witharg(args, i, &val, "--max-concurrent-ios", (char*)NULL)) { - max_concurrent_ios = atoi(val.c_str()); + max_concurrent_ios = (int)strict_strtol(val.c_str(), 10, &err); + if (!err.empty()) { + cerr << "ERROR: failed to parse max concurrent ios: " << err << std::endl; + return EINVAL; + } } else if (ceph_argparse_witharg(args, i, &val, "--orphan-stale-secs", (char*)NULL)) { - orphan_stale_secs = (uint64_t)atoi(val.c_str()); + orphan_stale_secs = (uint64_t)strict_strtoll(val.c_str(), 10, &err); + if (!err.empty()) { + cerr << "ERROR: failed to parse orphan stale secs: " << err << std::endl; + return EINVAL; + } } else if (ceph_argparse_witharg(args, i, &val, "--shard-id", (char*)NULL)) { - shard_id = atoi(val.c_str()); + shard_id = (int)strict_strtol(val.c_str(), 10, &err); + if (!err.empty()) { + cerr << "ERROR: failed to parse shard id: " << err << std::endl; + return EINVAL; + } specified_shard_id = true; } else if (ceph_argparse_witharg(args, i, &val, "--daemon-id", (char*)NULL)) { daemon_id = val; -- 2.47.3