]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: clean up generic attribute val
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 9 Jan 2019 03:40:46 +0000 (19:40 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Wed, 9 Jan 2019 21:23:45 +0000 (13:23 -0800)
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 <yehuda@redhat.com>
src/rgw/rgw_rest_s3.cc

index 1e6725e0c5e1b9ea13457a2d0fc66020c75bdb53..c620904b129dcc1a2bbf9b3927c5b2aa520464d0 100644 (file)
@@ -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. */