Merge remote-tracking branch 'linus/bug4369'

This commit is contained in:
Nick Mathewson 2012-05-30 13:05:15 -04:00
commit 711e4b4237
2 changed files with 16 additions and 3 deletions

3
changes/bug4369 Normal file
View File

@ -0,0 +1,3 @@
o Minor features:
- Close any connection that sends unrecognized junk before the
handshake. Solves an issue noted in bug 4369.

View File

@ -160,9 +160,11 @@ command_process_cell(cell_t *cell, or_connection_t *conn)
if (handshaking && cell->command != CELL_VERSIONS && if (handshaking && cell->command != CELL_VERSIONS &&
cell->command != CELL_NETINFO) { cell->command != CELL_NETINFO) {
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
"Received unexpected cell command %d in state %s; ignoring it.", "Received unexpected cell command %d in state %s; closing the "
"connection.",
(int)cell->command, (int)cell->command,
conn_state_to_string(CONN_TYPE_OR,conn->_base.state)); conn_state_to_string(CONN_TYPE_OR,conn->_base.state));
connection_mark_for_close(TO_CONN(conn));
return; return;
} }
@ -258,8 +260,15 @@ command_process_var_cell(var_cell_t *cell, or_connection_t *conn)
switch (conn->_base.state) switch (conn->_base.state)
{ {
case OR_CONN_STATE_OR_HANDSHAKING_V2: case OR_CONN_STATE_OR_HANDSHAKING_V2:
if (cell->command != CELL_VERSIONS) if (cell->command != CELL_VERSIONS) {
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
"Received a cell with command %d in state %s; "
"closing the connection.",
(int)cell->command,
conn_state_to_string(CONN_TYPE_OR,conn->_base.state));
connection_mark_for_close(TO_CONN(conn));
return; return;
}
break; break;
case OR_CONN_STATE_TLS_HANDSHAKING: case OR_CONN_STATE_TLS_HANDSHAKING:
/* If we're using bufferevents, it's entirely possible for us to /* If we're using bufferevents, it's entirely possible for us to
@ -272,9 +281,10 @@ command_process_var_cell(var_cell_t *cell, or_connection_t *conn)
if (! command_allowed_before_handshake(cell->command)) { if (! command_allowed_before_handshake(cell->command)) {
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
"Received a cell with command %d in state %s; " "Received a cell with command %d in state %s; "
"ignoring it.", "closing the connection.",
(int)cell->command, (int)cell->command,
conn_state_to_string(CONN_TYPE_OR,conn->_base.state)); conn_state_to_string(CONN_TYPE_OR,conn->_base.state));
connection_mark_for_close(TO_CONN(conn));
return; return;
} else { } else {
if (enter_v3_handshake_with_cell(cell, conn)<0) if (enter_v3_handshake_with_cell(cell, conn)<0)