Merge PR #29089 into master

* refs/pull/29089/head:
	mon/MgrMonitor: fix null deref when invalid formatter is specified

Reviewed-by: Kefu Chai <kchai@redhat.com>
Reviewed-by: João Eduardo Luís <joao@suse.de>
This commit is contained in:
Sage Weil 2019-07-22 13:40:31 -05:00
commit 525ab21f71

View File

@ -855,8 +855,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);
@ -952,14 +953,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());