Repository navigation
rgw: Check if HTTP_X_AMZ_COPY_SOURCE header is empty - #65159
Conversation
026beb9 to
e1243c8
Compare
| if (name_str[0] == '/') // trim leading slash | ||
| if (!name_str.empty() && name_str[0] == '/') // trim leading slash |
There was a problem hiding this comment.
thanks. https://en.cppreference.com/w/cpp/string/basic_string_view/remove_prefix does say that name_str.remove_prefix(1) is undefined behavior if name_str is empty, so this looks correct 👍
but ultimately an empty name_str should cause us to return false below:
pos = dec_src.find('/');
if (pos == string::npos)
return false;so i'd suggest that we instead add an early return for name_str.empty() before this line:
+ if (name_str.empty()) {
+ return false;
+ }
if (name_str[0] == '/') // trim leading slashdoes that look right to you?
| @@ -4995,7 +4995,7 @@ int RGWHandler_REST_S3::init(rgw::sal::Driver* driver, req_state *s, | |||
| s->has_acl_header = s->info.env->exists_prefix("HTTP_X_AMZ_GRANT"); | |||
|
|
|||
| const char *copy_source = s->info.env->get("HTTP_X_AMZ_COPY_SOURCE"); | |||
| if (copy_source && | |||
| if (copy_source && copy_source[0] != '\0' && | |||
There was a problem hiding this comment.
is this change necessary? if the client sends an empty x-amz-copy-source header, this function should still treat it as a copy request and catch the error from parse_copy_location() just below. but your change will cause us to skip this block and continue on with a null s->src_object. that might cause us to crash or misbehave later in the request processing
|
@Suyashd999 Did you get a chance to make the changes Casey requested? |
The issue was that the `HTTP_X_AMZ_COPY_SOURCE` header could be present but empty (i.e., an empty string rather than NULL). The code only checked if the pointer was not NULL, but didn't verify that the string had content. When an empty string was passed to RGWCopyObj::parse_copy_location(), it would eventually try to access name_str[0] on an empty string, causing a crash. Fixes: https://tracker.ceph.com/issues/72669 Signed-off-by: Suyash Dongre <[email protected]>
e1243c8 to
bef59f1
Compare
|
jenkins test api |
|
pr testing completed and approved by @ivancich. Please find the details : https://tracker.ceph.com/issues/73371 |
|
has anyone raised the issue of whitespaces such as " " ? I would suggest using boost::trim at least before the check? |
@mrwormhole will it be crashing the RGW? if so, please open a tracker for that |
The issue was that the
HTTP_X_AMZ_COPY_SOURCEheader could be present but empty (i.e., an empty string rather than NULL). The code only checked if the pointer was not NULL, but didn't verify that the string had content. When an empty string was passed to RGWCopyObj::parse_copy_location(), it would eventually try to access name_str[0] on an empty string, causing a crash.Fixes: https://tracker.ceph.com/issues/72669 (cbodley edited to fix the link)
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job Definition