1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-12-22 04:02:04 +03:00

Make parse_http_headers robust against headers without :

This commit is contained in:
bel
2016-01-18 21:14:32 +01:00
parent f73c868407
commit ac0860f6bc

View File

@@ -6459,10 +6459,26 @@ parse_http_headers(char **buf, struct mg_request_info *ri)
ri->num_headers = 0; ri->num_headers = 0;
for (i = 0; i < (int)ARRAY_SIZE(ri->http_headers); i++) { for (i = 0; i < (int)ARRAY_SIZE(ri->http_headers); i++) {
char *dp = strchr(*buf, ':'); char *dp = *buf;
if (!dp) { while ((*dp != ':') && (*dp != '\r') && (*dp != 0)) {
dp++;
}
if (!*dp) {
/* neither : nor \r\n. This is not a valid field. */
break; break;
} }
if (*dp == '\r') {
if (dp[1] == '\n') {
/* \r\n */
ri->http_headers[i].name = *buf;
ri->http_headers[i].value = 0;
*buf = dp;
} else {
/* stray \r. This is not valid. */
break;
}
} else {
/* (*dp == ':') */
*dp = 0; *dp = 0;
ri->http_headers[i].name = *buf; ri->http_headers[i].name = *buf;
do { do {
@@ -6471,6 +6487,7 @@ parse_http_headers(char **buf, struct mg_request_info *ri)
ri->http_headers[i].value = dp; ri->http_headers[i].value = dp;
*buf = strstr(dp, "\r\n"); *buf = strstr(dp, "\r\n");
}
ri->num_headers = i + 1; ri->num_headers = i + 1;
if (*buf) { if (*buf) {