Commit c2fbff6d authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Cesanta Bot

Fix mg_http_parse_header

Per standard, cookies are delimited by `; `.

CL: Fix mg_http_parse_header: treat ";" as a delimiter.

PUBLISHED_FROM=039243c30f5fabf4a4700a43506f841b3268306a
parent b8eca17c
...@@ -7208,7 +7208,7 @@ void mg_printf_html_escape(struct mg_connection *nc, const char *fmt, ...) { ...@@ -7208,7 +7208,7 @@ void mg_printf_html_escape(struct mg_connection *nc, const char *fmt, ...) {
static void mg_http_parse_header_internal(struct mg_str *hdr, static void mg_http_parse_header_internal(struct mg_str *hdr,
const char *var_name, const char *var_name,
struct altbuf *ab) { struct altbuf *ab) {
int ch = ' ', ch1 = ',', n = strlen(var_name); int ch = ' ', ch1 = ',', ch2 = ';', n = strlen(var_name);
const char *p, *end = hdr ? hdr->p + hdr->len : NULL, *s = NULL; const char *p, *end = hdr ? hdr->p + hdr->len : NULL, *s = NULL;
/* Find where variable starts */ /* Find where variable starts */
...@@ -7221,10 +7221,10 @@ static void mg_http_parse_header_internal(struct mg_str *hdr, ...@@ -7221,10 +7221,10 @@ static void mg_http_parse_header_internal(struct mg_str *hdr,
if (s != NULL && &s[n + 1] < end) { if (s != NULL && &s[n + 1] < end) {
s += n + 1; s += n + 1;
if (*s == '"' || *s == '\'') { if (*s == '"' || *s == '\'') {
ch = ch1 = *s++; ch = ch1 = ch2 = *s++;
} }
p = s; p = s;
while (p < end && p[0] != ch && p[0] != ch1) { while (p < end && p[0] != ch && p[0] != ch1 && p[0] != ch2) {
if (ch != ' ' && p[0] == '\\' && p[1] == ch) p++; if (ch != ' ' && p[0] == '\\' && p[1] == ch) p++;
altbuf_append(ab, *p++); altbuf_append(ab, *p++);
} }
......
...@@ -1644,7 +1644,7 @@ void mg_printf_html_escape(struct mg_connection *nc, const char *fmt, ...) { ...@@ -1644,7 +1644,7 @@ void mg_printf_html_escape(struct mg_connection *nc, const char *fmt, ...) {
static void mg_http_parse_header_internal(struct mg_str *hdr, static void mg_http_parse_header_internal(struct mg_str *hdr,
const char *var_name, const char *var_name,
struct altbuf *ab) { struct altbuf *ab) {
int ch = ' ', ch1 = ',', n = strlen(var_name); int ch = ' ', ch1 = ',', ch2 = ';', n = strlen(var_name);
const char *p, *end = hdr ? hdr->p + hdr->len : NULL, *s = NULL; const char *p, *end = hdr ? hdr->p + hdr->len : NULL, *s = NULL;
/* Find where variable starts */ /* Find where variable starts */
...@@ -1657,10 +1657,10 @@ static void mg_http_parse_header_internal(struct mg_str *hdr, ...@@ -1657,10 +1657,10 @@ static void mg_http_parse_header_internal(struct mg_str *hdr,
if (s != NULL && &s[n + 1] < end) { if (s != NULL && &s[n + 1] < end) {
s += n + 1; s += n + 1;
if (*s == '"' || *s == '\'') { if (*s == '"' || *s == '\'') {
ch = ch1 = *s++; ch = ch1 = ch2 = *s++;
} }
p = s; p = s;
while (p < end && p[0] != ch && p[0] != ch1) { while (p < end && p[0] != ch && p[0] != ch1 && p[0] != ch2) {
if (ch != ' ' && p[0] == '\\' && p[1] == ch) p++; if (ch != ' ' && p[0] == '\\' && p[1] == ch) p++;
altbuf_append(ab, *p++); altbuf_append(ab, *p++);
} }
......
...@@ -4973,7 +4973,7 @@ static const char *test_buffer_limit(void) { ...@@ -4973,7 +4973,7 @@ static const char *test_buffer_limit(void) {
static const char *test_http_parse_header(void) { static const char *test_http_parse_header(void) {
static struct mg_str h = MG_MK_STR( static struct mg_str h = MG_MK_STR(
"xx=1 kl yy, ert=234 kl=123, " "xx=1 kl yy, ert=234 kl=123, qq=ww;"
"uri=\"/?naii=x,y\";ii=\"12\\\"34\" zz='aa bb',tt=2,gf=\"xx d=1234"); "uri=\"/?naii=x,y\";ii=\"12\\\"34\" zz='aa bb',tt=2,gf=\"xx d=1234");
char buf[20]; char buf[20];
char *buf2; char *buf2;
...@@ -5021,6 +5021,9 @@ static const char *test_http_parse_header(void) { ...@@ -5021,6 +5021,9 @@ static const char *test_http_parse_header(void) {
ASSERT_EQ(mg_http_parse_header(&h, "tt", buf, sizeof(buf)), 1); ASSERT_EQ(mg_http_parse_header(&h, "tt", buf, sizeof(buf)), 1);
ASSERT_STREQ(buf, "2"); ASSERT_STREQ(buf, "2");
ASSERT(mg_http_parse_header(&h, "uri", buf, sizeof(buf)) > 0); ASSERT(mg_http_parse_header(&h, "uri", buf, sizeof(buf)) > 0);
ASSERT_STREQ(buf, "/?naii=x,y");
ASSERT(mg_http_parse_header(&h, "qq", buf, sizeof(buf)) > 0);
ASSERT_STREQ(buf, "ww");
return NULL; return NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment