From 4eb37953c338747230c9770488efae149b24c7a8 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 13 Aug 2018 13:28:40 -0500 Subject: [PATCH] common: catch cmd_bad_get Signed-off-by: Sage Weil --- src/common/admin_socket.cc | 9 +++++++-- src/common/ceph_context.cc | 6 +++++- src/common/cmdparse.cc | 26 +++++++++++++++----------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/common/admin_socket.cc b/src/common/admin_socket.cc index a49298c6b403a..009304587c05d 100644 --- a/src/common/admin_socket.cc +++ b/src/common/admin_socket.cc @@ -352,11 +352,16 @@ bool AdminSocket::do_accept() retry_sys_call(::close, connection_fd); return false; } - cmd_getval(m_cct, cmdmap, "format", format); + try { + cmd_getval(m_cct, cmdmap, "format", format); + cmd_getval(m_cct, cmdmap, "prefix", c); + } catch (const bad_cmd_get& e) { + retry_sys_call(::close, connection_fd); + return false; + } if (format != "json" && format != "json-pretty" && format != "xml" && format != "xml-pretty") format = "json-pretty"; - cmd_getval(m_cct, cmdmap, "prefix", c); std::unique_lock l(lock); decltype(hooks)::iterator p; diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index 2e633fbed74df..e311eae3880d1 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -376,7 +376,11 @@ public: bool call(std::string_view command, const cmdmap_t& cmdmap, std::string_view format, bufferlist& out) override { - m_cct->do_command(command, cmdmap, format, &out); + try { + m_cct->do_command(command, cmdmap, format, &out); + } catch (const bad_cmd_get& e) { + return false; + } return true; } }; diff --git a/src/common/cmdparse.cc b/src/common/cmdparse.cc index 241aa3fa9ea0a..4230fc5808cc9 100644 --- a/src/common/cmdparse.cc +++ b/src/common/cmdparse.cc @@ -487,19 +487,23 @@ bool validate_arg(CephContext* cct, std::ostream& os) { Value v; - if (!cmd_getval(cct, cmdmap, string(name), v)) { - if constexpr (is_vector) { - // an empty list is acceptable. - return true; - } else { - if (auto req = desc.find("req"); - req != end(desc) && req->second == "false") { - return true; - } else { - os << "missing required parameter: '" << name << "'"; - return false; + try { + if (!cmd_getval(cct, cmdmap, string(name), v)) { + if constexpr (is_vector) { + // an empty list is acceptable. + return true; + } else { + if (auto req = desc.find("req"); + req != end(desc) && req->second == "false") { + return true; + } else { + os << "missing required parameter: '" << name << "'"; + return false; + } } } + } catch (const bad_cmd_get& e) { + return false; } auto validate = [&](const T& value) { if constexpr (is_same_v) { -- 2.39.5