]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MgrMonitor: fix null deref when invalid formatter is specified 29089/head
authorSage Weil <sage@redhat.com>
Wed, 17 Jul 2019 14:44:49 +0000 (09:44 -0500)
committerSage Weil <sage@redhat.com>
Wed, 17 Jul 2019 18:21:04 +0000 (13:21 -0500)
Fixes: https://tracker.ceph.com/issues/40804
Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/MgrMonitor.cc

index ff3539f72c593fe2bf0525862eca24add49957d9..31d5035df8f3124616997440ab7e019718b42499 100644 (file)
@@ -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<Formatter> f(Formatter::create(format));
+  cmd_getval(g_ceph_context, cmdmap, "format", format);
+  boost::scoped_ptr<Formatter> 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());