commit 9b4358cd5a46b7cd85663c09811ab8258662c158
parent 832739556b765571f80520b91bdad5f14f6aa1b4
Author: Christian Grothoff <christian@grothoff.org>
Date: Fri, 22 Jun 2018 15:58:24 +0200
check response allocation succeeded when generating internal errors
Diffstat:
3 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
@@ -1756,6 +1756,7 @@ transmit_error_response (struct MHD_Connection *connection,
const char *message)
{
struct MHD_Response *response;
+ int iret;
if (NULL == connection->version)
{
@@ -1779,11 +1780,24 @@ transmit_error_response (struct MHD_Connection *connection,
response = MHD_create_response_from_buffer (strlen (message),
(void *) message,
MHD_RESPMEM_PERSISTENT);
- MHD_queue_response (connection,
- status_code,
- response);
- mhd_assert (NULL != connection->response);
+ if (NULL == response)
+ {
+ /* can't even send a reply, at least close the connection */
+ connection->state = MHD_CONNECTION_CLOSED;
+ return;
+ }
+ iret = MHD_queue_response (connection,
+ status_code,
+ response);
MHD_destroy_response (response);
+ if (MHD_YES != iret)
+ {
+ /* can't even send a reply, at least close the connection */
+ CONNECTION_CLOSE_ERROR (connection,
+ _("Closing connection (failed to queue response)\n"));
+ return;
+ }
+ mhd_assert (NULL != connection->response);
/* Do not reuse this connection. */
connection->keepalive = MHD_CONN_MUST_CLOSE;
if (MHD_NO == build_header_response (connection))
@@ -2732,6 +2746,8 @@ parse_connection_headers (struct MHD_Connection *connection)
MHD_HEADER_KIND,
MHD_HTTP_HEADER_HOST)) )
{
+ int iret;
+
/* die, http 1.1 request without host and we are pedantic */
connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
connection->read_closed = true;
@@ -2744,10 +2760,23 @@ parse_connection_headers (struct MHD_Connection *connection)
MHD_create_response_from_buffer (MHD_STATICSTR_LEN_ (REQUEST_LACKS_HOST),
REQUEST_LACKS_HOST,
MHD_RESPMEM_PERSISTENT);
- MHD_queue_response (connection,
- MHD_HTTP_BAD_REQUEST,
- response);
+ if (NULL == response)
+ {
+ /* can't even send a reply, at least close the connection */
+ CONNECTION_CLOSE_ERROR (connection,
+ _("Closing connection (failed to create response)\n"));
+ return;
+ }
+ iret = MHD_queue_response (connection,
+ MHD_HTTP_BAD_REQUEST,
+ response);
MHD_destroy_response (response);
+ if (MHD_YES != iret)
+ {
+ /* can't even send a reply, at least close the connection */
+ CONNECTION_CLOSE_ERROR (connection,
+ _("Closing connection (failed to queue response)\n"));
+ }
return;
}
diff --git a/src/microhttpd/test_postprocessor.c b/src/microhttpd/test_postprocessor.c
@@ -171,8 +171,6 @@ test_multipart_garbage (void)
xdata[1] = 'x';
xdata[2] = '\r';
memcpy (&xdata[3], FORM_DATA, size);
-
- size = strlen (FORM_DATA);
size += 3;
for (splitpoint = 1; splitpoint < size; splitpoint++)
{
diff --git a/src/testzzuf/socat.c b/src/testzzuf/socat.c
@@ -91,7 +91,6 @@ zzuf_socat_start ()
setpgid (0, 0);
execvp ("zzuf", args);
fprintf (stderr, "execution of `zzuf' failed: %s\n", strerror (errno));
- zzuf_pid = 0; /* fork failed */
exit (1);
}