libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 07e48b90fc9070b6775eb0c97b03d00ae6e610d6
parent e1180e9ff4f946bc531328c8d95a52a70a5f48ae
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon,  3 Aug 2009 22:21:33 +0000

fixing double-read issue

Diffstat:
MChangeLog | 10++++++++++
Msrc/daemon/connection.c | 30++++++++++++++++++++++++++----
2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,13 @@ +Tue Aug 4 00:14:04 CEST 2009 + Fixing double-call to read from content-reader callback for first + data segment (as reported by Alex on the mailinglist). -CG + +Thu Jul 29 21:41:52 CEST 2009 + Fixed issue with the code not using the "block_size" argument + given to MHD_create_response_from_callback causing inefficiencies + for values < 2048 and segmentation faults for values > 2048 + (as reported by Andre Colomb on the mailinglist). -CG + Sun May 17 03:29:46 MDT 2009 Releasing libmicrohttpd 0.4.2. -CG diff --git a/src/daemon/connection.c b/src/daemon/connection.c @@ -328,6 +328,11 @@ try_ready_normal_body (struct MHD_Connection *connection) response = connection->response; if (response->crc == NULL) return MHD_YES; + if ( (response->data_start <= + connection->response_write_position) && + (response->data_size + response->data_start > + connection->response_write_position) ) + return MHD_YES; /* response already ready */ ret = response->crc (response->crc_cls, connection->response_write_position, response->data, @@ -402,10 +407,27 @@ try_ready_chunked_body (struct MHD_Connection *connection) connection->write_buffer = buf; } - ret = response->crc (response->crc_cls, - connection->response_write_position, - &connection->write_buffer[sizeof (cbuf)], - connection->write_buffer_size - sizeof (cbuf) - 2); + if ( (response->data_start <= + connection->response_write_position) && + (response->data_size + response->data_start > + connection->response_write_position) ) + { + /* buffer already ready, use what is there for the chunk */ + ret = response->data_size + response->data_start - connection->response_write_position; + if (ret > connection->write_buffer_size - sizeof (cbuf) - 2) + ret = connection->write_buffer_size - sizeof (cbuf) - 2; + memcpy (&connection->write_buffer[sizeof (cbuf)], + &response->data[connection->response_write_position - response->data_start], + ret); + } + else + { + /* buffer not in range, try to fill it */ + ret = response->crc (response->crc_cls, + connection->response_write_position, + &connection->write_buffer[sizeof (cbuf)], + connection->write_buffer_size - sizeof (cbuf) - 2); + } if (ret == -1) { /* end of message, signal other side! */