dovecot-2.2: lib-http: Ignore trailing whitespace in headers.
dovecot at dovecot.org
dovecot at dovecot.org
Sun Aug 4 14:04:09 EEST 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/2d6497a4f124
changeset: 16641:2d6497a4f124
user: Timo Sirainen <tss at iki.fi>
date: Sun Aug 04 14:03:54 2013 +0300
description:
lib-http: Ignore trailing whitespace in headers.
Patch by Stephan Bosch.
diffstat:
src/lib-http/http-header-parser.c | 13 +++++++++++--
src/lib-http/test-http-header-parser.c | 34 +++++++++++++++++++++++++++++++++-
2 files changed, 44 insertions(+), 3 deletions(-)
diffs (91 lines):
diff -r 97fcb2904b22 -r 2d6497a4f124 src/lib-http/http-header-parser.c
--- a/src/lib-http/http-header-parser.c Sun Aug 04 12:16:09 2013 +0300
+++ b/src/lib-http/http-header-parser.c Sun Aug 04 14:03:54 2013 +0300
@@ -124,7 +124,7 @@
int ret;
/* 'header' = *( header-field CRLF ) CRLF
- header-field = field-name ":" OWS field-value BWS
+ header-field = field-name ":" OWS field-value OWS
field-name = token
field-value = *( field-content / obs-fold )
field-content = *( HTAB / SP / VCHAR / obs-text )
@@ -247,6 +247,7 @@
const char **name_r, const unsigned char **data_r, size_t *size_r,
const char **error_r)
{
+ const unsigned char *data;
size_t size;
int ret;
@@ -264,8 +265,16 @@
if (ret == 1) {
if (parser->state != HTTP_HEADER_PARSE_STATE_EOH) {
+ data = buffer_get_data(parser->value_buf, &size);
+
+ /* trim trailing OWS */
+ while (size > 0 &&
+ (data[size-1] == ' ' || data[size-1] == '\t'))
+ size--;
+
*name_r = str_c(parser->name);
- *data_r = buffer_get_data(parser->value_buf, size_r);
+ *data_r = data;
+ *size_r = size;
parser->state = HTTP_HEADER_PARSE_STATE_INIT;
} else {
*name_r = NULL;
diff -r 97fcb2904b22 -r 2d6497a4f124 src/lib-http/test-http-header-parser.c
--- a/src/lib-http/test-http-header-parser.c Sun Aug 04 12:16:09 2013 +0300
+++ b/src/lib-http/test-http-header-parser.c Sun Aug 04 14:03:54 2013 +0300
@@ -62,6 +62,22 @@
};
static struct http_header_parse_result valid_header_parse_result4[] = {
+ { "Age", "58" },
+ { "Date", "Sun, 04 Aug 2013 09:33:09 GMT" },
+ { "Expires", "Sun, 04 Aug 2013 09:34:08 GMT" },
+ { "Cache-Control", "max-age=60" },
+ { "Content-Length", "17336" },
+ { "Connection", "Keep-Alive" },
+ { "Via", "NS-CACHE-9.3" },
+ { "Server", "Apache" },
+ { "Vary", "Host" },
+ { "Last-Modified", "Sun, 04 Aug 2013 09:33:07 GMT" },
+ { "Content-Type", "text/html; charset=utf-8" },
+ { "Content-Encoding", "gzip" },
+ { NULL, NULL }
+};
+
+static struct http_header_parse_result valid_header_parse_result5[] = {
{ NULL, NULL }
};
@@ -108,9 +124,25 @@
"\r\n",
.fields = valid_header_parse_result3
},{
+ .header =
+ "Age: 58 \r\n"
+ "Date: Sun, 04 Aug 2013 09:33:09 GMT\r\n"
+ "Expires: Sun, 04 Aug 2013 09:34:08 GMT\r\n"
+ "Cache-Control: max-age=60 \r\n"
+ "Content-Length: 17336 \r\n"
+ "Connection: Keep-Alive\r\n"
+ "Via: NS-CACHE-9.3\r\n"
+ "Server: Apache\r\n"
+ "Vary: Host\r\n"
+ "Last-Modified: Sun, 04 Aug 2013 09:33:07 GMT\r\n"
+ "Content-Type: text/html; charset=utf-8\r\n"
+ "Content-Encoding: gzip\r\n"
+ "\r\n",
+ .fields = valid_header_parse_result4
+ },{
.header =
"\r\n",
- .fields = valid_header_parse_result4
+ .fields = valid_header_parse_result5
}
};
More information about the dovecot-cvs
mailing list