From: Matt Benjamin Date: Wed, 14 Aug 2019 18:11:16 +0000 (-0400) Subject: rgw_file: readdir: do not construct markers w/leading '/' X-Git-Tag: v13.2.7~111^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=274d798b75079f23a6616e07cecb0b45067743d6;p=ceph.git 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) --- diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index eade60cff8f6..1cf7fbd2cec0 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -486,17 +486,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; } @@ -1422,8 +1422,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), "", ""}; } }