]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Don't crash if isc_uv_export returns an error in accept_connection.
authorWitold Kręcicki <wpk@isc.org>
Tue, 20 Oct 2020 10:55:58 +0000 (12:55 +0200)
committerEvan Hunt <each@isc.org>
Thu, 22 Oct 2020 18:37:16 +0000 (11:37 -0700)
isc_uv_export can return an error - e.g. EMFILE (from dup), handle this
nicely.

lib/isc/netmgr/tcp.c

index 483bd6d12f7e901254caf9c011fcc2a9d586656a..7aef685058445a82f6c69220b88db7539966b9a9 100644 (file)
@@ -16,6 +16,7 @@
 #include <isc/atomic.h>
 #include <isc/buffer.h>
 #include <isc/condition.h>
+#include <isc/errno.h>
 #include <isc/log.h>
 #include <isc/magic.h>
 #include <isc/mem.h>
@@ -933,7 +934,9 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) {
        if (r != 0) {
                result = isc__nm_uverr2result(r);
                uv_close((uv_handle_t *)uvstream, free_uvtcpt);
-               isc_quota_detach(&quota);
+               if (quota != NULL) {
+                       isc_quota_detach(&quota);
+               }
                return (result);
        }
 
@@ -942,6 +945,17 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) {
        event = isc__nm_get_ievent(ssock->mgr, netievent_tcpchildaccept);
 
        /* Duplicate the server socket */
+       r = isc_uv_export((uv_stream_t *)uvstream, &event->streaminfo);
+       if (r != 0) {
+               result = isc_errno_toresult(errno);
+               uv_close((uv_handle_t *)uvstream, free_uvtcpt);
+               if (quota != NULL) {
+                       isc_quota_detach(&quota);
+               }
+               isc__nm_put_ievent(ssock->mgr, event);
+               return (result);
+       }
+
        isc_nmsocket_t *csock = isc_mem_get(ssock->mgr->mctx,
                                            sizeof(isc_nmsocket_t));
        isc__nmsocket_init(csock, ssock->mgr, isc_nm_tcpsocket, ssock->iface);
@@ -954,9 +968,6 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) {
        event->sock = csock;
        event->quota = quota;
 
-       r = isc_uv_export((uv_stream_t *)uvstream, &event->streaminfo);
-       RUNTIME_CHECK(r == 0);
-
        uv_close((uv_handle_t *)uvstream, free_uvtcpt);
 
        if (w == isc_nm_tid()) {