]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: properly handle initial slashes in SLO's segment path. 9544/head
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Wed, 25 May 2016 12:23:29 +0000 (14:23 +0200)
committerAbhishek Varshney <abhishek.varshney@flipkart.com>
Tue, 7 Jun 2016 13:15:08 +0000 (18:45 +0530)
Fixes: http://tracker.ceph.com/issues/16015
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
(cherry picked from commit d384b2b8e0ed670f229eb889a14f521fa8d194fc)

src/rgw/rgw_op.cc

index a2202caf07518f9733e9ca8c816c81ca6ad01c1b..3f9212a236c5e27bc561eddbd0c553203d9ff642 100644 (file)
@@ -1015,13 +1015,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;