mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-30 21:18:25 +00:00
Fix to stop misbehaving clients to DoS mongoose
This commit is contained in:
1 parent
eecf24b20c
commit
cdb6588973
1 file changed
+6
-1
+6
-1
@@ -4632,9 +4632,12 @@ static void reset_per_request_attributes(struct mg_connection *conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void close_socket_gracefully(struct mg_connection *conn) {
|
static void close_socket_gracefully(struct mg_connection *conn) {
|
||||||
|
#if defined(_WIN32)
|
||||||
char buf[MG_BUF_LEN];
|
char buf[MG_BUF_LEN];
|
||||||
|
int n;
|
||||||
|
#endif
|
||||||
struct linger linger;
|
struct linger linger;
|
||||||
int n, sock = conn->client.sock;
|
int sock = conn->client.sock;
|
||||||
|
|
||||||
// Set linger option to avoid socket hanging out after close. This prevent
|
// Set linger option to avoid socket hanging out after close. This prevent
|
||||||
// ephemeral port exhaust problem under high QPS.
|
// ephemeral port exhaust problem under high QPS.
|
||||||
@@ -4646,6 +4649,7 @@ static void close_socket_gracefully(struct mg_connection *conn) {
|
|||||||
(void) shutdown(sock, SHUT_WR);
|
(void) shutdown(sock, SHUT_WR);
|
||||||
set_non_blocking_mode(sock);
|
set_non_blocking_mode(sock);
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
// Read and discard pending incoming data. If we do not do that and close the
|
// Read and discard pending incoming data. If we do not do that and close the
|
||||||
// socket, the data in the send buffer may be discarded. This
|
// socket, the data in the send buffer may be discarded. This
|
||||||
// behaviour is seen on Windows, when client keeps sending data
|
// behaviour is seen on Windows, when client keeps sending data
|
||||||
@@ -4654,6 +4658,7 @@ static void close_socket_gracefully(struct mg_connection *conn) {
|
|||||||
do {
|
do {
|
||||||
n = pull(NULL, conn, buf, sizeof(buf));
|
n = pull(NULL, conn, buf, sizeof(buf));
|
||||||
} while (n > 0);
|
} while (n > 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Now we know that our FIN is ACK-ed, safe to close
|
// Now we know that our FIN is ACK-ed, safe to close
|
||||||
(void) closesocket(sock);
|
(void) closesocket(sock);
|
||||||
|
|||||||
Reference in new issue
Block a user