From: Abhishek Lekshmanan Date: Fri, 8 Jun 2018 15:41:54 +0000 (+0200) Subject: mon/ConfigKeyService: dump: print placeholder value for binary blobs X-Git-Tag: v12.2.6~8^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F21368%2Fhead;p=ceph.git mon/ConfigKeyService: dump: print placeholder value for binary blobs JSON cannot express arbitrary binary blobs. Instead of outputting invalid and unparseable JSON, represent the value of blobs as something like '<<< binary blob of length 12 >>>'. Fixes: http://tracker.ceph.com/issues/23622 Signed-off-by: Sage Weil (cherry picked from commit 4669134b89ee1f7759fb59faef218da0880daa98) Conflicts: PendingReleaseNotes: 12.2.6 dropped, will be added in a seperate pr src/mon/ConfigKeyService.cc (ConfigKeyService::store_dump does not take prefix argument in luminous) --- diff --git a/src/mon/ConfigKeyService.cc b/src/mon/ConfigKeyService.cc index 29ae9d959427..e191f8367c80 100644 --- a/src/mon/ConfigKeyService.cc +++ b/src/mon/ConfigKeyService.cc @@ -108,6 +108,17 @@ bool ConfigKeyService::store_has_prefix(const string &prefix) return false; } +static bool is_binary_string(const string& s) +{ + for (auto c : s) { + // \n and \t are escaped in JSON; other control characters are not. + if ((c < 0x20 && c != '\n' && c != '\t') || c >= 0x7f) { + return true; + } + } + return false; +} + void ConfigKeyService::store_dump(stringstream &ss) { KeyValueDB::Iterator iter = @@ -117,7 +128,14 @@ void ConfigKeyService::store_dump(stringstream &ss) f.open_object_section("config-key store"); while (iter->valid()) { - f.dump_string(iter->key().c_str(), iter->value().to_str()); + string s = iter->value().to_str(); + if (is_binary_string(s)) { + ostringstream ss; + ss << "<<< binary blob of length " << s.size() << " >>>"; + f.dump_string(iter->key().c_str(), ss.str()); + } else { + f.dump_string(iter->key().c_str(), s); + } iter->next(); } f.close_section();