]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MgrMonitor: fix null deref when invalid formatter is specified 29593/head
authorSage Weil <sage@redhat.com>
Wed, 17 Jul 2019 14:44:49 +0000 (09:44 -0500)
committerPrashant D <pdhange@redhat.com>
Mon, 12 Aug 2019 00:22:10 +0000 (20:22 -0400)
Fixes: https://tracker.ceph.com/issues/40804
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit b3cc451fc299c7d377196aaa9058026dad231721)

src/mon/MgrMonitor.cc

index 6b4eab48fdc986fd25138c6f7fe9487a5f94d5cd..2bf1866a8d89cbebe322fc98fc2f07b7f1f6fa71 100644 (file)
@@ -682,8 +682,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);
@@ -776,14 +777,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());