From: Ricardo Dias Date: Mon, 3 Dec 2018 08:05:31 +0000 (+0000) Subject: ceph_argparse: fix CephBool to CephChoices conversion X-Git-Tag: v14.1.0~736^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F25373%2Fhead;p=ceph.git 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 --- diff --git a/src/common/cmdparse.cc b/src/common/cmdparse.cc index 518112facf4e..3380178934d6 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";