From ea2db1411c6243a527882942fe8b02d0af9a9440 Mon Sep 17 00:00:00 2001 From: "J. Eric Ivancich" Date: Thu, 23 Dec 2021 16:25:26 -0500 Subject: [PATCH] rgw: `radosgw-admin bucket stats` on indexless bucket crashes The new bucket layout code didn't check whether the bucket is indexless prior to asking for the last entry in the layout log. The layout log appears to be empty for an indexless bucket, thereby putting the runtime in an undefined state that later may cause a failed assertion. This commit adds two safety checks and returns -EINVAL along with putting useful information on stderr when either stats are requested on an indexless bucket or when the layout log is empty. Signed-off-by: J. Eric Ivancich --- src/rgw/rgw_bucket.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index ae326714cc434..8f194840dea3a 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -1045,10 +1045,25 @@ static int bucket_stats(rgw::sal::Store* store, return ret; } - string bucket_ver, master_ver; - string max_marker; + if (bucket->get_info().layout.current_index.layout.type == + rgw::BucketIndexType::Indexless) { + cerr << "error, indexless buckets do not maintain stats; bucket=" << + bucket->get_name() << std::endl; + return -EINVAL; + } + + if (bucket->get_info().layout.logs.empty()) { + // this check may be redundant with the previous check of + // layout.type; calling back() on an empty vector produces + // undefined behavior + cerr << "error, layout log list is empty; bucket=" << bucket->get_name() << + std::endl; + return -EINVAL; + } const auto& latest_log = bucket->get_info().layout.logs.back(); const auto& index = log_to_index_layout(latest_log); + std::string bucket_ver, master_ver; + std::string max_marker; ret = bucket->read_stats(dpp, index, RGW_NO_SHARD, &bucket_ver, &master_ver, stats, &max_marker); if (ret < 0) { cerr << "error getting bucket stats bucket=" << bucket->get_name() << " ret=" << ret << std::endl; -- 2.39.5