[tor-commits] [tor/master] Check that new listener connection is actually listening

nickm at torproject.org nickm at torproject.org
Wed Dec 5 13:14:25 UTC 2018


commit 9369152aae9527cc3764cac8688f258b11bd503d
Author: rl1987 <rl1987 at sdf.lonestar.org>
Date:   Mon Dec 3 14:28:32 2018 +0200

    Check that new listener connection is actually listening
---
 src/core/mainloop/connection.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index eaad45c81..66a8b5147 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -1460,6 +1460,19 @@ connection_listener_new(const struct sockaddr *listensockaddr,
                tor_socket_strerror(tor_socket_errno(s)));
       goto err;
     }
+
+#ifndef __APPLE__
+    int value;
+    socklen_t len = sizeof(value);
+
+    if (!getsockopt(s, SOL_SOCKET, SO_ACCEPTCONN, &value, &len)) {
+      if (value == 0) {
+        log_err(LD_NET, "Could not listen on %s - "
+                        "getsockopt(.,SO_ACCEPTCONN,.) yields 0.", address);
+        goto err;
+      }
+    }
+#endif /* __APPLE__ */
 #endif /* defined(HAVE_SYS_UN_H) */
   } else {
     log_err(LD_BUG, "Got unexpected address family %d.",





More information about the tor-commits mailing list