summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2019-02-08 01:00:48 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2019-02-08 22:49:46 -0500
commitd7ad5819e6c80170ad03cc790a4f18d4f40e91a4 (patch)
tree98e2064a0b6195086683dc7a6b3d7f1170d79001
parenta620f80b77be952011ae326b4609f2f3fb7684b0 (diff)
downloadlighttpd1.4-d7ad5819e6c80170ad03cc790a4f18d4f40e91a4.tar.gz
lighttpd1.4-d7ad5819e6c80170ad03cc790a4f18d4f40e91a4.zip
[core] copy request only if might need for logging
copy request header only if we may need to log it upon error
-rw-r--r--src/connections.c41
-rw-r--r--src/request.c32
-rw-r--r--src/t/test_request.c2
3 files changed, 37 insertions, 38 deletions
diff --git a/src/connections.c b/src/connections.c
index 05e64e73..4ae98823 100644
--- a/src/connections.c
+++ b/src/connections.c
@@ -2,6 +2,7 @@
#include "base.h"
#include "buffer.h"
+#include "burl.h" /* HTTP_PARSEOPT_HEADER_STRICT */
#include "log.h"
#include "connections.h"
#include "fdevent.h"
@@ -671,16 +672,12 @@ static int connection_reset(server *srv, connection *con) {
CLEAN(request.uri);
CLEAN(request.request_line);
CLEAN(request.pathinfo);
- CLEAN(request.request);
/* CLEAN(request.orig_uri); */
/* CLEAN(uri.path); */
CLEAN(uri.path_raw);
/* CLEAN(uri.query); */
-
- CLEAN(parse_request);
-
#undef CLEAN
buffer_clear(con->uri.scheme);
@@ -717,6 +714,7 @@ static void connection_read_header(server *srv, connection *con) {
chunk *c;
size_t hlen = 0;
int le = 0;
+ buffer *save;
for (c = cq->first; c; c = c->next) {
size_t clen = buffer_string_length(c->mem) - c->offset;
@@ -762,6 +760,28 @@ static void connection_read_header(server *srv, connection *con) {
chunkqueue_remove_finished_chunks(cq);
+ /* skip past \r\n or \n after previous POST request when keep-alive */
+ if (con->request_count > 1) {
+ char * const s = con->request.request->ptr;
+ #ifdef __COVERITY__
+ if (buffer_string_length(con->request.request) < 2) {
+ return;
+ }
+ #endif
+ if (s[0] == '\r' && s[1] == '\n') {
+ size_t len = buffer_string_length(con->request.request);
+ memmove(s, s+2, len-2);
+ buffer_string_set_length(con->request.request, len-2);
+ }
+ else if (s[0] == '\n') {
+ if (!(con->conf.http_parseopts & HTTP_PARSEOPT_HEADER_STRICT)) {
+ size_t len = buffer_string_length(con->request.request);
+ memmove(s, s+1, len-1);
+ buffer_string_set_length(con->request.request, len-1);
+ }
+ }
+ }
+
if (con->conf.log_request_header) {
log_error_write(srv, __FILE__, __LINE__, "sdsdSb",
"fd:", con->fd,
@@ -774,16 +794,27 @@ static void connection_read_header(server *srv, connection *con) {
buffer_reset(con->uri.query);
buffer_reset(con->request.orig_uri);
+ save = con->parse_request;
+ con->parse_request = con->request.request; /* for http_request_parse() */
+ if (srv->srvconf.log_request_header_on_error) {
+ /* copy request only if we may need to log it upon error */
+ buffer_copy_buffer(save, con->request.request);
+ }
+
if (0 != http_request_parse(srv, con)) {
con->keep_alive = 0;
con->request.content_length = 0;
if (srv->srvconf.log_request_header_on_error) {
log_error_write(srv, __FILE__, __LINE__, "Sb",
- "request-header:\n", con->request.request);
+ "request-header:\n", save);
}
}
+ con->parse_request = save;
+ buffer_reset(save);
+ buffer_reset(con->request.request);
+
connection_set_state(srv, con, CON_STATE_REQUEST_END);
}
diff --git a/src/request.c b/src/request.c
index a4712b76..d550d19b 100644
--- a/src/request.c
+++ b/src/request.c
@@ -587,38 +587,6 @@ static size_t http_request_parse_reqline(server *srv, connection *con, parse_hea
* End : "^$"
*/
-
- if (con->request_count > 1 &&
- con->request.request->ptr[0] == '\r' &&
- con->request.request->ptr[1] == '\n') {
- /* we are in keep-alive and might get \r\n after a previous POST request.*/
-
- #ifdef __COVERITY__
- if (buffer_string_length(con->request.request) < 2) {
- return 0;
- }
- #endif
- /* coverity[overflow_sink : FALSE] */
- buffer_copy_string_len(con->parse_request, con->request.request->ptr + 2, buffer_string_length(con->request.request) - 2);
- } else if (con->request_count > 0 &&
- con->request.request->ptr[1] == '\n') {
- /* we are in keep-alive and might get \n after a previous POST request.*/
- if (http_header_strict) {
- http_request_missing_CR_before_LF(srv, con);
- return 0;
- }
- #ifdef __COVERITY__
- if (buffer_string_length(con->request.request) < 1) {
- return 0;
- }
- #endif
- /* coverity[overflow_sink : FALSE] */
- buffer_copy_string_len(con->parse_request, con->request.request->ptr + 1, buffer_string_length(con->request.request) - 1);
- } else {
- /* fill the local request buffer */
- buffer_copy_buffer(con->parse_request, con->request.request);
- }
-
/* parse the first line of the request
*
* should be:
diff --git a/src/t/test_request.c b/src/t/test_request.c
index e14647b4..374427b9 100644
--- a/src/t/test_request.c
+++ b/src/t/test_request.c
@@ -31,7 +31,7 @@ static void test_request_connection_reset(connection *con)
static void run_http_request_parse(server *srv, connection *con, int line, int status, const char *desc, const char *req, size_t reqlen)
{
test_request_connection_reset(con);
- buffer_copy_string_len(con->request.request, req, reqlen);
+ buffer_copy_string_len(con->parse_request, req, reqlen);
http_request_parse(srv, con);
if (con->http_status != status) {
fprintf(stderr,