From: Jesse F. Williamson Date: Sat, 15 Feb 2025 18:47:36 +0000 (-0800) Subject: revert parse() support for buffer::list X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=a13ab3b2ca30d6c274a58a8e5e408a6f3e9ddd2d;p=ceph.git revert parse() support for buffer::list This is why we can't have nice things. Signed-off-by: Jesse F. Williamson --- diff --git a/src/common/ceph_json.h b/src/common/ceph_json.h index 643ab7d34cd46..00d015fa555e2 100644 --- a/src/common/ceph_json.h +++ b/src/common/ceph_json.h @@ -32,8 +32,6 @@ #include #include -#include "include/buffer.h" - #include "common/ceph_time.h" #include @@ -283,8 +281,6 @@ public: : false; } - bool parse(ceph::buffer::list& bl) { return parse(std::string_view { bl.c_str(), bl.length() }); } - // operate on a data file: bool parse(const char *file_name); @@ -301,7 +297,7 @@ public: JSONParser parser; JSONDecoder(ceph::buffer::list& bl) { - if (!parser.parse(bl)) + if (!parser.parse(bl.c_str(), bl.length())) throw JSONDecoder::err("failed to parse JSON input"); } diff --git a/src/rgw/rgw_auth_keystone.cc b/src/rgw/rgw_auth_keystone.cc index 33bf75bb34742..7f3bd66a1b95c 100644 --- a/src/rgw/rgw_auth_keystone.cc +++ b/src/rgw/rgw_auth_keystone.cc @@ -546,7 +546,7 @@ auto EC2Engine::get_secret_from_keystone(const DoutPrefixProvider* dpp, /* now parse response */ JSONParser parser; - if (! parser.parse(token_body_bl)) { + if (! parser.parse(token_body_bl.c_str(), token_body_bl.length())) { ldpp_dout(dpp, 0) << "Keystone credential parse error: malformed json" << dendl; return make_pair(boost::none, -EINVAL); } diff --git a/src/rgw/rgw_keystone.cc b/src/rgw/rgw_keystone.cc index aab3b47ba1b82..2767cea06def1 100644 --- a/src/rgw/rgw_keystone.cc +++ b/src/rgw/rgw_keystone.cc @@ -285,7 +285,7 @@ int TokenEnvelope::parse(const DoutPrefixProvider *dpp, ceph::bufferlist& bl) { JSONParser parser; - if (! parser.parse(bl)) { + if (! parser.parse(bl.c_str(), bl.length())) { ldpp_dout(dpp, 0) << "Keystone token parse error: malformed json" << dendl; return -EINVAL; } diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc index 65ada37dcc06d..92b03e41bcdc1 100644 --- a/src/rgw/rgw_metadata.cc +++ b/src/rgw/rgw_metadata.cc @@ -309,7 +309,7 @@ int RGWMetadataManager::put(string& metadata_key, bufferlist& bl, } JSONParser parser; - if (!parser.parse(bl)) { + if (!parser.parse(bl.c_str(), bl.length())) { return -EINVAL; } diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 50ed075d7a8ff..a96eb3ef6024f 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -159,7 +159,7 @@ int rgw_forward_request_to_master(const DoutPrefixProvider* dpp, if (ret < 0) { return ret; } - if (jp && !jp->parse(outdata)) { + if (jp && !jp->parse(outdata.c_str(), outdata.length())) { ldpp_dout(dpp, 0) << "failed parsing response from master zonegroup" << dendl; return -EINVAL; } diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index a0314cf1c3e6d..cbe441c140bfd 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -158,7 +158,7 @@ int rgw_rest_get_json_input(CephContext *cct, req_state *s, T& out, JSONParser parser; - if (!parser.parse(data)) { + if (!parser.parse(data.c_str(), data.length())) { return -EINVAL; } diff --git a/src/rgw/rgw_opa.cc b/src/rgw/rgw_opa.cc index 93b8693dbdf58..0bda4d62a51ad 100644 --- a/src/rgw/rgw_opa.cc +++ b/src/rgw/rgw_opa.cc @@ -79,7 +79,7 @@ int rgw_opa_authorize(RGWOp *& op, /* check OPA response */ JSONParser parser; - if (!parser.parse(bl)) { + if (!parser.parse(bl.c_str(), bl.length())) { ldpp_dout(op, 2) << "OPA parse error: malformed json" << dendl; return -EINVAL; } diff --git a/src/rgw/rgw_period_puller.cc b/src/rgw/rgw_period_puller.cc index 6a8cca0aedc5d..ea2f28e567b46 100644 --- a/src/rgw/rgw_period_puller.cc +++ b/src/rgw/rgw_period_puller.cc @@ -46,7 +46,7 @@ int pull_period(const DoutPrefixProvider *dpp, RGWRESTConn* conn, const std::str } JSONParser parser; - r = parser.parse(data); + r = parser.parse(data.c_str(), data.length()); if (r < 0) { ldpp_dout(dpp, -1) << "request failed: " << cpp_strerror(-r) << dendl; return r; diff --git a/src/rgw/rgw_policy_s3.cc b/src/rgw/rgw_policy_s3.cc index f9d324fc36f6c..2919e392b4e83 100644 --- a/src/rgw/rgw_policy_s3.cc +++ b/src/rgw/rgw_policy_s3.cc @@ -248,7 +248,8 @@ int RGWPolicy::from_json(bufferlist& bl, string& err_msg) { JSONParser parser; - if (!parser.parse(bl)) { + // JSON coming in for Policies can include the NULL character, which breaks parsing: + if (!parser.parse(std::string_view(bl.c_str(), bl.length() - 1))) { err_msg = "Malformed JSON"; dout(0) << "malformed json" << dendl; return -EINVAL; diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h index a5e7bdbf56af9..a302257e428bc 100644 --- a/src/rgw/rgw_rest.h +++ b/src/rgw/rgw_rest.h @@ -62,7 +62,7 @@ std::tuple rgw_rest_get_json_input_keep_data(CephContext *cct, JSONParser parser; - if (!parser.parse(data)) { + if (!parser.parse(data.c_str(), data.length())) { return std::make_tuple(-EINVAL, std::move(data)); } diff --git a/src/rgw/rgw_rest_conn.h b/src/rgw/rgw_rest_conn.h index 13bc607731983..7abf86a3d3f09 100644 --- a/src/rgw/rgw_rest_conn.h +++ b/src/rgw/rgw_rest_conn.h @@ -17,7 +17,7 @@ template inline int parse_decode_json(T& t, bufferlist& bl) { JSONParser p; - if (!p.parse(bl)) { + if (!p.parse(bl.c_str(), bl.length())) { return -EINVAL; } diff --git a/src/rgw/rgw_rest_role.cc b/src/rgw/rgw_rest_role.cc index 7e924c640ffdd..a3733c175cc3c 100644 --- a/src/rgw/rgw_rest_role.cc +++ b/src/rgw/rgw_rest_role.cc @@ -449,7 +449,7 @@ int RGWModifyRoleTrustPolicy::init_processing(optional_yield y) } JSONParser p; - if (!p.parse(trust_policy)) { + if (!p.parse(trust_policy.c_str(), trust_policy.length())) { ldpp_dout(this, 20) << "ERROR: failed to parse assume role policy doc" << dendl; return -ERR_MALFORMED_DOC; } diff --git a/src/rgw/rgw_rest_sts.cc b/src/rgw/rgw_rest_sts.cc index 7b36511f0e46c..c0c6b5e89acd2 100644 --- a/src/rgw/rgw_rest_sts.cc +++ b/src/rgw/rgw_rest_sts.cc @@ -327,7 +327,7 @@ WebTokenEngine::get_cert_url(const string& iss, const DoutPrefixProvider *dpp, o ldpp_dout(dpp, 20) << "JSON Response is: " << openidc_resp.c_str() << dendl; JSONParser parser; - if (parser.parse(openidc_resp)) { + if (parser.parse(openidc_resp.c_str(), openidc_resp.length())) { JSONObj::data_val val; if (parser.get_data("jwks_uri", &val)) { cert_url = val.str.c_str(); @@ -364,7 +364,7 @@ WebTokenEngine::validate_signature(const DoutPrefixProvider* dpp, const jwt::dec ldpp_dout(dpp, 20) << "JSON Response is: " << cert_resp.c_str() << dendl; JSONParser parser; - if (parser.parse(cert_resp)) { + if (parser.parse(cert_resp.c_str(), cert_resp.length())) { JSONObj::data_val val; if (parser.get_data("keys", &val)) { if (val.str[0] == '[') { diff --git a/src/test/common/test_json_formatter.cc b/src/test/common/test_json_formatter.cc index 144a52ef524d0..f6de954274b69 100644 --- a/src/test/common/test_json_formatter.cc +++ b/src/test/common/test_json_formatter.cc @@ -155,7 +155,7 @@ TEST(formatter, parse_types) { buffer::list bl; bl.append(outstring); - EXPECT_TRUE(parser.parse(bl)); + EXPECT_TRUE(parser.parse(bl.c_str(), bl.length())); JSONObj *pgstat_obj = parser.find_obj("pg_stats"); EXPECT_TRUE(pgstat_obj); @@ -167,7 +167,7 @@ TEST(formatter, parse_types) { buffer::list bl; bl.append(json_input); - ASSERT_TRUE(parser.parse(bl)); + ASSERT_TRUE(parser.parse(bl.c_str(), bl.length())); JSONObjIter oi = parser.find_first();