-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: buffer overflow in multipart body proc #3546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3/master
Are you sure you want to change the base?
Changes from all commits
164de0f
b9fb213
f9248f9
9b33b2e
3b8b094
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -362,11 +362,11 @@ int Multipart::parse_content_disposition(const char *c_d_value, int offset) { | |||||||||||||||||||
| const char* start_of_filename = p; | ||||||||||||||||||||
| while ((*p != '\0') && (*p != ';')) { | ||||||||||||||||||||
| if (*p == '%') { | ||||||||||||||||||||
| if ((*(p+1) == '\0') || (!isxdigit(*(p+1))) || (!isxdigit(*(p+2)))) { | ||||||||||||||||||||
| if ((*(p+1) == '\0') || (*(p+2) == '\0') || (!isxdigit(static_cast<unsigned char>(*(p+1)))) || (!isxdigit(static_cast<unsigned char>(*(p+2))))) { | ||||||||||||||||||||
| return -18; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| p += 3; | ||||||||||||||||||||
| } else if (isalnum(*p) || strchr(attr_char_special, *p)) { | ||||||||||||||||||||
| } else if (isalnum(static_cast<unsigned char>(*p)) || strchr(attr_char_special, *p)) { | ||||||||||||||||||||
| p++; | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| return -19; | ||||||||||||||||||||
|
|
@@ -415,7 +415,12 @@ int Multipart::parse_content_disposition(const char *c_d_value, int offset) { | |||||||||||||||||||
| value.append((p++), 1); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| p++; /* go over the quote at the end */ | ||||||||||||||||||||
| if (*p == quote) { | ||||||||||||||||||||
| p++; /* go over the quote at the end */ | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| m_flag_invalid_quoting = 1; | ||||||||||||||||||||
| return -15; /* closing quote not found */ | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Comment on lines
+418
to
424
|
||||||||||||||||||||
| if (*p == quote) { | |
| p++; /* go over the quote at the end */ | |
| } | |
| if (*p == '\0') { | |
| /* missing terminating quote */ | |
| return -7; | |
| } | |
| p++; /* go over the quote at the end */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is a valid case, multipart header can contain urlencoded text, but the parser's task process it as is.
This suggestion removes that very important condition, I'm afraid that could make the parser wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only get here if a opening quote was observed, so a closing quote is expected. If the closing quote is URL encoded, then that looks like an evasion attempt. If the opening quote is also URL encoded, we won't end up here anyway (I think), so I think it's valid to say that the quote is missing.
I don't think we should set invalid_quoting in this case, the semantics are different.
I don't understand what difference it makes for you whether the return value is -7 or -15. The previous suggestion would behave the same, just with a different return code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here we should split up the suggestions into two parts:
- handling url-encoded characters
- handling missing quote at the end
First item: not relevant, the parser does not handle the url encoded quotes at all, this is why I wrote that the suggestion from Copilot is not a valid case.
Second: the missing quote is handled correctly with this, I added a new test case; I checked this test without this modification, which was failed.
I don't understand what difference it makes for you whether the return value is -7 or -15. The previous suggestion would behave the same, just with a different return code.
I think this is why we shouldn't change anything here 😃.
Uh oh!
There was an error while loading. Please reload this page.