From 820ebcf4f8374f6e14f84098a3f7406d28f64b99 Mon Sep 17 00:00:00 2001 From: Philippe Troin Date: Sat, 18 May 2019 21:12:48 -0700 Subject: [PATCH] Multipart boundary field can be quoted. Reference: https://tools.ietf.org/html/rfc2046#section-5.1.1 According to RFC 2046, the boundary parameter in the Content-Type header can optionally be quoted with double quotes. Fix zchunk's boundary parsing so that double quotes are stripped when found. --- src/lib/dl/multipart.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/dl/multipart.c b/src/lib/dl/multipart.c index ca6341a..829972b 100644 --- a/src/lib/dl/multipart.c +++ b/src/lib/dl/multipart.c @@ -238,8 +238,16 @@ size_t multipart_get_boundary(zckDL *dl, char *b, size_t size) { regmatch_t match[2] = {{0}}; if(regexec(dl->hdr_regex, buf, 2, match, 0) == 0) { reset_mp(dl->mp); - char *boundary = zmalloc(match[1].rm_eo - match[1].rm_so + 1); - memcpy(boundary, buf + match[1].rm_so, match[1].rm_eo - match[1].rm_so); + size_t boundary_length = match[1].rm_eo - match[1].rm_so; + char *boundary_start = buf + match[1].rm_so; + if ( boundary_start[0] == '\"' && boundary_length > 2 + && boundary_start[boundary_length-1] == '\"') { + /* Remove optional quotes */ + boundary_start += 1; + boundary_length -= 2; + } + char *boundary = zmalloc(boundary_length + 1); + memcpy(boundary, boundary_start, boundary_length); zck_log(ZCK_LOG_DEBUG, "Multipart boundary: %s", boundary); dl->boundary = boundary; } -- 2.30.2