From 2267b67279ee614d28a616b001ed2c5cfce44c33 Mon Sep 17 00:00:00 2001 From: Enming Zhang Date: Wed, 10 Jul 2019 00:48:57 -0700 Subject: [PATCH] rgw: fix checking index_doc_suffix when getting effective key Currently, if the index_doc_suffix is empty which is leaded by the IndexDocument field is not configurated or is set to empty string during enabling bucket website function, the rgw will crash when accessing the static website through the S3Website enabled RGW instance. In actually, we have add the necessary checking in the commit 355f392ad26631f44dac250296e96f421d86fb8f, but double checking in here is better. Signed-off-by: Enming Zhang (cherry picked from commit c96f415dafe176b1b8d10ff9456d13fb76c79baa) Conflicts: src/rgw/rgw_rest_s3.cc - ldpp_dout --- src/rgw/rgw_rest_s3.cc | 7 +++++++ src/rgw/rgw_website.cc | 7 ++++++- src/rgw/rgw_website.h | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index b48f93685507d..b0e36dec5d8e5 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3610,6 +3610,13 @@ int RGWHandler_REST_S3Website::retarget(RGWOp* op, RGWOp** new_op) { rgw_obj_key new_obj; s->bucket_info.website_conf.get_effective_key(s->object.name, &new_obj.name, web_dir()); + bool get_res = s->bucket_info.website_conf.get_effective_key(s->object.name, &new_obj.name, web_dir()); + if (!get_res) { + s->err.message = "The IndexDocument Suffix is not configurated or not well formed!"; + ldout(s->cct, 5) << s->err.message << dendl; + return -EINVAL; + } + ldout(s->cct, 10) << "retarget get_effective_key " << s->object << " -> " << new_obj << dendl; diff --git a/src/rgw/rgw_website.cc b/src/rgw/rgw_website.cc index 69599e60bdf76..55c512b7e32f2 100644 --- a/src/rgw/rgw_website.cc +++ b/src/rgw/rgw_website.cc @@ -105,8 +105,11 @@ bool RGWBucketWebsiteConf::should_redirect(const string& key, const int http_err return true; } -void RGWBucketWebsiteConf::get_effective_key(const string& key, string *effective_key, bool is_file) const +bool RGWBucketWebsiteConf::get_effective_key(const string& key, string *effective_key, bool is_file) const { + if (index_doc_suffix.empty()) { + return false; + } if (key.empty()) { *effective_key = index_doc_suffix; @@ -117,4 +120,6 @@ void RGWBucketWebsiteConf::get_effective_key(const string& key, string *effectiv } else { *effective_key = key; } + + return true; } diff --git a/src/rgw/rgw_website.h b/src/rgw/rgw_website.h index 68f41018420f7..d6b6842ddb972 100644 --- a/src/rgw/rgw_website.h +++ b/src/rgw/rgw_website.h @@ -224,7 +224,7 @@ struct RGWBucketWebsiteConf const int http_error_code, RGWBWRoutingRule *redirect); - void get_effective_key(const std::string& key, + bool get_effective_key(const std::string& key, std::string *effective_key, bool is_file) const; const std::string& get_index_doc() const { -- 2.39.5