From d294bfddc747bc66995a4d6dda0b71415eecbf74 Mon Sep 17 00:00:00 2001 From: Ionut-Francisc Oancea Date: Tue, 27 May 2014 01:10:22 +0300 Subject: [PATCH 1/2] Fixed bug in the s_header_field state If the buffer ended with the '-' char on the s_header_field state, the parser forgot to call the on_header_field() callback due to the wrong 'break'. Fixed by letting the 'is_last' check to handle the "last-char" situations. --- multipart_parser.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/multipart_parser.c b/multipart_parser.c index 034bf9b..568af09 100644 --- a/multipart_parser.c +++ b/multipart_parser.c @@ -160,10 +160,6 @@ size_t multipart_parser_execute(multipart_parser* p, const char *buf, size_t len break; } - if (c == '-') { - break; - } - if (c == ':') { EMIT_DATA_CB(header_field, buf + mark, i - mark); p->state = s_header_value_start; @@ -171,7 +167,7 @@ size_t multipart_parser_execute(multipart_parser* p, const char *buf, size_t len } cl = tolower(c); - if (cl < 'a' || cl > 'z') { + if ((c != '-') && (cl < 'a' || cl > 'z')) { multipart_log("invalid character in header name"); return i; } From c61b685af18b26dba211d1629398eba498ea65a9 Mon Sep 17 00:00:00 2001 From: Ionut-Francisc Oancea Date: Tue, 27 May 2014 01:26:36 +0300 Subject: [PATCH 2/2] Fixed bug in the s_header_value state If the buffer ended with the '\r' char on the s_header_value state, the parser triggered the on_header_value() callback twice (buffer="data\r"): 1st time with "data" and 2nd time "data\r" resulting in "datadata\r" instead of "data". --- multipart_parser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/multipart_parser.c b/multipart_parser.c index 568af09..981dabb 100644 --- a/multipart_parser.c +++ b/multipart_parser.c @@ -199,6 +199,7 @@ size_t multipart_parser_execute(multipart_parser* p, const char *buf, size_t len if (c == CR) { EMIT_DATA_CB(header_value, buf + mark, i - mark); p->state = s_header_value_almost_done; + break; } if (is_last) EMIT_DATA_CB(header_value, buf + mark, (i - mark) + 1);