]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: lc fix rgw crash when lc configuration xml not including ID 18534/head
authorEnming Zhang <enming.zhang@umcloud.com>
Wed, 25 Oct 2017 10:56:08 +0000 (18:56 +0800)
committerEnming Zhang <enming.zhang@umcloud.com>
Tue, 31 Oct 2017 03:10:00 +0000 (11:10 +0800)
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 <enming.zhang@umcloud.com>
src/rgw/rgw_lc_s3.cc
src/rgw/rgw_lc_s3.h

index e8a647f429b1c92c643232f9e66c9563afc8f6c3..b05b8a1ac0d1aaaaa25ca2568a3806de982a25b5 100644 (file)
@@ -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 << "<Rule>" ;
   out << "<ID>" << id << "</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) {
index bc2f29f61581b118a7c52d53a2cd0c1cb07c106c..10960c6365db574b8c826b3829e38f6418f45c39 100644 (file)
@@ -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<string, LCRule>::iterator iter;
     for (iter = rule_map.begin(); iter != rule_map.end(); ++iter) {
       LCRule_S3& rule = static_cast<LCRule_S3&>(iter->second);
-      rule.to_xml(cct, out);
+      rule.to_xml(out);
     }
     out << "</LifecycleConfiguration>";
   }