diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-12-21 11:20:56 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-12-21 11:20:56 -0500 |
commit | f75660958cc62422d158f9284b7fcfdee9fa9b95 (patch) | |
tree | 74d035018d40eda822bd07663c948d4e8f0bbb0f /src/or/connection.c | |
parent | d7531b2adc6d09e33f9a4a3accc4cf3fe28284d6 (diff) | |
parent | b5e6bbc01dc5d89285aba8a1440a2f5833e531a5 (diff) | |
download | tor-f75660958cc62422d158f9284b7fcfdee9fa9b95.tar.gz tor-f75660958cc62422d158f9284b7fcfdee9fa9b95.zip |
Merge remote-tracking branch 'origin/maint-0.2.2'
Diffstat (limited to 'src/or/connection.c')
-rw-r--r-- | src/or/connection.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index 28d8bca12a..87755842c9 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -1051,7 +1051,12 @@ connection_create_listener(const struct sockaddr *listensockaddr, } /** Do basic sanity checking on a newly received socket. Return 0 - * if it looks ok, else return -1. */ + * if it looks ok, else return -1. + * + * Notably, some TCP stacks can erroneously have accept() return successfully + * with socklen 0, when the client sends an RST before the accept call (as + * nmap does). We want to detect that, and not go on with the connection. + */ static int check_sockaddr(struct sockaddr *sa, int len, int level) { @@ -1117,7 +1122,7 @@ connection_handle_listener_read(connection_t *conn, int new_type) tor_socket_t news; /* the new socket */ connection_t *newconn; /* information about the remote peer when connecting to other routers */ - char addrbuf[256]; + char addrbuf[256]; /*XXX023 use sockaddr_storage instead*/ struct sockaddr *remote = (struct sockaddr*)addrbuf; /* length of the remote address. Must be whatever accept() needs. */ socklen_t remotelen = (socklen_t)sizeof(addrbuf); @@ -1161,21 +1166,9 @@ connection_handle_listener_read(connection_t *conn, int new_type) uint16_t port; if (check_sockaddr(remote, remotelen, LOG_INFO)<0) { log_info(LD_NET, - "accept() returned a strange address; trying getsockname()."); - remotelen=sizeof(addrbuf); - memset(addrbuf, 0, sizeof(addrbuf)); - if (getsockname(news, remote, &remotelen)<0) { - int e = tor_socket_errno(news); - log_warn(LD_NET, "getsockname() for new connection failed: %s", - tor_socket_strerror(e)); - } else { - if (check_sockaddr((struct sockaddr*)addrbuf, remotelen, - LOG_WARN) < 0) { - log_warn(LD_NET,"Something's wrong with this conn. Closing it."); - tor_close_socket(news); - return 0; - } - } + "accept() returned a strange address; closing connection."); + tor_close_socket(news); + return 0; } if (check_sockaddr_family_match(remote->sa_family, conn) < 0) { |