aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-06-22 15:58:24 +0200
committerChristian Grothoff <christian@grothoff.org>2018-06-22 15:58:24 +0200
commit9b4358cd5a46b7cd85663c09811ab8258662c158 (patch)
tree309f1521fe0cfb2aa1cdd95b5e0f641d87402ea1
parent832739556b765571f80520b91bdad5f14f6aa1b4 (diff)
downloadlibmicrohttpd-9b4358cd5a46b7cd85663c09811ab8258662c158.tar.gz
libmicrohttpd-9b4358cd5a46b7cd85663c09811ab8258662c158.zip
check response allocation succeeded when generating internal errors
-rw-r--r--src/microhttpd/connection.c43
-rw-r--r--src/microhttpd/test_postprocessor.c2
-rw-r--r--src/testzzuf/socat.c1
3 files changed, 36 insertions, 10 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 13b5015b..1778c59b 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -1756,6 +1756,7 @@ transmit_error_response (struct MHD_Connection *connection,
1756 const char *message) 1756 const char *message)
1757{ 1757{
1758 struct MHD_Response *response; 1758 struct MHD_Response *response;
1759 int iret;
1759 1760
1760 if (NULL == connection->version) 1761 if (NULL == connection->version)
1761 { 1762 {
@@ -1779,11 +1780,24 @@ transmit_error_response (struct MHD_Connection *connection,
1779 response = MHD_create_response_from_buffer (strlen (message), 1780 response = MHD_create_response_from_buffer (strlen (message),
1780 (void *) message, 1781 (void *) message,
1781 MHD_RESPMEM_PERSISTENT); 1782 MHD_RESPMEM_PERSISTENT);
1782 MHD_queue_response (connection, 1783 if (NULL == response)
1783 status_code, 1784 {
1784 response); 1785 /* can't even send a reply, at least close the connection */
1785 mhd_assert (NULL != connection->response); 1786 connection->state = MHD_CONNECTION_CLOSED;
1787 return;
1788 }
1789 iret = MHD_queue_response (connection,
1790 status_code,
1791 response);
1786 MHD_destroy_response (response); 1792 MHD_destroy_response (response);
1793 if (MHD_YES != iret)
1794 {
1795 /* can't even send a reply, at least close the connection */
1796 CONNECTION_CLOSE_ERROR (connection,
1797 _("Closing connection (failed to queue response)\n"));
1798 return;
1799 }
1800 mhd_assert (NULL != connection->response);
1787 /* Do not reuse this connection. */ 1801 /* Do not reuse this connection. */
1788 connection->keepalive = MHD_CONN_MUST_CLOSE; 1802 connection->keepalive = MHD_CONN_MUST_CLOSE;
1789 if (MHD_NO == build_header_response (connection)) 1803 if (MHD_NO == build_header_response (connection))
@@ -2732,6 +2746,8 @@ parse_connection_headers (struct MHD_Connection *connection)
2732 MHD_HEADER_KIND, 2746 MHD_HEADER_KIND,
2733 MHD_HTTP_HEADER_HOST)) ) 2747 MHD_HTTP_HEADER_HOST)) )
2734 { 2748 {
2749 int iret;
2750
2735 /* die, http 1.1 request without host and we are pedantic */ 2751 /* die, http 1.1 request without host and we are pedantic */
2736 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED; 2752 connection->state = MHD_CONNECTION_FOOTERS_RECEIVED;
2737 connection->read_closed = true; 2753 connection->read_closed = true;
@@ -2744,10 +2760,23 @@ parse_connection_headers (struct MHD_Connection *connection)
2744 MHD_create_response_from_buffer (MHD_STATICSTR_LEN_ (REQUEST_LACKS_HOST), 2760 MHD_create_response_from_buffer (MHD_STATICSTR_LEN_ (REQUEST_LACKS_HOST),
2745 REQUEST_LACKS_HOST, 2761 REQUEST_LACKS_HOST,
2746 MHD_RESPMEM_PERSISTENT); 2762 MHD_RESPMEM_PERSISTENT);
2747 MHD_queue_response (connection, 2763 if (NULL == response)
2748 MHD_HTTP_BAD_REQUEST, 2764 {
2749 response); 2765 /* can't even send a reply, at least close the connection */
2766 CONNECTION_CLOSE_ERROR (connection,
2767 _("Closing connection (failed to create response)\n"));
2768 return;
2769 }
2770 iret = MHD_queue_response (connection,
2771 MHD_HTTP_BAD_REQUEST,
2772 response);
2750 MHD_destroy_response (response); 2773 MHD_destroy_response (response);
2774 if (MHD_YES != iret)
2775 {
2776 /* can't even send a reply, at least close the connection */
2777 CONNECTION_CLOSE_ERROR (connection,
2778 _("Closing connection (failed to queue response)\n"));
2779 }
2751 return; 2780 return;
2752 } 2781 }
2753 2782
diff --git a/src/microhttpd/test_postprocessor.c b/src/microhttpd/test_postprocessor.c
index 8edc5b22..36b32f6d 100644
--- a/src/microhttpd/test_postprocessor.c
+++ b/src/microhttpd/test_postprocessor.c
@@ -171,8 +171,6 @@ test_multipart_garbage (void)
171 xdata[1] = 'x'; 171 xdata[1] = 'x';
172 xdata[2] = '\r'; 172 xdata[2] = '\r';
173 memcpy (&xdata[3], FORM_DATA, size); 173 memcpy (&xdata[3], FORM_DATA, size);
174
175 size = strlen (FORM_DATA);
176 size += 3; 174 size += 3;
177 for (splitpoint = 1; splitpoint < size; splitpoint++) 175 for (splitpoint = 1; splitpoint < size; splitpoint++)
178 { 176 {
diff --git a/src/testzzuf/socat.c b/src/testzzuf/socat.c
index b21f2c6f..72089a6d 100644
--- a/src/testzzuf/socat.c
+++ b/src/testzzuf/socat.c
@@ -91,7 +91,6 @@ zzuf_socat_start ()
91 setpgid (0, 0); 91 setpgid (0, 0);
92 execvp ("zzuf", args); 92 execvp ("zzuf", args);
93 fprintf (stderr, "execution of `zzuf' failed: %s\n", strerror (errno)); 93 fprintf (stderr, "execution of `zzuf' failed: %s\n", strerror (errno));
94 zzuf_pid = 0; /* fork failed */
95 exit (1); 94 exit (1);
96} 95}
97 96