From 49d2fb71422fe4edfe5795c001104fb5bc8c98c3 Mon Sep 17 00:00:00 2001 From: Joao Eduardo Luis Date: Fri, 22 Nov 2013 02:17:16 +0000 Subject: [PATCH] mon: OSDMonitor: don't crash if formatter is invalid during osd crush dump Code would assume a formatter would always be defined. If a 'plain' formatter or even an invalid formatter were to be supplied, the monitor would crash and burn in poor style. Fixes: 6820 Backport: emperor Signed-off-by: Joao Eduardo Luis --- src/mon/OSDMonitor.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 1994b0d2dbabd..058a5cfeef3a3 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2414,7 +2414,10 @@ stats_out: prefix == "osd crush rule ls") { string format; cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(new_formatter(format)); + Formatter *fp = new_formatter(format); + if (!fp) + fp = new_formatter("json-pretty"); + boost::scoped_ptr f(fp); f->open_array_section("rules"); osdmap.crush->list_rules(f.get()); f->close_section(); @@ -2425,7 +2428,10 @@ stats_out: } else if (prefix == "osd crush rule dump") { string format; cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(new_formatter(format)); + Formatter *fp = new_formatter(format); + if (!fp) + fp = new_formatter("json-pretty"); + boost::scoped_ptr f(fp); f->open_array_section("rules"); osdmap.crush->dump_rules(f.get()); f->close_section(); @@ -2436,7 +2442,10 @@ stats_out: } else if (prefix == "osd crush dump") { string format; cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty")); - boost::scoped_ptr f(new_formatter(format)); + Formatter *fp = new_formatter(format); + if (!fp) + fp = new_formatter("json-pretty"); + boost::scoped_ptr f(fp); f->open_object_section("crush_map"); osdmap.crush->dump(f.get()); f->close_section(); -- 2.39.5