Skip to content

Commit

Permalink
http: cleanup of the request-line parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
azat committed Oct 22, 2018
1 parent 2f43d1d commit 6cf659b
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1825,11 +1825,11 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line)
req->type = type;

if (evhttp_parse_http_version(version, req) < 0)
return (-1);
return -1;

if ((req->uri = mm_strdup(uri)) == NULL) {
event_debug(("%s: mm_strdup", __func__));
return (-1);
return -1;
}

if (type == EVHTTP_REQ_CONNECT) {
Expand All @@ -1854,7 +1854,7 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line)
!evhttp_find_vhost(req->evcon->http_server, NULL, hostname))
req->flags |= EVHTTP_PROXY_REQUEST;

return (0);
return 0;
}

const char *
Expand Down Expand Up @@ -1989,9 +1989,9 @@ evhttp_parse_firstline_(struct evhttp_request *req, struct evbuffer *buffer)
char *line;
enum message_read_status status = ALL_DATA_READ;

size_t line_length;
size_t len;
/* XXX try */
line = evbuffer_readln(buffer, &line_length, EVBUFFER_EOL_CRLF);
line = evbuffer_readln(buffer, &len, EVBUFFER_EOL_CRLF);
if (line == NULL) {
if (req->evcon != NULL &&
evbuffer_get_length(buffer) > req->evcon->max_headers_size)
Expand All @@ -2000,13 +2000,12 @@ evhttp_parse_firstline_(struct evhttp_request *req, struct evbuffer *buffer)
return (MORE_DATA_EXPECTED);
}

if (req->evcon != NULL &&
line_length > req->evcon->max_headers_size) {
if (req->evcon != NULL && len > req->evcon->max_headers_size) {
mm_free(line);
return (DATA_TOO_LONG);
}

req->headers_size = line_length;
req->headers_size = len;

switch (req->kind) {
case EVHTTP_REQUEST:
Expand Down Expand Up @@ -2063,12 +2062,12 @@ evhttp_parse_headers_(struct evhttp_request *req, struct evbuffer* buffer)
enum message_read_status status = MORE_DATA_EXPECTED;

struct evkeyvalq* headers = req->input_headers;
size_t line_length;
while ((line = evbuffer_readln(buffer, &line_length, EVBUFFER_EOL_CRLF))
size_t len;
while ((line = evbuffer_readln(buffer, &len, EVBUFFER_EOL_CRLF))
!= NULL) {
char *skey, *svalue;

req->headers_size += line_length;
req->headers_size += len;

if (req->evcon != NULL &&
req->headers_size > req->evcon->max_headers_size) {
Expand Down

0 comments on commit 6cf659b

Please sign in to comment.