libmicrohttpd

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

commit 523fa712fdc408997f8387c9fef62968c13758f2
parent 0b22e20357dad582e4b7a7a45b6e68102fb27b43
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Mon, 19 Apr 2021 16:22:43 +0300

connection: report error details for recv() as well

Diffstat:
Msrc/microhttpd/connection.c | 27+++++++++++++++++++++------
Msrc/microhttpd/connection_https.c | 23+++++++++++++++++++++--
2 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -208,9 +208,19 @@ recv_param_adapter (struct MHD_Connection *connection, } if (MHD_SCKT_ERR_IS_EINTR_ (err)) return MHD_ERR_AGAIN_; - if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ECONNRESET_)) + if (MHD_SCKT_ERR_IS_REMOTE_DISCNN_ (err)) return MHD_ERR_CONNRESET_; - /* Treat any other error as hard error. */ + if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EOPNOTSUPP_)) + return MHD_ERR_OPNOTSUPP_; + if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_ENOTCONN_)) + return MHD_ERR_NOTCONN_; + if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EINVAL_)) + return MHD_ERR_INVAL_; + if (MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err)) + return MHD_ERR_NOMEM_; + if (MHD_SCKT_ERR_IS_ (err, MHD_SCKT_EBADF_)) + return MHD_ERR_BADF_; + /* Treat any other error as a hard error. */ return MHD_ERR_NOTCONN_; } #ifdef EPOLL_SUPPORT @@ -2852,11 +2862,16 @@ MHD_connection_handle_read (struct MHD_Connection *connection) "Socket disconnected while reading request.")); return; } + +#ifdef HAVE_MESSAGES + if (MHD_CONNECTION_INIT != connection->state) + MHD_DLOG (connection->daemon, + _ ("Connection socket is closed when reading " \ + "request due to the error: %s\n"), + str_conn_error_ (bytes_read)); +#endif CONNECTION_CLOSE_ERROR (connection, - (MHD_CONNECTION_INIT == connection->state) ? - NULL : - _ ( - "Connection socket is closed due to error when reading request.")); + NULL); return; } diff --git a/src/microhttpd/connection_https.c b/src/microhttpd/connection_https.c @@ -73,9 +73,28 @@ recv_tls_adapter (struct MHD_Connection *connection, } if (res < 0) { - /* Likely 'GNUTLS_E_INVALID_SESSION' (client communication - disrupted); interpret as a hard error */ connection->tls_read_ready = false; + if ( (GNUTLS_E_DECRYPTION_FAILED == res) || + (GNUTLS_E_INVALID_SESSION == res) || + (GNUTLS_E_DECOMPRESSION_FAILED == res) || + (GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER == res) || + (GNUTLS_E_UNSUPPORTED_VERSION_PACKET == res) || + (GNUTLS_E_UNEXPECTED_PACKET_LENGTH == res) || + (GNUTLS_E_UNEXPECTED_PACKET == res) || + (GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET == res) || + (GNUTLS_E_EXPIRED == res) || + (GNUTLS_E_REHANDSHAKE == res) ) + return MHD_ERR_TLS_; + if ( (GNUTLS_E_PULL_ERROR == res) || + (GNUTLS_E_INTERNAL_ERROR == res) || + (GNUTLS_E_CRYPTODEV_IOCTL_ERROR == res) || + (GNUTLS_E_CRYPTODEV_DEVICE_ERROR == res) ) + return MHD_ERR_PIPE_; + if (GNUTLS_E_PREMATURE_TERMINATION == res) + return MHD_ERR_CONNRESET_; + if (GNUTLS_E_MEMORY_ERROR == res) + return MHD_ERR_NOMEM_; + /* Treat any other error as a hard error. */ return MHD_ERR_NOTCONN_; }