]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: rgw_parse_url_bucket() rejects empty bucket names after 'tenant:' 50625/head
authorCasey Bodley <cbodley@redhat.com>
Tue, 22 Nov 2022 18:36:40 +0000 (13:36 -0500)
committerCasey Bodley <cbodley@redhat.com>
Wed, 22 Mar 2023 13:16:11 +0000 (09:16 -0400)
fail with ERR_INVALID_BUCKET_NAME if rgw_parse_url_bucket() finds a
'tenant:' but empty bucket name

Fixes: https://tracker.ceph.com/issues/58111
Signed-off-by: Casey Bodley <cbodley@redhat.com>
(cherry picked from commit 8f8bb1d2b743a2681d40cd8f25dedd0f221b49c7)

Conflicts:
src/rgw/rgw_bucket.cc: renamed to driver/rados/rgw_bucket

src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h
src/rgw/rgw_rest_s3.cc

index c0929422268406b9d2c9216d04176da85461e143..7013f28ec696e6bbfec478d79a83118f184a9c26 100644 (file)
@@ -141,8 +141,8 @@ std::string rgw_make_bucket_entry_name(const std::string& tenant_name,
  * Tenants are separated from buckets in URLs by a colon in S3.
  * This function is not to be used on Swift URLs, not even for COPY arguments.
  */
-void rgw_parse_url_bucket(const string &bucket, const string& auth_tenant,
-                          string &tenant_name, string &bucket_name) {
+int rgw_parse_url_bucket(const string &bucket, const string& auth_tenant,
+                         string &tenant_name, string &bucket_name) {
 
   int pos = bucket.find(':');
   if (pos >= 0) {
@@ -153,10 +153,14 @@ void rgw_parse_url_bucket(const string &bucket, const string& auth_tenant,
      */
     tenant_name = bucket.substr(0, pos);
     bucket_name = bucket.substr(pos + 1);
+    if (bucket_name.empty()) {
+      return -ERR_INVALID_BUCKET_NAME;
+    }
   } else {
     tenant_name = auth_tenant;
     bucket_name = bucket;
   }
+  return 0;
 }
 
 int rgw_bucket_parse_bucket_instance(const string& bucket_instance, string *bucket_name, string *bucket_id, int *shard_id)
index 090effd2858f51243361cb253f57a27512ac3f1a..bcddc7ae8fd0b996f41bc1270059d61fa8527a89 100644 (file)
@@ -47,9 +47,10 @@ extern int rgw_bucket_parse_bucket_key(CephContext *cct, const std::string& key,
 extern std::string rgw_make_bucket_entry_name(const std::string& tenant_name,
                                               const std::string& bucket_name);
 
-extern void rgw_parse_url_bucket(const std::string& bucket,
-                                 const std::string& auth_tenant,
-                                 std::string &tenant_name, std::string &bucket_name);
+[[nodiscard]] int rgw_parse_url_bucket(const std::string& bucket,
+                                       const std::string& auth_tenant,
+                                       std::string &tenant_name,
+                                       std::string &bucket_name);
 
 extern int rgw_chown_bucket_and_objects(rgw::sal::Store* store,
                                        rgw::sal::Bucket* bucket,
index c0afa4c3c3ea58c218d85e1aa9d9f89252e26a0e..f51c38df9054c2e4c0d736ce2540b27c68ca6e3f 100644 (file)
@@ -4871,9 +4871,11 @@ int RGWHandler_REST_S3::postauth_init(optional_yield y)
 {
   struct req_init_state *t = &s->init_state;
 
-  rgw_parse_url_bucket(t->url_bucket, s->user->get_tenant(),
-                     s->bucket_tenant, s->bucket_name);
-
+  int ret = rgw_parse_url_bucket(t->url_bucket, s->user->get_tenant(),
+                                 s->bucket_tenant, s->bucket_name);
+  if (ret) {
+    return ret;
+  }
   if (s->auth.identity->get_identity_type() == TYPE_ROLE) {
     s->bucket_tenant = s->auth.identity->get_role_tenant();
   }
@@ -4881,7 +4883,6 @@ int RGWHandler_REST_S3::postauth_init(optional_yield y)
   ldpp_dout(s, 10) << "s->object=" << s->object
            << " s->bucket=" << rgw_make_bucket_entry_name(s->bucket_tenant, s->bucket_name) << dendl;
 
-  int ret;
   ret = rgw_validate_tenant_name(s->bucket_tenant);
   if (ret)
     return ret;
@@ -4898,8 +4899,11 @@ int RGWHandler_REST_S3::postauth_init(optional_yield y)
     } else {
       auth_tenant = s->user->get_tenant();
     }
-    rgw_parse_url_bucket(t->src_bucket, auth_tenant,
-                       s->src_tenant_name, s->src_bucket_name);
+    ret = rgw_parse_url_bucket(t->src_bucket, auth_tenant,
+                               s->src_tenant_name, s->src_bucket_name);
+    if (ret) {
+      return ret;
+    }
     ret = rgw_validate_tenant_name(s->src_tenant_name);
     if (ret)
       return ret;