diff --git a/src/rgw/driver/posix/rgw_sal_posix.cc b/src/rgw/driver/posix/rgw_sal_posix.cc index 8ca6a09275bd5..170e086f9310f 100644 --- a/src/rgw/driver/posix/rgw_sal_posix.cc +++ b/src/rgw/driver/posix/rgw_sal_posix.cc @@ -2817,17 +2817,19 @@ int POSIXMultipartWriter::complete(size_t accounted_size, const std::string& eta POSIXUploadPartInfo info; if (if_match) { - if (strcmp(if_match, "*") == 0) { + std::string if_match_str = rgw_string_unquote(if_match); + if (if_match_str == "*") { // test the object is existing if (!obj->exists(dpp)) { return -ERR_PRECONDITION_FAILED; } } else { - bufferlist bl; - if (!get_attr(obj->get_attrs(), RGW_ATTR_ETAG, bl)) { + bufferlist etag_bl; + if (!get_attr(obj->get_attrs(), RGW_ATTR_ETAG, etag_bl)) { return -ERR_PRECONDITION_FAILED; } - if (strncmp(if_match, bl.c_str(), bl.length()) != 0) { + ldpp_dout(dpp, 10) << "If-Match: " << if_match_str << " ETAG: " << etag_bl.c_str() << dendl; + if (if_match_str.compare(0, etag_bl.length(), etag_bl.c_str(), etag_bl.length()) != 0) { return -ERR_PRECONDITION_FAILED; } } @@ -2884,33 +2886,37 @@ int POSIXAtomicWriter::complete(size_t accounted_size, const std::string& etag, int ret; if (if_match) { - if (strcmp(if_match, "*") == 0) { + std::string if_match_str = rgw_string_unquote(if_match); + if (if_match_str == "*") { // test the object is existing if (!obj.exists(dpp)) { - return -ERR_PRECONDITION_FAILED; + return -ERR_PRECONDITION_FAILED; } } else { - bufferlist bl; - if (!get_attr(obj.get_attrs(), RGW_ATTR_ETAG, bl)) { + bufferlist etag_bl; + if (!get_attr(obj.get_attrs(), RGW_ATTR_ETAG, etag_bl)) { return -ERR_PRECONDITION_FAILED; } - if (strncmp(if_match, bl.c_str(), bl.length()) != 0) { + ldpp_dout(dpp, 10) << "If-Match: " << if_match_str << " ETAG: " << etag_bl.c_str() << dendl; + if (if_match_str.compare(0, etag_bl.length(), etag_bl.c_str(), etag_bl.length()) != 0) { return -ERR_PRECONDITION_FAILED; } } } if (if_nomatch) { - if (strcmp(if_nomatch, "*") == 0) { + std::string if_nomatch_str = rgw_string_unquote(if_nomatch); + if (if_nomatch_str == "*") { // test the object is not existing if (obj.exists(dpp)) { - return -ERR_PRECONDITION_FAILED; + return -ERR_PRECONDITION_FAILED; } } else { - bufferlist bl; - if (!get_attr(obj.get_attrs(), RGW_ATTR_ETAG, bl)) { + bufferlist etag_bl; + if (!get_attr(obj.get_attrs(), RGW_ATTR_ETAG, etag_bl)) { return -ERR_PRECONDITION_FAILED; } - if (strncmp(if_nomatch, bl.c_str(), bl.length()) == 0) { + ldpp_dout(dpp, 10) << "ETag: " << std::string(etag_bl.c_str(), etag_bl.length()) << " " << " If-NoMatch: " << if_nomatch_str << dendl; + if (if_nomatch_str.compare(0, etag_bl.length(), etag_bl.c_str(), etag_bl.length()) == 0) { return -ERR_PRECONDITION_FAILED; } } diff --git a/src/rgw/driver/rados/rgw_rados.cc b/src/rgw/driver/rados/rgw_rados.cc index 7925cddf86fc1..ac6f65d1e9100 100644 --- a/src/rgw/driver/rados/rgw_rados.cc +++ b/src/rgw/driver/rados/rgw_rados.cc @@ -6353,15 +6353,19 @@ int RGWRados::Object::prepare_atomic_modification(const DoutPrefixProvider *dpp, } if (if_match) { - if (strcmp(if_match, "*") == 0) { + std::string if_match_str = rgw_string_unquote(if_match); + if (if_match_str == "*") { // test the object is existing if (!state->exists) { return -ERR_PRECONDITION_FAILED; } } else { - bufferlist bl; - if (!state->get_attr(RGW_ATTR_ETAG, bl) || - strncmp(if_match, bl.c_str(), bl.length()) != 0) { + bufferlist etag_bl; + if (!state->get_attr(RGW_ATTR_ETAG, etag_bl)) { + return -ERR_PRECONDITION_FAILED; + } + ldpp_dout(dpp, 10) << "If-Match: " << if_match_str << " ETAG: " << etag_bl.c_str() << dendl; + if (if_match_str.compare(0, etag_bl.length(), etag_bl.c_str(), etag_bl.length()) != 0) { return -ERR_PRECONDITION_FAILED; } }