From: Yehuda Sadeh Date: Thu, 24 Jan 2019 01:22:25 +0000 (-0800) Subject: rgw: es: fix attrs trimming X-Git-Tag: v14.1.0~210^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9f8bb33fa7dd00a5c220710543618b6ad9e77dcc;p=ceph.git rgw: es: fix attrs trimming 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 --- diff --git a/src/rgw/rgw_sync_module_es.cc b/src/rgw/rgw_sync_module_es.cc index db75c986fa3..5cea97c3525 100644 --- a/src/rgw/rgw_sync_module_es.cc +++ b/src/rgw/rgw_sync_module_es.cc @@ -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))); } } }