diff options
author | Patrick Monnerat <patrick@monnerat.net> | 2020-04-18 16:50:20 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2020-04-19 20:52:48 +0200 |
commit | d7471c136901e1955547a20d7bfa126d47d81b56 (patch) | |
tree | 2e0d68157313e764482a187b7b48379ffe09a538 /lib | |
parent | 7e53974603079a9522acdb10f3b4de499ffa6e4d (diff) | |
download | curl-d7471c136901e1955547a20d7bfa126d47d81b56.tar.gz |
mime: properly check Content-Type even if it has parameters
New test 669 checks this fix is effective.
Fixes #5256
Closes #5258
Reported-by: thanhchungbtc on github
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mime.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/mime.c b/lib/mime.c index b72732310..e13d92e94 100644 --- a/lib/mime.c +++ b/lib/mime.c @@ -1778,6 +1778,23 @@ const char *Curl_mime_contenttype(const char *filename) return NULL; } +static bool content_type_match(const char *contenttype, const char *target) +{ + size_t len = strlen(target); + + if(contenttype && strncasecompare(contenttype, target, len)) + switch(contenttype[len]) { + case '\0': + case '\t': + case '\r': + case '\n': + case ' ': + case ';': + return TRUE; + } + return FALSE; +} + CURLcode Curl_mime_prepare_headers(curl_mimepart *part, const char *contenttype, const char *disposition, @@ -1829,7 +1846,7 @@ CURLcode Curl_mime_prepare_headers(curl_mimepart *part, boundary = mime->boundary; } else if(contenttype && !customct && - strcasecompare(contenttype, "text/plain")) + content_type_match(contenttype, "text/plain")) if(strategy == MIMESTRATEGY_MAIL || !part->filename) contenttype = NULL; @@ -1905,7 +1922,7 @@ CURLcode Curl_mime_prepare_headers(curl_mimepart *part, curl_mimepart *subpart; disposition = NULL; - if(strcasecompare(contenttype, "multipart/form-data")) + if(content_type_match(contenttype, "multipart/form-data")) disposition = "form-data"; for(subpart = mime->firstpart; subpart; subpart = subpart->nextpart) { ret = Curl_mime_prepare_headers(subpart, NULL, disposition, strategy); |