From 1a1691d20ca3d0fa3fd9423320c59ffae9fa1ed6 Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Mon, 3 Dec 2018 08:05:31 +0000 Subject: [PATCH] ceph_argparse: fix CephBool to CephChoices conversion Commit 525623b has introduced a regression that makes Ceph clients of versions prior to Nautilus to receive invalid unicode characters in the commands list JSON sent by the monitors. The unicode characters are caused by memory corruption in a dangling pointer stored by a std::string_view. The dangling pointer belonged to an std::string object that was already destructed when the std::string_view is used. The fix in this PR makes the std::string object to live enough time for the std::string_view to be used safely. Signed-off-by: Ricardo Dias --- src/common/cmdparse.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/cmdparse.cc b/src/common/cmdparse.cc index 518112facf4ec..3380178934d6c 100644 --- a/src/common/cmdparse.cc +++ b/src/common/cmdparse.cc @@ -93,6 +93,7 @@ dump_cmd_to_json(Formatter *f, uint64_t features, const string& cmd) f->open_object_section(string(desckv["name"]).c_str()); // Compatibility for pre-nautilus clients that don't know about CephBool + std::string val; if (!HAVE_FEATURE(features, SERVER_NAUTILUS)) { auto i = desckv.find("type"); if (i != desckv.end() && i->second == "CephBool") { @@ -100,7 +101,7 @@ dump_cmd_to_json(Formatter *f, uint64_t features, const string& cmd) // of a 'true'/'false' value std::ostringstream oss; oss << std::string("--") << desckv["name"]; - std::string val = oss.str(); + val = oss.str(); std::replace(val.begin(), val.end(), '_', '-'); desckv["type"] = "CephChoices"; -- 2.39.5