Skip to content

Commit

Permalink
rgw: fix if-match conditions should always be unquoted
Browse files Browse the repository at this point in the history
Signed-off-by: Damian Peckett <damian@pecke.tt>
  • Loading branch information
dpeckett committed Feb 14, 2024
1 parent 8259f75 commit 0ae123d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
34 changes: 20 additions & 14 deletions src/rgw/driver/posix/rgw_sal_posix.cc
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/rgw/driver/rados/rgw_rados.cc
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 0ae123d

Please sign in to comment.