From: Matt Benjamin Date: Tue, 15 Sep 2020 12:55:59 +0000 (-0400) Subject: rgwlc: fix clause counting in LCFilter_S3::decode_xml() X-Git-Tag: v16.1.0~692^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a358e4b8ab7860a78e141636449d427f0424d220;p=ceph.git rgwlc: fix clause counting in LCFilter_S3::decode_xml() The logic is not a structural parse, so remove the unreliable logic to match And to Filter clauses. Accept any number of tags (including 1) after Prefix. Empty Filter is allowed: https://docs.aws.amazon.com/AmazonS3/latest/dev/intro-lifecycle-rules.html Fixes: https://tracker.ceph.com/issues/47472 Signed-off-by: Matt Benjamin --- diff --git a/src/rgw/rgw_lc.h b/src/rgw/rgw_lc.h index 7ab3296e995d..b0e87efba76c 100644 --- a/src/rgw/rgw_lc.h +++ b/src/rgw/rgw_lc.h @@ -184,9 +184,6 @@ class LCFilter bool has_multi_condition() const { if (obj_tags.count() > 1) return true; - else if (has_prefix() && has_tags()) - return true; - return false; } diff --git a/src/rgw/rgw_lc_s3.cc b/src/rgw/rgw_lc_s3.cc index 712a6ed4dad0..cba2b00c0f86 100644 --- a/src/rgw/rgw_lc_s3.cc +++ b/src/rgw/rgw_lc_s3.cc @@ -128,20 +128,21 @@ void LCFilter_S3::dump_xml(Formatter *f) const void LCFilter_S3::decode_xml(XMLObj *obj) { + /* + * The prior logic here looked for an And element, but did not + * structurally parse the Filter clause (and incorrectly rejected + * the base case where a Prefix and one Tag were supplied). It + * could not reject generally malformed Filter syntax. + * + * Empty filters are allowed: + * https://docs.aws.amazon.com/AmazonS3/latest/dev/intro-lifecycle-rules.html + */ XMLObj *o = obj->find_first("And"); - bool single_cond = false; - int num_conditions = 0; - // If there is an AND condition, every tag is a child of and - // else we only support single conditions and return false if we see multiple - if (o == nullptr){ o = obj; - single_cond = true; } RGWXMLDecoder::decode_xml("Prefix", prefix, o); - if (!prefix.empty()) - num_conditions++; auto tags_iter = o->find("Tag"); obj_tags.clear(); while (auto tag_xml =tags_iter.get_next()){ @@ -149,11 +150,6 @@ void LCFilter_S3::decode_xml(XMLObj *obj) RGWXMLDecoder::decode_xml("Key", _key, tag_xml); RGWXMLDecoder::decode_xml("Value", _val, tag_xml); obj_tags.emplace_tag(std::move(_key), std::move(_val)); - num_conditions++; - } - - if (single_cond && num_conditions > 1) { - throw RGWXMLDecoder::err("Bad filter: badly formed multiple conditions"); } }