]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Don't crash on copy when metadata directive not supplied 29500/head
authorAdam C. Emerson <aemerson@redhat.com>
Tue, 9 Jul 2019 21:34:51 +0000 (17:34 -0400)
committerPrashant D <pdhange@redhat.com>
Tue, 6 Aug 2019 00:58:28 +0000 (20:58 -0400)
Fixes: http://tracker.ceph.com/issues/40416
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
(cherry picked from commit d5a85e681f05f2b680bfe771ac16704b374218c7)

src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rest_s3.cc

index 9c6d06ac37db8230aee6ba113c9de3b5de78e514..652c1d7f1e0a5505c1cc506bf84758c1fdb4eeeb 100644 (file)
@@ -4612,7 +4612,9 @@ int RGWCopyObj::verify_permission()
   if (! s->auth.identity->is_admin_of(dest_policy.get_owner().get_id())){
     if (dest_iam_policy != boost::none) {
       rgw_add_to_iam_environment(s->env, "s3:x-amz-copy-source", copy_source);
-      rgw_add_to_iam_environment(s->env, "s3:x-amz-metadata-directive", md_directive);
+      if (md_directive)
+       rgw_add_to_iam_environment(s->env, "s3:x-amz-metadata-directive",
+                                  *md_directive);
 
       auto e = dest_iam_policy->eval(s->env, *s->auth.identity,
                                      rgw::IAM::s3PutObject,
index 21bc8c7a6fb9978f5fef27a106d13b1707cc253d..c51527b2cad6211f64e98993313ad2529541af02 100644 (file)
@@ -1286,8 +1286,10 @@ protected:
   const char *if_unmod;
   const char *if_match;
   const char *if_nomatch;
-  const char *copy_source = nullptr;
-  const char *md_directive = nullptr;
+  // Required or it is not a copy operation
+  std::string_view copy_source;
+  // Not actually required
+  std::optional<std::string_view> md_directive;
 
   off_t ofs;
   off_t len;
index bda05ba923a4320ff431a193bf465a7e7d1eb713..bc6033ce15e0d70f3008c096df61a5010f596d43 100644 (file)
@@ -2152,11 +2152,11 @@ int RGWCopyObj_ObjStore_S3::get_params()
   }
 
   copy_source = s->info.env->get("HTTP_X_AMZ_COPY_SOURCE");
-  md_directive = s->info.env->get("HTTP_X_AMZ_METADATA_DIRECTIVE");
-  if (md_directive) {
-    if (strcasecmp(md_directive, "COPY") == 0) {
+  auto tmp_md_d = s->info.env->get("HTTP_X_AMZ_METADATA_DIRECTIVE");
+  if (tmp_md_d) {
+    if (strcasecmp(tmp_md_d, "COPY") == 0) {
       attrs_mod = RGWRados::ATTRSMOD_NONE;
-    } else if (strcasecmp(md_directive, "REPLACE") == 0) {
+    } else if (strcasecmp(tmp_md_d, "REPLACE") == 0) {
       attrs_mod = RGWRados::ATTRSMOD_REPLACE;
     } else if (!source_zone.empty()) {
       attrs_mod = RGWRados::ATTRSMOD_NONE; // default for intra-zone_group copy
@@ -2165,6 +2165,7 @@ int RGWCopyObj_ObjStore_S3::get_params()
       ldout(s->cct, 0) << s->err.message << dendl;
       return -EINVAL;
     }
+    md_directive = tmp_md_d;
   }
 
   if (source_zone.empty() &&