Skip to content

Commit

Permalink
rgw: Swift API returns 400 Bad Request on too long container names.
Browse files Browse the repository at this point in the history
Fixes: http://tracker.ceph.com/issues/17935
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
  • Loading branch information
rzarzynski committed Aug 22, 2017
1 parent e851614 commit 1845e41
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/rgw/rgw_common.cc
Expand Up @@ -118,6 +118,7 @@ rgw_http_errors rgw_http_s3_errors({
rgw_http_errors rgw_http_swift_errors({
{ EACCES, {403, "AccessDenied" }},
{ EPERM, {401, "AccessDenied" }},
{ ENAMETOOLONG, {400, "Metadata name too long" }},
{ ERR_USER_SUSPENDED, {401, "UserSuspended" }},
{ ERR_INVALID_UTF8, {412, "Invalid UTF8" }},
{ ERR_BAD_URL, {412, "Bad URL" }},
Expand Down
22 changes: 17 additions & 5 deletions src/rgw/rgw_rest_swift.cc
Expand Up @@ -2,6 +2,7 @@
// vim: ts=8 sw=2 smarttab

#include <boost/algorithm/string/predicate.hpp>
#include <boost/format.hpp>
#include <boost/optional.hpp>
#include <boost/utility/in_place_factory.hpp>

Expand Down Expand Up @@ -2591,11 +2592,22 @@ int RGWHandler_REST_SWIFT::postauth_init()

int RGWHandler_REST_SWIFT::validate_bucket_name(const string& bucket)
{
int ret = RGWHandler_REST::validate_bucket_name(bucket);
if (ret < 0)
return ret;
const size_t len = bucket.size();

if (len > MAX_BUCKET_NAME_LEN) {
/* Bucket Name too long. Generate custom error message and bind it
* to an R-value reference. */
const auto msg = boost::str(
boost::format("Container name length of %lld longer than %lld")
% len % int(MAX_BUCKET_NAME_LEN));
set_req_state_err(s, ERR_INVALID_BUCKET_NAME, msg);
return -ERR_INVALID_BUCKET_NAME;
}

int len = bucket.size();
const auto ret = RGWHandler_REST::validate_bucket_name(bucket);
if (ret < 0) {
return ret;
}

if (len == 0)
return 0;
Expand All @@ -2608,7 +2620,7 @@ int RGWHandler_REST_SWIFT::validate_bucket_name(const string& bucket)

const char *s = bucket.c_str();

for (int i = 0; i < len; ++i, ++s) {
for (size_t i = 0; i < len; ++i, ++s) {
if (*(unsigned char *)s == 0xff)
return -ERR_INVALID_BUCKET_NAME;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_rest_swift.h
Expand Up @@ -381,7 +381,7 @@ class RGWHandler_REST_SWIFT : public RGWHandler_REST {
}
~RGWHandler_REST_SWIFT() override = default;

static int validate_bucket_name(const string& bucket);
int validate_bucket_name(const string& bucket);

int init(RGWRados *store, struct req_state *s, rgw::io::BasicClient *cio) override;
int authorize() override;
Expand Down

0 comments on commit 1845e41

Please sign in to comment.