diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-07-23 10:04:55 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-07-23 10:04:55 +0300 |
commit | 78c28187ffb8f6ae8aa0662e6be193d23ae7808b (patch) | |
tree | 437c9c562d04bc4c0c2bf42d3c0b2c9bd3feb8b1 | |
parent | 29ebc161e427e491706b874ecdb227dad77619d7 (diff) | |
download | mailutils-78c28187ffb8f6ae8aa0662e6be193d23ae7808b.tar.gz mailutils-78c28187ffb8f6ae8aa0662e6be193d23ae7808b.tar.bz2 |
Fixes in MIME structured header parser
* libmailutils/mime/mimehdr.c (parse_param): Allow for whitespace
surrounding =.
* libmailutils/tests/mimehdr.at: More tests
-rw-r--r-- | libmailutils/mime/mimehdr.c | 30 | ||||
-rw-r--r-- | libmailutils/tests/mimehdr.at | 17 |
2 files changed, 40 insertions, 7 deletions
diff --git a/libmailutils/mime/mimehdr.c b/libmailutils/mime/mimehdr.c index 6bbfcfdb9..ec883329b 100644 --- a/libmailutils/mime/mimehdr.c +++ b/libmailutils/mime/mimehdr.c @@ -309,12 +309,34 @@ parse_param (struct mu_wordsplit *ws, size_t *pi, mu_assoc_t assoc, return MU_ERR_PARSE; p = strchr (key, '='); - if (!p) - val = ""; - else + if (p) { *p++ = 0; - val = p; + if (*p) + { + /* key=val */ + val = p; + } + else if ((val = getword (ws, pi)) == NULL) + return MU_ERR_PARSE; + /* key= WSP val */ + } + else + { + p = getword (ws, pi); + if (p && p[0] == '=') + { + if (p[1]) + { + /* key WSP =val */ + val = p + 1; + } + else if ((val = getword (ws, pi)) == NULL) + return MU_ERR_PARSE; + /* key WSP = WSP val */ + } + else + return MU_ERR_PARSE; } klen = strlen (key); diff --git a/libmailutils/tests/mimehdr.at b/libmailutils/tests/mimehdr.at index 951a35a80..cef3a6e9b 100644 --- a/libmailutils/tests/mimehdr.at +++ b/libmailutils/tests/mimehdr.at @@ -259,21 +259,32 @@ MIMEHDR([missing parameters],[mimehdr13], [message ]) -MIMEHDR_FAIL([empty input],[mimehdr14], +MIMEHDR([surrounding whitespace],[mimehdr14], +[], +[text/plain ; charset = utf-8; param=foo ; p1 =bar ; p2= baz +], +[text/plain +charset=utf-8 +p1=bar +p2=baz +param=foo +]) + +MIMEHDR_FAIL([empty input],[mimehdr15], [], [], [], [mimehdr: mu_mime_header_parse() failed: Parse error ]) -MIMEHDR_FAIL([missing semicolon after type],[mimehdr15], +MIMEHDR_FAIL([missing semicolon after type],[mimehdr16], [], [message name="foo"], [], [mimehdr: mu_mime_header_parse() failed: Parse error ]) -MIMEHDR_FAIL([whitespace in type],[mimehdr16], +MIMEHDR_FAIL([whitespace in type],[mimehdr17], [], [TeX file/plain; name=foo], [], |