From dd44c068c5b962c26efd52c0ae013f281b743d8e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 14 Oct 2007 08:48:51 +0000 Subject: r15761@catbus: nickm | 2007-10-14 04:24:18 -0400 backport r11828: when accept gives us something we didn't want (which means "not AF_INET" in 0.1.2.x) then warn and bail from connection_handle_listener_read(). svn:r11926 --- src/or/connection.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/or') diff --git a/src/or/connection.c b/src/or/connection.c index 86fc4bf629..e92345aeb3 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -736,7 +736,7 @@ connection_handle_listener_read(connection_t *conn, int new_type) struct sockaddr_in remote; char addrbuf[256]; /* length of the remote address. Must be whatever accept() needs. */ - socklen_t remotelen = 256; + socklen_t remotelen = sizeof(addrbuf); char tmpbuf[INET_NTOA_BUF_LEN]; tor_assert((size_t)remotelen >= sizeof(struct sockaddr_in)); memset(addrbuf, 0, sizeof(addrbuf)); @@ -762,6 +762,16 @@ connection_handle_listener_read(connection_t *conn, int new_type) news,conn->s); set_socket_nonblocking(news); + if (((struct sockaddr*)addrbuf)->sa_family != AF_INET) { + log_info(LD_BUG, "A listener connection returned a socket with a " + "mismatched family. %s for addr_family %d gave us a socket " + "with address family %d. Dropping.", + conn_type_to_string(conn->type), + (int)AF_INET, + (int)((struct sockaddr*)addrbuf)->sa_family); + tor_close_socket(news); + return 0; + } if (check_sockaddr_in((struct sockaddr*)addrbuf, remotelen, LOG_INFO)<0) { log_info(LD_NET, -- cgit v1.2.3-54-g00ecf