From 4669134b89ee1f7759fb59faef218da0880daa98 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 10 Apr 2018 08:31:06 -0500 Subject: [PATCH] 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 --- PendingReleaseNotes | 5 +++++ src/mon/ConfigKeyService.cc | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/PendingReleaseNotes b/PendingReleaseNotes index c9eaa94ed45..e1e5322a6c5 100644 --- a/PendingReleaseNotes +++ b/PendingReleaseNotes @@ -165,3 +165,8 @@ method. See http://docs.ceph.com/docs/luminous/mgr/restful for details. has an error. This head object is there to show the snapset that was used in determining errors. + +* The config-key interface can store arbitrary binary blobs but JSON + can only express printable strings. If binary blobs are present, + the 'ceph config-key dump' command will show them as something like + ``<<< binary blob of length N >>>``. diff --git a/src/mon/ConfigKeyService.cc b/src/mon/ConfigKeyService.cc index 761cf399baf..a9d78fcd331 100644 --- a/src/mon/ConfigKeyService.cc +++ b/src/mon/ConfigKeyService.cc @@ -109,6 +109,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, const string& prefix) { KeyValueDB::Iterator iter = @@ -127,7 +138,14 @@ void ConfigKeyService::store_dump(stringstream &ss, const string& prefix) iter->key().find(prefix) != 0) { break; } - 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(); -- 2.39.5