Skip to content
Snippets Groups Projects
Commit 1f528dad authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Improved parsing of "charset" parameter in MIME Content-Type header.

In Issue #177, the reported problem message header was "Content-Type: text/plain; charset=utf-8; format=flowed"
The fact that the "charset" value was not quoted and not space delimited means the charset would have been parsed as "utf-8;", which would not provide an exact match (against "utf-8") in smb_msg_is_utf8() and thus the message body would not be considered to be utf-8 encoded.

The solution is to terminate the "charset" parameter value at the semicolon, if it exists, and the value was not quoted.

Also, for good measure, only search for " charset" or ";charset" to avoid false-positive parameter matches,  like "notcharset".
parent 41e1bfb8
No related branches found
No related tags found
No related merge requests found
......@@ -367,15 +367,22 @@ void SMBCALL smb_parse_content_type(const char* content_type, char** subtype, ch
*tp = 0;
}
}
if(charset != NULL && (p = strcasestr(p, "charset=")) != NULL) {
p += 8;
if(*p == '"')
if(charset != NULL && ((p = strcasestr(p, " charset=")) != NULL || (p = strcasestr(p, ";charset=")) != NULL)) {
BOOL quoted = FALSE;
p += 9;
if(*p == '"') {
quoted = TRUE;
p++;
}
char* tp = p;
FIND_WHITESPACE(tp);
*tp = 0;
tp = p;
FIND_CHAR(tp, '"');
if(quoted) {
FIND_CHAR(tp, '"');
} else {
FIND_CHAR(tp, ';');
}
*tp = 0;
*charset = strdup(p);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment