From ae677264411f80a5587164c48a6a17390eaf72c9 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 26 Aug 2022 09:49:01 -0400 Subject: [PATCH] rgw: cloud sync: fix crash due to objs on cr stack Fixes: https://tracker.ceph.com/issues/57306 When passing objects that are declared on the stack (as ref / ptr), called cr can't access them (other than for initialization), as the yield destroys them. We now keep these objects as class members. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_sync_module_aws.cc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/rgw/rgw_sync_module_aws.cc b/src/rgw/rgw_sync_module_aws.cc index c7090e937f9..18aab89fe8a 100644 --- a/src/rgw/rgw_sync_module_aws.cc +++ b/src/rgw/rgw_sync_module_aws.cc @@ -1594,6 +1594,13 @@ class RGWAWSHandleRemoteObjCBCR: public RGWStatRemoteObjCBCR { } } result; + rgw_bucket target_bucket; + std::unique_ptr bucket; + std::unique_ptr src_obj; + std::unique_ptr dest_bucket; + std::unique_ptr dest_obj; + + public: RGWAWSHandleRemoteObjCBCR(RGWDataSyncCtx *_sc, rgw_bucket_sync_pipe& _sync_pipe, @@ -1672,16 +1679,14 @@ public: } yield { - rgw::sal::RadosBucket bucket(sync_env->store, src_bucket); - rgw::sal::RadosObject src_obj(sync_env->store, key, &bucket); + bucket.reset(new rgw::sal::RadosBucket(sync_env->store, src_bucket)); + src_obj.reset(new rgw::sal::RadosObject(sync_env->store, key, bucket.get())); /* init output */ - rgw_bucket target_bucket; target_bucket.name = target_bucket_name; /* this is only possible because we only use bucket name for uri resolution */ - rgw::sal::RadosBucket dest_bucket(sync_env->store, target_bucket); - rgw::sal::RadosObject dest_obj(sync_env->store, rgw_obj_key(target_obj_name), &dest_bucket); - + dest_bucket.reset(new rgw::sal::RadosBucket(sync_env->store, target_bucket)); + dest_obj.reset(new rgw::sal::RadosObject(sync_env->store, rgw_obj_key(target_obj_name), dest_bucket.get())); rgw_sync_aws_src_obj_properties src_properties; src_properties.mtime = mtime; @@ -1691,10 +1696,10 @@ public: src_properties.versioned_epoch = versioned_epoch; if (size < instance.conf.s3.multipart_sync_threshold) { - call(new RGWAWSStreamObjToCloudPlainCR(sc, source_conn, &src_obj, + call(new RGWAWSStreamObjToCloudPlainCR(sc, source_conn, src_obj.get(), src_properties, target, - &dest_obj)); + dest_obj.get())); } else { rgw_rest_obj rest_obj; rest_obj.init(key); @@ -1702,8 +1707,8 @@ public: ldpp_dout(dpp, 0) << "ERROR: failed to decode rest obj out of headers=" << headers << ", attrs=" << attrs << dendl; return set_cr_error(-EINVAL); } - call(new RGWAWSStreamObjToCloudMultipartCR(sc, sync_pipe, instance.conf, source_conn, &src_obj, - target, &dest_obj, size, src_properties, rest_obj)); + call(new RGWAWSStreamObjToCloudMultipartCR(sc, sync_pipe, instance.conf, source_conn, src_obj.get(), + target, dest_obj.get(), size, src_properties, rest_obj)); } } if (retcode < 0) {