From: Jesse F. Williamson Date: Fri, 21 Mar 2025 15:57:07 +0000 (-0700) Subject: DNM testing X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=d942b9fcebf99ead8aa0e3eb5e1d028d7d7e1cd4;p=ceph.git DNM testing Signed-off-by: Jesse F. Williamson --- diff --git a/src/common/ceph_json.cc b/src/common/ceph_json.cc index 77aceb8b3ac82..dbab32105a15a 100644 --- a/src/common/ceph_json.cc +++ b/src/common/ceph_json.cc @@ -146,6 +146,40 @@ bool JSONParser::parse(std::string_view json_string_view) return false; } +bool JSONParser::parse(const char *buf_, int len) +{ + if (nullptr == buf_ || 0 >= len) { + return false; + } + + if (!parse_json({ buf_, static_cast(len) }, data)) { + return false; + } + + // recursively evaluate the result: + handle_value(data); + + if (data.is_object() or data.is_array()) + return true; + + if (data.is_string()) { + val.set(data.as_string(), true); + return true; + } + + // For any other kind of value: + std::string s = boost::json::serialize(data); + + // Was the entire string read? + if (s.size() == static_cast(len)) { + val.set(s, false); + return true; + } + + // Could not parse and convert: + return false; +} + // parse a supplied ifstream: bool JSONParser::parse(const char *file_name) { diff --git a/src/common/ceph_json.h b/src/common/ceph_json.h index 58416401b3f47..0c4c8cd10dc83 100644 --- a/src/common/ceph_json.h +++ b/src/common/ceph_json.h @@ -289,12 +289,7 @@ public: // operate on a string/stringlike range or object: bool parse(std::string_view sv); - - bool parse(const char *buf_, int len) { - return buf_ ? - parse(std::string_view { buf_, static_cast(len) }) - : false; - } + bool parse(const char *buf_, int len); // operate on a data file: bool parse(const char *file_name); diff --git a/src/rgw/rgw_policy_s3.cc b/src/rgw/rgw_policy_s3.cc index d734249ed2c3b..0414dd5cdebbc 100644 --- a/src/rgw/rgw_policy_s3.cc +++ b/src/rgw/rgw_policy_s3.cc @@ -250,7 +250,7 @@ int RGWPolicy::from_json(bufferlist& bl, string& err_msg) // Without subtracting 1, we wind up sending bad data into the // parser: - if (!parser.parse(bl.c_str(), bl.length() - 1)) { + if (!parser.parse(bl.c_str(), bl.length())) { err_msg = "Malformed JSON (RGWPolicy)"; dout(0) << "malformed json (RGWPolicy)" << dendl; return -EINVAL;