From: Sage Weil Date: Thu, 2 Aug 2018 19:34:44 +0000 (-0500) Subject: mon: catch bad_cmd_exception and reply EINVAL X-Git-Tag: v14.0.1~648^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=b684f02c72f24c7181a459c9034ef63609060124;p=ceph-ci.git mon: catch bad_cmd_exception and reply EINVAL If we get bad input we should always reply EINVAL. Note that bad_cmd_get will be reserved for invalid input, not missing/optional input, like passing a float when an int is expected. Signed-off-by: Sage Weil --- diff --git a/src/mon/AuthMonitor.cc b/src/mon/AuthMonitor.cc index 147e4d69f81..b8a3b320e2d 100644 --- a/src/mon/AuthMonitor.cc +++ b/src/mon/AuthMonitor.cc @@ -363,7 +363,14 @@ bool AuthMonitor::preprocess_query(MonOpRequestRef op) dout(10) << "preprocess_query " << *m << " from " << m->get_orig_source_inst() << dendl; switch (m->get_type()) { case MSG_MON_COMMAND: - return preprocess_command(op); + try { + return preprocess_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } case CEPH_MSG_AUTH: return prep_auth(op, false); @@ -383,7 +390,14 @@ bool AuthMonitor::prepare_update(MonOpRequestRef op) dout(10) << "prepare_update " << *m << " from " << m->get_orig_source_inst() << dendl; switch (m->get_type()) { case MSG_MON_COMMAND: - return prepare_command(op); + try { + return prepare_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } case MSG_MON_GLOBAL_ID: return prepare_global_id(op); case CEPH_MSG_AUTH: diff --git a/src/mon/ConfigMonitor.cc b/src/mon/ConfigMonitor.cc index 1f5cfb25d8e..872a4c5257a 100644 --- a/src/mon/ConfigMonitor.cc +++ b/src/mon/ConfigMonitor.cc @@ -109,7 +109,14 @@ bool ConfigMonitor::preprocess_query(MonOpRequestRef op) { switch (op->get_req()->get_type()) { case MSG_MON_COMMAND: - return preprocess_command(op); + try { + return preprocess_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } } return false; } @@ -367,7 +374,14 @@ bool ConfigMonitor::prepare_update(MonOpRequestRef op) << " from " << m->get_orig_source_inst() << dendl; switch (m->get_type()) { case MSG_MON_COMMAND: - return prepare_command(op); + try { + return prepare_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } } return false; } diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index 95ea2bda5aa..28d57d3e812 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -258,7 +258,14 @@ bool LogMonitor::preprocess_query(MonOpRequestRef op) dout(10) << "preprocess_query " << *m << " from " << m->get_orig_source_inst() << dendl; switch (m->get_type()) { case MSG_MON_COMMAND: - return preprocess_command(op); + try { + return preprocess_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } case MSG_LOG: return preprocess_log(op); @@ -276,7 +283,14 @@ bool LogMonitor::prepare_update(MonOpRequestRef op) dout(10) << "prepare_update " << *m << " from " << m->get_orig_source_inst() << dendl; switch (m->get_type()) { case MSG_MON_COMMAND: - return prepare_command(op); + try { + return prepare_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } case MSG_LOG: return prepare_log(op); default: diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index f716a75419a..22b8d566f24 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -286,7 +286,14 @@ bool MDSMonitor::preprocess_query(MonOpRequestRef op) return preprocess_beacon(op); case MSG_MON_COMMAND: - return preprocess_command(op); + try { + return preprocess_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } case MSG_MDS_OFFLOAD_TARGETS: return preprocess_offload_targets(op); @@ -497,7 +504,14 @@ bool MDSMonitor::prepare_update(MonOpRequestRef op) return prepare_beacon(op); case MSG_MON_COMMAND: - return prepare_command(op); + try { + return prepare_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } case MSG_MDS_OFFLOAD_TARGETS: return prepare_offload_targets(op); diff --git a/src/mon/MgrMonitor.cc b/src/mon/MgrMonitor.cc index a7af4241c00..e4207c4eba4 100644 --- a/src/mon/MgrMonitor.cc +++ b/src/mon/MgrMonitor.cc @@ -220,7 +220,15 @@ bool MgrMonitor::preprocess_query(MonOpRequestRef op) case MSG_MGR_BEACON: return preprocess_beacon(op); case MSG_MON_COMMAND: - return preprocess_command(op); + try { + return preprocess_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } + default: mon->no_reply(op); derr << "Unhandled message type " << m->get_type() << dendl; @@ -236,7 +244,14 @@ bool MgrMonitor::prepare_update(MonOpRequestRef op) return prepare_beacon(op); case MSG_MON_COMMAND: - return prepare_command(op); + try { + return prepare_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } default: mon->no_reply(op); diff --git a/src/mon/MonmapMonitor.cc b/src/mon/MonmapMonitor.cc index 245acde6e16..2397d4642dc 100644 --- a/src/mon/MonmapMonitor.cc +++ b/src/mon/MonmapMonitor.cc @@ -201,7 +201,14 @@ bool MonmapMonitor::preprocess_query(MonOpRequestRef op) switch (m->get_type()) { // READs case MSG_MON_COMMAND: - return preprocess_command(op); + try { + return preprocess_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } case MSG_MON_JOIN: return preprocess_join(op); default: @@ -405,7 +412,14 @@ bool MonmapMonitor::prepare_update(MonOpRequestRef op) switch (m->get_type()) { case MSG_MON_COMMAND: - return prepare_command(op); + try { + return prepare_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } case MSG_MON_JOIN: return prepare_join(op); default: diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 02900318fee..27c26a7d63d 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2037,7 +2037,14 @@ bool OSDMonitor::preprocess_query(MonOpRequestRef op) switch (m->get_type()) { // READs case MSG_MON_COMMAND: - return preprocess_command(op); + try { + return preprocess_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } case CEPH_MSG_MON_GET_OSDMAP: return preprocess_get_osdmap(op); @@ -2097,7 +2104,14 @@ bool OSDMonitor::prepare_update(MonOpRequestRef op) return prepare_beacon(op); case MSG_MON_COMMAND: - return prepare_command(op); + try { + return prepare_command(op); + } + catch (const bad_cmd_get& e) { + bufferlist bl; + mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed()); + return true; + } case CEPH_MSG_POOLOP: return prepare_pool_op(op);