mirror of
https://github.com/cesanta/mongoose.git
synced 2026-09-30 13:32:29 +07:00
Do uri len check after it is finalised
This commit is contained in:
+4
-3
@@ -1493,9 +1493,6 @@ int mg_http_parse(const char *s, size_t len, struct mg_http_message *hm) {
|
||||
while (s < end && s[0] == ' ') s++; // Skip spaces
|
||||
if ((s = skiptorn(s, end, &hm->proto)) == NULL) return false;
|
||||
|
||||
// Sanity check. Allow protocol/reason to be empty
|
||||
if (hm->method.len == 0 || hm->uri.len == 0) return -1;
|
||||
|
||||
// If URI contains '?' character, setup query string
|
||||
if ((qs = (const char *) memchr(hm->uri.ptr, '?', hm->uri.len)) != NULL) {
|
||||
hm->query.ptr = qs + 1;
|
||||
@@ -1503,6 +1500,10 @@ int mg_http_parse(const char *s, size_t len, struct mg_http_message *hm) {
|
||||
hm->uri.len = (size_t) (qs - hm->uri.ptr);
|
||||
}
|
||||
|
||||
// Sanity check. Allow protocol/reason to be empty
|
||||
// Do this check after hm->method.len and hm->uri.len are finalised
|
||||
if (hm->method.len == 0 || hm->uri.len == 0) return -1;
|
||||
|
||||
if (!mg_http_parse_headers(s, end, hm->headers,
|
||||
sizeof(hm->headers) / sizeof(hm->headers[0])))
|
||||
return -1; // error when parsing
|
||||
|
||||
+4
-3
@@ -257,9 +257,6 @@ int mg_http_parse(const char *s, size_t len, struct mg_http_message *hm) {
|
||||
while (s < end && s[0] == ' ') s++; // Skip spaces
|
||||
if ((s = skiptorn(s, end, &hm->proto)) == NULL) return false;
|
||||
|
||||
// Sanity check. Allow protocol/reason to be empty
|
||||
if (hm->method.len == 0 || hm->uri.len == 0) return -1;
|
||||
|
||||
// If URI contains '?' character, setup query string
|
||||
if ((qs = (const char *) memchr(hm->uri.ptr, '?', hm->uri.len)) != NULL) {
|
||||
hm->query.ptr = qs + 1;
|
||||
@@ -267,6 +264,10 @@ int mg_http_parse(const char *s, size_t len, struct mg_http_message *hm) {
|
||||
hm->uri.len = (size_t) (qs - hm->uri.ptr);
|
||||
}
|
||||
|
||||
// Sanity check. Allow protocol/reason to be empty
|
||||
// Do this check after hm->method.len and hm->uri.len are finalised
|
||||
if (hm->method.len == 0 || hm->uri.len == 0) return -1;
|
||||
|
||||
if (!mg_http_parse_headers(s, end, hm->headers,
|
||||
sizeof(hm->headers) / sizeof(hm->headers[0])))
|
||||
return -1; // error when parsing
|
||||
|
||||
Reference in New Issue
Block a user