]> granicus.if.org Git - libevent/commitdiff
http: allow trailing spaces (and only them) in request-line (like nginx)
authorAzat Khuzhin <a3at.mail@gmail.com>
Mon, 22 Oct 2018 20:56:19 +0000 (23:56 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Mon, 22 Oct 2018 20:56:31 +0000 (23:56 +0300)
http.c

diff --git a/http.c b/http.c
index b6bbc6999aed392df72baf1204187afe14f1671d..9a641da832b93da9f0114d50971b62c65061154a 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1686,8 +1686,9 @@ evhttp_parse_response_line(struct evhttp_request *req, char *line)
 /* Parse the first line of a HTTP request */
 
 static int
-evhttp_parse_request_line(struct evhttp_request *req, char *line)
+evhttp_parse_request_line(struct evhttp_request *req, char *line, size_t len)
 {
+       char *eos = line + len;
        char *method;
        char *uri;
        char *version;
@@ -1696,6 +1697,12 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line)
        size_t method_len;
        enum evhttp_cmd_type type;
 
+       while (eos > line && *(eos-1) == ' ') {
+               *(eos-1) = '\0';
+               --eos;
+               --len;
+       }
+
        /* Parse the request line */
        method = strsep(&line, " ");
        if (line == NULL)
@@ -2009,7 +2016,7 @@ evhttp_parse_firstline_(struct evhttp_request *req, struct evbuffer *buffer)
 
        switch (req->kind) {
        case EVHTTP_REQUEST:
-               if (evhttp_parse_request_line(req, line) == -1)
+               if (evhttp_parse_request_line(req, line, len) == -1)
                        status = DATA_CORRUPTED;
                break;
        case EVHTTP_RESPONSE: