diff options
Diffstat (limited to 'src/microhttpd/mhd_send.c')
-rw-r--r-- | src/microhttpd/mhd_send.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c index bed850ce..fbb65023 100644 --- a/src/microhttpd/mhd_send.c +++ b/src/microhttpd/mhd_send.c | |||
@@ -650,7 +650,7 @@ post_send_setopt (struct MHD_Connection *connection, | |||
650 | #endif /* ! MHD_TCP_CORK_NOPUSH */ | 650 | #endif /* ! MHD_TCP_CORK_NOPUSH */ |
651 | #ifdef HAVE_MESSAGES | 651 | #ifdef HAVE_MESSAGES |
652 | MHD_DLOG (connection->daemon, | 652 | MHD_DLOG (connection->daemon, |
653 | _ ("Failed to put the data from buffers to the network. " | 653 | _ ("Failed to push the data from buffers to the network. " |
654 | "Client may experience some delay " | 654 | "Client may experience some delay " |
655 | "(usually in range 200ms - 5 sec).\n")); | 655 | "(usually in range 200ms - 5 sec).\n")); |
656 | #endif /* HAVE_MESSAGES */ | 656 | #endif /* HAVE_MESSAGES */ |
@@ -672,21 +672,21 @@ MHD_send_data_ (struct MHD_Connection *connection, | |||
672 | const bool tls_conn = false; | 672 | const bool tls_conn = false; |
673 | #endif /* ! HTTPS_SUPPORT */ | 673 | #endif /* ! HTTPS_SUPPORT */ |
674 | 674 | ||
675 | /* error handling from send_param_adapter() */ | ||
676 | if ( (MHD_INVALID_SOCKET == s) || | 675 | if ( (MHD_INVALID_SOCKET == s) || |
677 | (MHD_CONNECTION_CLOSED == connection->state) ) | 676 | (MHD_CONNECTION_CLOSED == connection->state) ) |
678 | { | 677 | { |
679 | return MHD_ERR_NOTCONN_; | 678 | return MHD_ERR_NOTCONN_; |
680 | } | 679 | } |
681 | 680 | ||
681 | if (buffer_size > SSIZE_MAX) | ||
682 | { | ||
683 | buffer_size = SSIZE_MAX; /* Max return value */ | ||
684 | push_data = false; /* Incomplete send */ | ||
685 | } | ||
686 | |||
682 | if (tls_conn) | 687 | if (tls_conn) |
683 | { | 688 | { |
684 | #ifdef HTTPS_SUPPORT | 689 | #ifdef HTTPS_SUPPORT |
685 | if (buffer_size > SSIZE_MAX) | ||
686 | { | ||
687 | buffer_size = SSIZE_MAX; | ||
688 | push_data = false; /* Incomplete send */ | ||
689 | } | ||
690 | pre_send_setopt (connection, (! tls_conn), push_data); | 690 | pre_send_setopt (connection, (! tls_conn), push_data); |
691 | ret = gnutls_record_send (connection->tls_session, | 691 | ret = gnutls_record_send (connection->tls_session, |
692 | buffer, | 692 | buffer, |
@@ -723,7 +723,7 @@ MHD_send_data_ (struct MHD_Connection *connection, | |||
723 | /* plaintext transmission */ | 723 | /* plaintext transmission */ |
724 | if (buffer_size > MHD_SCKT_SEND_MAX_SIZE_) | 724 | if (buffer_size > MHD_SCKT_SEND_MAX_SIZE_) |
725 | { | 725 | { |
726 | buffer_size = MHD_SCKT_SEND_MAX_SIZE_; /* return value limit */ | 726 | buffer_size = MHD_SCKT_SEND_MAX_SIZE_; /* send() return value limit */ |
727 | push_data = false; /* Incomplete send */ | 727 | push_data = false; /* Incomplete send */ |
728 | } | 728 | } |
729 | 729 | ||
@@ -855,14 +855,15 @@ MHD_send_hdr_and_body_ (struct MHD_Connection *connection, | |||
855 | push_hdr); | 855 | push_hdr); |
856 | 856 | ||
857 | if ( (header_size == (size_t) ret) && | 857 | if ( (header_size == (size_t) ret) && |
858 | (((size_t) SSIZE_MAX > header_size)) && | 858 | ((size_t) SSIZE_MAX > header_size) && |
859 | (0 != body_size) ) | 859 | (0 != body_size) ) |
860 | { | 860 | { |
861 | ssize_t ret2; | 861 | ssize_t ret2; |
862 | /* The header has been sent completely. | 862 | /* The header has been sent completely. |
863 | * Try to send the reply body without waiting for | 863 | * Try to send the reply body without waiting for |
864 | * the next round. */ | 864 | * the next round. */ |
865 | /* Make sure that sum of ret + ret2 will not exceed SSIZE_MAX. */ | 865 | /* Make sure that sum of ret + ret2 will not exceed SSIZE_MAX as |
866 | * function needs to return positive value if succeed. */ | ||
866 | if ( (((size_t) SSIZE_MAX) - ((size_t) ret)) < body_size) | 867 | if ( (((size_t) SSIZE_MAX) - ((size_t) ret)) < body_size) |
867 | { | 868 | { |
868 | body_size = (((size_t) SSIZE_MAX) - ((size_t) ret)); | 869 | body_size = (((size_t) SSIZE_MAX) - ((size_t) ret)); |
@@ -888,6 +889,7 @@ MHD_send_hdr_and_body_ (struct MHD_Connection *connection, | |||
888 | if ( ((size_t) SSIZE_MAX <= body_size) || | 889 | if ( ((size_t) SSIZE_MAX <= body_size) || |
889 | ((size_t) SSIZE_MAX < (header_size + body_size)) ) | 890 | ((size_t) SSIZE_MAX < (header_size + body_size)) ) |
890 | { | 891 | { |
892 | /* Return value limit */ | ||
891 | body_size = SSIZE_MAX - header_size; | 893 | body_size = SSIZE_MAX - header_size; |
892 | complete_response = false; | 894 | complete_response = false; |
893 | push_body = complete_response; | 895 | push_body = complete_response; |
@@ -965,8 +967,7 @@ MHD_send_hdr_and_body_ (struct MHD_Connection *connection, | |||
965 | { | 967 | { |
966 | /* The header has been sent completely and there is a | 968 | /* The header has been sent completely and there is a |
967 | * need to push the header data. */ | 969 | * need to push the header data. */ |
968 | /* Luckily it is know what type of send function will be used | 970 | /* Luckily the type of send function will be used next is known. */ |
969 | * next. */ | ||
970 | post_send_setopt (connection, | 971 | post_send_setopt (connection, |
971 | #if defined(_MHD_HAVE_SENDFILE) | 972 | #if defined(_MHD_HAVE_SENDFILE) |
972 | MHD_resp_sender_std == connection->resp_sender, | 973 | MHD_resp_sender_std == connection->resp_sender, |