From e70e1a7d54c73c9f76794dd43c0cbdd48f3549e6 Mon Sep 17 00:00:00 2001 From: Vedansh Bhartia Date: Thu, 18 May 2023 13:28:20 +0530 Subject: [PATCH] rgw: modify RGWRados::cls_bucket_list_ordered to store dirent key before move There was a use after move issue in RGWRados::cls_bucket_list_ordered where dirent.key might be logged after it has been moved. This is fixed by copying the key before the move. Signed-off-by: Vedansh Bhartia --- src/rgw/driver/rados/rgw_rados.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rgw/driver/rados/rgw_rados.cc b/src/rgw/driver/rados/rgw_rados.cc index c71848bbfd0..e6f2c836cf0 100644 --- a/src/rgw/driver/rados/rgw_rados.cc +++ b/src/rgw/driver/rados/rgw_rados.cc @@ -8866,10 +8866,12 @@ int RGWRados::cls_bucket_list_ordered(const DoutPrefixProvider *dpp, r = 0; } + const cls_rgw_obj_key dirent_key = dirent.key; + // at this point either r >= 0 or r == -ENOENT if (r >= 0) { // i.e., if r != -ENOENT ldpp_dout(dpp, 10) << __func__ << ": got " << - dirent.key << dendl; + dirent_key << dendl; auto [it, inserted] = m.insert_or_assign(name, std::move(dirent)); last_entry_visited = &it->second; @@ -8910,7 +8912,7 @@ int RGWRados::cls_bucket_list_ordered(const DoutPrefixProvider *dpp, // fewer than what was requested ldpp_dout(dpp, 10) << __func__ << ": stopped accumulating results at count=" << count << - ", dirent=\"" << dirent.key << + ", dirent=\"" << dirent_key << "\", because its shard is truncated and exhausted" << dendl; break; } -- 2.39.5