]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
* Fix so that ldns-testns does not leak sockets if the read fails.
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Thu, 26 Nov 2020 13:29:22 +0000 (14:29 +0100)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Thu, 26 Nov 2020 13:29:22 +0000 (14:29 +0100)
Changelog
examples/ldns-testns.c

index 5dc14318e0d9dfb4a7c5eeec46a303a5b309c300..1568010dc33aa56cddbf5247bf6ebc6e1460e6be 100644 (file)
--- 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
index 1a906ee43e00ab7b225018a17a9c56538e06d7e4..f1b9c7228d241c5870df5f64a7e4ffd37297f1f7 100644 (file)
@@ -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);