From dd44c068c5b962c26efd52c0ae013f281b743d8e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 14 Oct 2007 08:48:51 +0000 Subject: [PATCH] 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 --- ChangeLog | 2 ++ doc/TODO.012 | 2 +- src/or/connection.c | 12 +++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 967140c59a..5891698433 100644 --- a/ChangeLog +++ b/ChangeLog @@ -31,6 +31,8 @@ Changes in version 0.1.2.18 - 2007-??-?? - When we have our clock set far in the future and generate an onion key, then re-set our clock to be correct, we should not stop the onion key from getting rotated. + - On some platforms, accept() can return a broken address. Detect + this more quietly, and deal accordingly. (Fixes bug 483.) Changes in version 0.1.2.17 - 2007-08-30 diff --git a/doc/TODO.012 b/doc/TODO.012 index 4fd15fb140..6126f3e966 100644 --- a/doc/TODO.012 +++ b/doc/TODO.012 @@ -3,7 +3,7 @@ description of the patch.) Backport items for 0.1.2: o r11166: Don't believe future dates from the state file. -N - r11828+: Detect bad sa_family from accept(). + o r11828+: Detect bad sa_family from accept(). N - r11882: Avoid crash-bug 451. N - r11886: Consider family as well as identity when cannibalizing circuits. 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,