From: W.C.A. Wijngaards Date: Thu, 26 Nov 2020 13:29:22 +0000 (+0100) Subject: * Fix so that ldns-testns does not leak sockets if the read fails. X-Git-Tag: 1.8.0-rc.1~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a4896c5fa238547b813fdbecbfb0e2c9d3846b3;p=thirdparty%2Fldns.git * Fix so that ldns-testns does not leak sockets if the read fails. --- diff --git a/Changelog b/Changelog index 5dc14318..1568010d 100644 --- a/Changelog +++ b/Changelog @@ -14,6 +14,7 @@ * Fix for #93: fix packaging/libldns.pc Makefile rule. * ldns-testns can answer several queries over one tcp connection, if they arrive within 100msec of each other. + * Fix so that ldns-testns does not leak sockets if the read fails. 1.7.1 2019-07-26 * bugfix: Manage verification paths for OpenSSL >= 1.1.0 diff --git a/examples/ldns-testns.c b/examples/ldns-testns.c index 1a906ee4..f1b9c722 100644 --- a/examples/ldns-testns.c +++ b/examples/ldns-testns.c @@ -347,8 +347,14 @@ handle_tcp(int tcp_sock, struct entry* entries, int *count) while(1) { /* tcp recv */ - if (read_n_bytes(s, (uint8_t*)&tcplen, sizeof(tcplen))) + if (read_n_bytes(s, (uint8_t*)&tcplen, sizeof(tcplen))) { +#ifndef USE_WINSOCK + close(s); +#else + closesocket(s); +#endif return; + } tcplen = ntohs(tcplen); if(tcplen >= INBUF_SIZE) { log_msg("query %d bytes too large, buffer %d bytes.\n", @@ -360,8 +366,14 @@ handle_tcp(int tcp_sock, struct entry* entries, int *count) #endif return; } - if (read_n_bytes(s, inbuf, tcplen)) + if (read_n_bytes(s, inbuf, tcplen)) { +#ifndef USE_WINSOCK + close(s); +#else + closesocket(s); +#endif return; + } handle_query(inbuf, (ssize_t) tcplen, entries, count, transport_tcp, send_tcp, &userdata, do_verbose?logfile:0);