libmicrohttpd

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

commit 773d6cce732d9bcdde16851926a4e6c92baddd3c
parent bade8d9c4b5c1c6ab8b38a68ce57f8593177763c
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 19 Aug 2020 09:41:31 +0200

add logic to check return value of MHD_pool_reallocate()

Diffstat:
MChangeLog | 4++++
Msrc/microhttpd/connection.c | 20++++++++++++++++----
2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,7 @@ +Wed 19 Aug 2020 09:40:39 AM CEST + Add logic to check on MHD_pool_reallocate() failure reported on the + mailinglist (will NOT yet fix the issue). -CG + Sun 26 Jul 2020 01:56:54 PM CEST Add MHD_create_response_from_pipe() to allow creating a response based on data read from a pipe. -CG diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -1147,6 +1147,7 @@ try_grow_read_buffer (struct MHD_Connection *connection, { size_t new_size; size_t avail_size; + void *rb; avail_size = MHD_pool_get_free (connection->pool); if (0 == avail_size) @@ -1175,10 +1176,21 @@ try_grow_read_buffer (struct MHD_Connection *connection, new_size = connection->read_buffer_size + grow_size; } /* we can actually grow the buffer, do it! */ - connection->read_buffer = MHD_pool_reallocate (connection->pool, - connection->read_buffer, - connection->read_buffer_size, - new_size); + rb = MHD_pool_reallocate (connection->pool, + connection->read_buffer, + connection->read_buffer_size, + new_size); + if (NULL == rb) + { + /* This should NOT be possible: we just computed 'new_size' so that + it should fit. If it happens, somehow our read buffer is not in + the right position in the pool, say because someone called + MHD_pool_allocate() without 'from_end' set to 'true'? Anyway, + should be investigated! (Ideally provide all data from + *pool and connection->read_buffer and new_size for debugging). */mhd_assert (0); + return false; + } + connection->read_buffer = rb; mhd_assert (NULL != connection->read_buffer); connection->read_buffer_size = new_size; return true;