From 537e5493fb7de65251cb4b55f3548b290b5704fa Mon Sep 17 00:00:00 2001 From: "Javier M. Mellid" Date: Thu, 5 Nov 2015 11:54:43 +0100 Subject: [PATCH] Revert "rgw: avoid re-encoding already encoded query strings in AWS4 auth" Signed-off-by: Javier M. Mellid --- src/rgw/rgw_common.cc | 19 ++++++------------- src/rgw/rgw_rest_s3.cc | 8 ++++---- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index ea2b2803c5b..a177fc4f14f 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -974,23 +974,16 @@ static bool char_needs_url_encoding(char c) return false; } -void url_encode(const string& src, string& dst, bool in_query) +void url_encode(const string& src, string& dst) { const char *p = src.c_str(); for (unsigned i = 0; i < src.size(); i++, p++) { - if (*p == '%' && in_query && (i + 2) < src.size()) { - /* keep %AB as it is */ - dst.append(p, 3); - i += 2; - p += 2; - } else { - if (char_needs_url_encoding(*p)) { - escape_char(*p, dst); - continue; - } - - dst.append(p, 1); + if (char_needs_url_encoding(*p)) { + escape_char(*p, dst); + continue; } + + dst.append(p, 1); } } diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 75342e2a6b6..b9025bf5434 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -2982,10 +2982,10 @@ int RGW_Auth_S3::authorize_v4(RGWRados *store, struct req_state *s) getline(kv, key, '='); getline(kv, val, '='); if (!using_qs || key != "X-Amz-Signature") { - string key_enc, val_enc; - url_encode(key, key_enc, true); - url_encode(val, val_enc, true); - canonical_qs_map[key_enc] = val_enc; + string key_enc, val_enc; + url_encode(key, key_enc); + url_encode(val, val_enc); + canonical_qs_map[key_enc] = val_enc; } }