From b3cc451fc299c7d377196aaa9058026dad231721 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 17 Jul 2019 09:44:49 -0500 Subject: [PATCH] mon/MgrMonitor: fix null deref when invalid formatter is specified Fixes: https://tracker.ceph.com/issues/40804 Signed-off-by: Sage Weil --- src/mon/MgrMonitor.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/mon/MgrMonitor.cc b/src/mon/MgrMonitor.cc index ff3539f72c5..31d5035df8f 100644 --- a/src/mon/MgrMonitor.cc +++ b/src/mon/MgrMonitor.cc @@ -854,8 +854,9 @@ bool MgrMonitor::preprocess_command(MonOpRequestRef op) } string format; - cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(Formatter::create(format)); + cmd_getval(g_ceph_context, cmdmap, "format", format); + boost::scoped_ptr f(Formatter::create(format, "json-pretty", + "json-pretty")); string prefix; cmd_getval(g_ceph_context, cmdmap, "prefix", prefix); @@ -951,14 +952,10 @@ bool MgrMonitor::preprocess_command(MonOpRequestRef op) } f->flush(rdata); } else if (prefix == "mgr versions") { - if (!f) - f.reset(Formatter::create("json-pretty")); count_metadata("ceph_version", f.get()); f->flush(rdata); r = 0; } else if (prefix == "mgr count-metadata") { - if (!f) - f.reset(Formatter::create("json-pretty")); string field; cmd_getval(g_ceph_context, cmdmap, "property", field); count_metadata(field, f.get());