Commit e4ad3010 authored by Sergey Lyubka's avatar Sergey Lyubka

Fix #416

parent 03a82ef8
...@@ -4105,23 +4105,23 @@ static int is_dav_request(const struct connection *conn) { ...@@ -4105,23 +4105,23 @@ static int is_dav_request(const struct connection *conn) {
static int parse_header(const char *str, int str_len, const char *var_name, static int parse_header(const char *str, int str_len, const char *var_name,
char *buf, size_t buf_size) { char *buf, size_t buf_size) {
int ch = ' ', len = 0, n = strlen(var_name); int ch = ' ', ch1 = ',', len = 0, n = strlen(var_name);
const char *p, *end = str + str_len, *s = NULL; const char *p, *end = str + str_len, *s = NULL;
if (buf != NULL && buf_size > 0) buf[0] = '\0'; if (buf != NULL && buf_size > 0) buf[0] = '\0';
// Find where variable starts // Find where variable starts
for (s = str; s != NULL && s + n < end; s++) { for (s = str; s != NULL && s + n < end; s++) {
if ((s == str || s[-1] == ' ' || s[-1] == ',') && s[n] == '=' && if ((s == str || s[-1] == ch || s[-1] == ch1) && s[n] == '=' &&
!memcmp(s, var_name, n)) break; !memcmp(s, var_name, n)) break;
} }
if (s != NULL && &s[n + 1] < end) { if (s != NULL && &s[n + 1] < end) {
s += n + 1; s += n + 1;
if (*s == '"' || *s == '\'') ch = *s++; if (*s == '"' || *s == '\'') ch = ch1 = *s++;
p = s; p = s;
while (p < end && p[0] != ch && p[0] != ',' && len < (int) buf_size) { while (p < end && p[0] != ch && p[0] != ch1 && len < (int) buf_size) {
if (p[0] == '\\' && p[1] == ch) p++; if (ch == ch1 && p[0] == '\\' && p[1] == ch) p++;
buf[len++] = *p++; buf[len++] = *p++;
} }
if (len >= (int) buf_size || (ch != ' ' && *p != ch)) { if (len >= (int) buf_size || (ch != ' ' && *p != ch)) {
......
...@@ -306,9 +306,9 @@ static const char *test_base64_encode(void) { ...@@ -306,9 +306,9 @@ static const char *test_base64_encode(void) {
} }
static const char *test_mg_parse_header(void) { static const char *test_mg_parse_header(void) {
const char *str = "xx=1 kl yy, ert=234 kl=123, " const char *str = "xx=1 kl yy, ert=234 kl=123, uri=\"/?name=x,y\", "
"ii=\"12\\\"34\" zz='aa bb',tt=2,gf=\"xx d=1234"; "ii=\"12\\\"34\" zz='aa bb',tt=2,gf=\"xx d=1234";
char buf[10]; char buf[20];
ASSERT(mg_parse_header(str, "yy", buf, sizeof(buf)) == 0); ASSERT(mg_parse_header(str, "yy", buf, sizeof(buf)) == 0);
ASSERT(mg_parse_header(str, "ert", buf, sizeof(buf)) == 3); ASSERT(mg_parse_header(str, "ert", buf, sizeof(buf)) == 3);
ASSERT(strcmp(buf, "234") == 0); ASSERT(strcmp(buf, "234") == 0);
...@@ -331,6 +331,7 @@ static const char *test_mg_parse_header(void) { ...@@ -331,6 +331,7 @@ static const char *test_mg_parse_header(void) {
ASSERT(strcmp(buf, "12\"34") == 0); ASSERT(strcmp(buf, "12\"34") == 0);
ASSERT(mg_parse_header(str, "tt", buf, sizeof(buf)) == 1); ASSERT(mg_parse_header(str, "tt", buf, sizeof(buf)) == 1);
ASSERT(strcmp(buf, "2") == 0); ASSERT(strcmp(buf, "2") == 0);
ASSERT(mg_parse_header(str, "uri", buf, sizeof(buf)) == 10);
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