From: Enming Zhang Date: Wed, 25 Oct 2017 10:56:08 +0000 (+0800) Subject: rgw: lc fix rgw crash when lc configuration xml not including ID X-Git-Tag: v12.2.3~212^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=03d1cd996cf189d10a23c839aead4075cbdb888f;p=ceph.git rgw: lc fix rgw crash when lc configuration xml not including ID When a putting lc config request does not include an ID tag in lc configuration xml, RGW should generate a random ID for the lc configuration. At present RGW will crash when generate a random ID for lc configuration. Fixes: http://tracker.ceph.com/issues/21980 Signed-off-by: Enming Zhang (cherry picked from commit 3d2f63de494f8cd065d3af3cfa49e111a294622c) --- diff --git a/src/rgw/rgw_lc_s3.cc b/src/rgw/rgw_lc_s3.cc index b03c4c32b9e..97a29342d11 100644 --- a/src/rgw/rgw_lc_s3.cc +++ b/src/rgw/rgw_lc_s3.cc @@ -87,7 +87,7 @@ bool LCRule_S3::xml_end(const char *el) { if (lc_id){ id = lc_id->get_data(); } else { - gen_rand_alphanumeric_lower(nullptr, &id, LC_ID_LENGTH); + gen_rand_alphanumeric_lower(cct, &id, LC_ID_LENGTH); } @@ -149,7 +149,7 @@ bool LCRule_S3::xml_end(const char *el) { return true; } -void LCRule_S3::to_xml(CephContext *cct, ostream& out) { +void LCRule_S3::to_xml(ostream& out) { out << "" ; out << "" << id << ""; if (!filter.empty()) { @@ -208,7 +208,7 @@ XMLObj *RGWLCXMLParser_S3::alloc_obj(const char *el) if (strcmp(el, "LifecycleConfiguration") == 0) { obj = new RGWLifecycleConfiguration_S3(cct); } else if (strcmp(el, "Rule") == 0) { - obj = new LCRule_S3(); + obj = new LCRule_S3(cct); } else if (strcmp(el, "ID") == 0) { obj = new LCID_S3(); } else if (strcmp(el, "Prefix") == 0) { diff --git a/src/rgw/rgw_lc_s3.h b/src/rgw/rgw_lc_s3.h index 7ff1bf71ba5..e792b97f6ae 100644 --- a/src/rgw/rgw_lc_s3.h +++ b/src/rgw/rgw_lc_s3.h @@ -159,11 +159,14 @@ public: class LCRule_S3 : public LCRule, public XMLObj { +private: + CephContext *cct; public: - LCRule_S3() {} + LCRule_S3(): cct(nullptr) {} + LCRule_S3(CephContext *_cct): cct(_cct) {} ~LCRule_S3() override {} - void to_xml(CephContext *cct, ostream& out); + void to_xml(ostream& out); bool xml_end(const char *el) override; bool xml_start(const char *el, const char **attr); void dump_xml(Formatter *f) const { @@ -192,6 +195,10 @@ public: f->close_section(); // Rule } + + void set_ctx(CephContext *ctx) { + cct = ctx; + } }; class RGWLCXMLParser_S3 : public RGWXMLParser @@ -217,7 +224,7 @@ public: multimap::iterator iter; for (iter = rule_map.begin(); iter != rule_map.end(); ++iter) { LCRule_S3& rule = static_cast(iter->second); - rule.to_xml(cct, out); + rule.to_xml(out); } out << ""; }