]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: es: fix attrs trimming
authorYehuda Sadeh <yehuda@redhat.com>
Thu, 24 Jan 2019 01:22:25 +0000 (17:22 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 25 Jan 2019 23:45:57 +0000 (15:45 -0800)
Fixes: http://tracker.ceph.com/issues/38028
Since we don't necessarily keep attr headers with null terminating char,
need to be careful when trying to trim them.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_sync_module_es.cc

index db75c986fa31933119945c30b7bef2ace38acd5a..5cea97c3525ec1615e8ea31cdbb256244c02b584 100644 (file)
@@ -362,6 +362,16 @@ static bool is_sys_attr(const std::string& attr_name){
   return std::find(rgw_sys_attrs.begin(), rgw_sys_attrs.end(), attr_name) != rgw_sys_attrs.end();
 }
 
+static size_t attr_len(const bufferlist& val)
+{
+  size_t len = val.length();
+  if (len && val[len - 1] == '\0') {
+    --len;
+  }
+
+  return len;
+}
+
 struct es_obj_metadata {
   CephContext *cct;
   ElasticConfigRef es_conf;
@@ -394,7 +404,7 @@ struct es_obj_metadata {
 
       if (boost::algorithm::starts_with(attr_name, RGW_ATTR_META_PREFIX)) {
         custom_meta.emplace(attr_name.substr(sizeof(RGW_ATTR_META_PREFIX) - 1),
-                            string(val.c_str(), (val.length() > 0 ? val.length() - 1 : 0)));
+                            string(val.c_str(), attr_len(val)));
         continue;
       }
 
@@ -452,7 +462,7 @@ struct es_obj_metadata {
       } else {
         if (!is_sys_attr(attr_name)) {
           out_attrs.emplace(attr_name.substr(sizeof(RGW_ATTR_PREFIX) - 1),
-                            std::string(val.c_str(), (val.length() > 0 ? val.length() - 1 : 0)));
+                            std::string(val.c_str(), attr_len(val)));
         }
       }
     }