From: Yehuda Sadeh Date: Wed, 9 Jan 2019 03:40:46 +0000 (-0800) Subject: rgw: clean up generic attribute val X-Git-Tag: v14.1.0~314^2~12 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0e032311ad87b46adfab8967aa6af045579c3e9d;p=ceph.git rgw: clean up generic attribute val There are cases where we keep/kept attributes value with a null termination, which bufferlist.to_str() returns as part of the string and returned headers are broken. Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 1e6725e0c5e1..c620904b129d 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -290,7 +290,18 @@ int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs, if (aiter != rgw_to_http_attrs.end()) { if (response_attrs.count(aiter->second) == 0) { /* Was not already overridden by a response param. */ - response_attrs[aiter->second] = iter->second.to_str(); + + /* clean up attribute, we have cases where we kept extra null character + * at the end of the buffer, so bufferlist.to_str() won't work because + * it'll generate a string with that extra character + */ + auto& buf = iter->second; + const char *val = buf.c_str(); + size_t len = buf.length(); + while (len > 0 && !val[len - 1]) { + --len; + } + response_attrs[aiter->second] = string(val, len); } } else if (iter->first.compare(RGW_ATTR_CONTENT_TYPE) == 0) { /* Special handling for content_type. */