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: v13.0.1~322^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3d2f63de494f8cd065d3af3cfa49e111a294622c;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 --- diff --git a/src/rgw/rgw_lc_s3.cc b/src/rgw/rgw_lc_s3.cc index e8a647f429b1..b05b8a1ac0d1 100644 --- a/src/rgw/rgw_lc_s3.cc +++ b/src/rgw/rgw_lc_s3.cc @@ -122,7 +122,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); } @@ -182,7 +182,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()) { @@ -243,7 +243,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 bc2f29f61581..10960c6365db 100644 --- a/src/rgw/rgw_lc_s3.h +++ b/src/rgw/rgw_lc_s3.h @@ -185,11 +185,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 { @@ -218,6 +221,10 @@ public: f->close_section(); // Rule } + + void set_ctx(CephContext *ctx) { + cct = ctx; + } }; class RGWLCXMLParser_S3 : public RGWXMLParser @@ -243,7 +250,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 << ""; }