]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/ConfigKeyService: dump: print placeholder value for binary blobs 21329/head
authorSage Weil <sage@redhat.com>
Tue, 10 Apr 2018 13:31:06 +0000 (08:31 -0500)
committerSage Weil <sage@redhat.com>
Wed, 11 Apr 2018 21:04:03 +0000 (16:04 -0500)
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 <sage@redhat.com>
PendingReleaseNotes
src/mon/ConfigKeyService.cc

index c9eaa94ed4564c20001003a352ac80055de806f3..e1e5322a6c5ff5c012225958ad8ae59d7735a9dc 100644 (file)
@@ -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 >>>``.
index 761cf399baf72647dfbece9aaa75ad99f134ea0e..a9d78fcd33158df111e1dd2e49fa397cbfbd5e68 100644 (file)
@@ -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();