-
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
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') || (!isxdigit(*(p+1))) || (*(p+2) == '\0') || (!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,9 @@ 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 */ | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Comment on lines
+418
to
421
|
||||||||||||||||||||
| 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.
If the quoted value runs to the end of the string without a closing quote, this now silently accepts the header and finishes parsing with
pat\0. That’s safer than the previous OOB, but it likely violates the expected grammar for quoted parameters and can lead to inconsistent parsing/validation. Consider treating a missing closing quote as an error (e.g., return a specific negative code and/or setm_flag_invalid_quoting) instead of accepting it as valid.