From d384b2b8e0ed670f229eb889a14f521fa8d194fc Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Wed, 25 May 2016 14:23:29 +0200 Subject: [PATCH] rgw: properly handle initial slashes in SLO's segment path. Fixes: http://tracker.ceph.com/issues/16015 Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_op.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 76a408cdcd2..77c958b3cb0 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1027,13 +1027,26 @@ int RGWGetObj::handle_slo_manifest(bufferlist& bl) for (const auto& entry : slo_info.entries) { const string& path = entry.path; - const size_t pos = path.find('/', 1); /* skip first / */ - if (pos == string::npos) { + + /* If the path starts with slashes, strip them all. */ + const size_t pos_init = path.find_first_not_of('/'); + /* According to the documentation of std::string::find following check + * is not necessary as we should get the std::string::npos propagation + * here. This might be true with the accuracy to implementation's bugs. + * See following question on SO: + * http://stackoverflow.com/questions/1011790/why-does-stdstring-findtext-stdstringnpos-not-return-npos + */ + if (pos_init == string::npos) { + return -EINVAL; + } + + const size_t pos_sep = path.find('/', pos_init); + if (pos_sep == string::npos) { return -EINVAL; } - string bucket_name = path.substr(1, pos - 1); - string obj_name = path.substr(pos + 1); + string bucket_name = path.substr(pos_init, pos_sep - pos_init); + string obj_name = path.substr(pos_sep + 1); rgw_bucket bucket; RGWAccessControlPolicy *bucket_policy; -- 2.47.3