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,18 +6459,35 @@ 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;
} }
*dp = 0; if (*dp == '\r') {
ri->http_headers[i].name = *buf; if (dp[1] == '\n') {
do { /* \r\n */
dp++; ri->http_headers[i].name = *buf;
} while (*dp == ' '); ri->http_headers[i].value = 0;
*buf = dp;
} else {
/* stray \r. This is not valid. */
break;
}
} else {
/* (*dp == ':') */
*dp = 0;
ri->http_headers[i].name = *buf;
do {
dp++;
} while (*dp == ' ');
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) {