From b7b05dc1b26c5d828cda618f2a27fa883b7bfb7e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 1 Mar 2005 01:15:01 +0000 Subject: [PATCH] make control interface stream IDs monotonically increasing to prevent possible races svn:r3715 --- src/or/connection.c | 2 ++ src/or/control.c | 2 +- src/or/or.h | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/or/connection.c b/src/or/connection.c index c76cc45625..f44185ac2d 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -110,6 +110,7 @@ static int connection_bucket_read_limit(connection_t *conn); * Initialize conn's timestamps to now. */ connection_t *connection_new(int type) { + static uint32_t n_connections_allocated = 0; connection_t *conn; time_t now = time(NULL); @@ -117,6 +118,7 @@ connection_t *connection_new(int type) { conn->magic = CONNECTION_MAGIC; conn->s = -1; /* give it a default of 'not used' */ conn->poll_index = -1; /* also default to 'not used' */ + conn->global_identifier = n_connections_allocated++; conn->type = type; if (!connection_is_listener(conn)) { /* listeners never use their buf */ diff --git a/src/or/control.c b/src/or/control.c index f9415b922c..4ce437283b 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -769,7 +769,7 @@ control_event_stream_status(connection_t *conn, stream_status_event_t tp) len = strlen(buf); msg = tor_malloc(5+len+1); msg[0] = (uint8_t) tp; - set_uint32(msg+1, htonl(conn->s)); /* ???? Is this a security problem? */ + set_uint32(msg+1, htonl(conn->global_identifier)); strlcpy(msg+5, buf, len+1); send_control_event(EVENT_STREAM_STATUS, (uint16_t)(5+len+1), msg); diff --git a/src/or/or.h b/src/or/or.h index a69f4b1c61..55dce9edbf 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -598,6 +598,10 @@ struct connection_t { socks_request_t *socks_request; /**< SOCKS structure describing request (AP * only.) */ + /** Quasi-global identifier for this connection; used for control.c */ + /* XXXX NM This can get re-used after 2**32 circuits. */ + uint32_t global_identifier; + /* Used only by control connections */ uint32_t event_mask; }; @@ -874,7 +878,7 @@ struct circuit_t { struct circuit_t *rend_splice; /** Quasi-global identifier for this circuit; used for control.c */ - /* XXXX009 NM This can get re-used after 2**32 circuits. */ + /* XXXX NM This can get re-used after 2**32 circuits. */ uint32_t global_identifier; struct circuit_t *next; /**< Next circuit in linked list. */