From 14b403c046c520ba6a755f2893dea6d4bddf47e4 Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Wed, 17 Aug 2011 12:42:12 +0200 Subject: [PATCH] fixed a post-buffering bug --- plugins/python/wsgi_subhandler.c | 1 + protocol.c | 2 +- utils.c | 9 +++++++-- uwsgi.c | 2 ++ uwsgi.h | 3 ++- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/python/wsgi_subhandler.c b/plugins/python/wsgi_subhandler.c index 774563bc..528ba725 100644 --- a/plugins/python/wsgi_subhandler.c +++ b/plugins/python/wsgi_subhandler.c @@ -27,6 +27,7 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_ Py_DECREF(pydictvalue); } + if (wsgi_req->uh.modifier1 == UWSGI_MODIFIER_MANAGE_PATH_INFO) { wsgi_req->uh.modifier1 = 0; pydictkey = PyDict_GetItemString(wsgi_req->async_environ, "SCRIPT_NAME"); diff --git a/protocol.c b/protocol.c index 18ad06f3..731cc2e8 100644 --- a/protocol.c +++ b/protocol.c @@ -717,7 +717,7 @@ next: } // on tiny post use memory else { - if (!uwsgi_read_whole_body_in_mem(wsgi_req, wsgi_req->post_buffering_buf)) { + if (!uwsgi_read_whole_body_in_mem(wsgi_req, uwsgi.mem_post_buf[wsgi_req->async_id], uwsgi.post_buffering)) { wsgi_req->status = -1; return -1; } diff --git a/utils.c b/utils.c index 24346280..17d67111 100644 --- a/utils.c +++ b/utils.c @@ -1391,7 +1391,7 @@ int count_options(struct option *lopt) { return count; } -int uwsgi_read_whole_body_in_mem(struct wsgi_request *wsgi_req, char *buf) { +int uwsgi_read_whole_body_in_mem(struct wsgi_request *wsgi_req, char *buf, size_t limit) { size_t post_remains = wsgi_req->post_cl; int ret; @@ -1413,7 +1413,12 @@ int uwsgi_read_whole_body_in_mem(struct wsgi_request *wsgi_req, char *buf) { return 0; } - len = read(wsgi_req->poll.fd, ptr, post_remains); + if (limit) { + len = read(wsgi_req->poll.fd, ptr, UMIN(post_remains, limit) ); + } + else { + len = read(wsgi_req->poll.fd, ptr, post_remains); + } if (len <= 0) { uwsgi_error("read()"); return 0; diff --git a/uwsgi.c b/uwsgi.c index e3a4fdcc..9a3547b0 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -1578,6 +1578,7 @@ int uwsgi_start(void *v_argv) { if (uwsgi.post_buffering > 0) { uwsgi.async_post_buf = uwsgi_malloc(sizeof(char *) * uwsgi.cores); + uwsgi.mem_post_buf = uwsgi_malloc(sizeof(char *) * uwsgi.cores); if (!uwsgi.post_buffering_bufsize) { uwsgi.post_buffering_bufsize = 8192; } @@ -1585,6 +1586,7 @@ int uwsgi_start(void *v_argv) { for (i = 0; i < uwsgi.cores; i++) { uwsgi.async_buf[i] = uwsgi_malloc(uwsgi.buffer_size); if (uwsgi.post_buffering > 0) { + uwsgi.mem_post_buf[i] = uwsgi_malloc(uwsgi.post_buffering); uwsgi.async_post_buf[i] = uwsgi_malloc(uwsgi.post_buffering_bufsize); } } diff --git a/uwsgi.h b/uwsgi.h index 14820f10..72f73543 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1015,6 +1015,7 @@ struct uwsgi_server { struct iovec **async_hvec; char **async_buf; char **async_post_buf; + char **mem_post_buf; struct wsgi_request **async_waiting_fd_table; struct wsgi_request **async_proto_fd_table; @@ -1719,7 +1720,7 @@ struct wsgi_request *threaded_current_wsgi_req(void); void build_options(void); int uwsgi_read_whole_body(struct wsgi_request *, char *, size_t); -int uwsgi_read_whole_body_in_mem(struct wsgi_request *, char *); +int uwsgi_read_whole_body_in_mem(struct wsgi_request *, char *, size_t); ssize_t uwsgi_sendfile(struct wsgi_request *);