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:
@@ -6459,18 +6459,35 @@ parse_http_headers(char **buf, struct mg_request_info *ri)
|
||||
ri->num_headers = 0;
|
||||
|
||||
for (i = 0; i < (int)ARRAY_SIZE(ri->http_headers); i++) {
|
||||
char *dp = strchr(*buf, ':');
|
||||
if (!dp) {
|
||||
char *dp = *buf;
|
||||
while ((*dp != ':') && (*dp != '\r') && (*dp != 0)) {
|
||||
dp++;
|
||||
}
|
||||
if (!*dp) {
|
||||
/* neither : nor \r\n. This is not a valid field. */
|
||||
break;
|
||||
}
|
||||
*dp = 0;
|
||||
ri->http_headers[i].name = *buf;
|
||||
do {
|
||||
dp++;
|
||||
} while (*dp == ' ');
|
||||
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;
|
||||
ri->http_headers[i].name = *buf;
|
||||
do {
|
||||
dp++;
|
||||
} while (*dp == ' ');
|
||||
|
||||
ri->http_headers[i].value = dp;
|
||||
*buf = strstr(dp, "\r\n");
|
||||
ri->http_headers[i].value = dp;
|
||||
*buf = strstr(dp, "\r\n");
|
||||
}
|
||||
|
||||
ri->num_headers = i + 1;
|
||||
if (*buf) {
|
||||
|
||||
Reference in New Issue
Block a user