From 57a9ac8c6db747ad8812b9cdf0434cf84c067049 Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Wed, 14 Aug 2019 14:11:16 -0400 Subject: [PATCH] rgw_file: readdir: do not construct markers w/leading '/' This case arises when listing the top directory of a bucket, and, with proper continued enumeration, would generate a non-terminating loop if a directory contained names which sort lexically before '/'. Fixes: https://tracker.ceph.com/issues/41252 Signed-off-by: Matt Benjamin (cherry picked from commit ca546fc53e5111052cbd7da35cb3105dde9b8bd1) --- src/rgw/rgw_file.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index 46623ecb4b0f6..91308140c1ee4 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -499,17 +499,17 @@ namespace rgw { reserve += (1 + tfh->object_name().length()); tfh = tfh->parent; } - bool first = true; + int pos = 1; path.reserve(reserve); for (auto& s : boost::adaptors::reverse(segments)) { - if (! first) + if (pos > 1) { path += "/"; - else { + } else { if (!omit_bucket && (path.front() != '/')) // pretty-print path += "/"; - first = false; } path += *s; + ++pos; } return path; } @@ -1453,8 +1453,9 @@ public: const char* mk = get(offset); if (mk) { std::string tmark{rgw_fh->relative_object_name()}; - tmark += "/"; - tmark += mk; + if (tmark.length() > 0) + tmark += "/"; + tmark += mk; marker = rgw_obj_key{std::move(tmark), "", ""}; } } -- 2.39.5