diff options
author | Roger Dingledine <arma@torproject.org> | 2002-09-23 01:04:59 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2002-09-23 01:04:59 +0000 |
commit | 988c6d4277669ad383a26710dd60666abee5f528 (patch) | |
tree | 8b0c3d9ba4a59eaeb213cce665f307f873656d27 /src | |
parent | 155c9b80cadc18715697dc24164dbdfc47b3cf77 (diff) | |
download | tor-988c6d4277669ad383a26710dd60666abee5f528.tar.gz tor-988c6d4277669ad383a26710dd60666abee5f528.zip |
more robust when only some of the socks info has arrived
svn:r108
Diffstat (limited to 'src')
-rw-r--r-- | src/or/connection_ap.c | 19 | ||||
-rw-r--r-- | src/or/or.h | 3 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/or/connection_ap.c b/src/or/connection_ap.c index c0caa5b87d..838fe737e5 100644 --- a/src/or/connection_ap.c +++ b/src/or/connection_ap.c @@ -5,7 +5,6 @@ #include "or.h" extern int global_role; /* from main.c */ -static const char socks_userid[] = "anonymous"; int connection_ap_process_inbuf(connection_t *conn) { @@ -34,8 +33,6 @@ int connection_ap_process_inbuf(connection_t *conn) { int ap_handshake_process_socks(connection_t *conn) { char c; socks4_t socks4_info; - static char destaddr[512]; /* XXX there's a race condition waiting to happen here */ - static int destlen=0; assert(conn); @@ -85,7 +82,9 @@ int ap_handshake_process_socks(connection_t *conn) { } if(!conn->read_username) { /* the socks spec says we've got to read stuff until we get a null */ - while(conn->inbuf_datalen) { + for(;;) { + if(!conn->inbuf_datalen) + return 0; /* maybe next time */ if(connection_fetch_from_buf((char *)&c,1,conn) < 0) return -1; if(!c) { @@ -98,19 +97,19 @@ int ap_handshake_process_socks(connection_t *conn) { if(!conn->dest_addr) { /* no dest_addr found yet */ - while(conn->inbuf_datalen) { + for(;;) { + if(!conn->inbuf_datalen) + return 0; /* maybe next time */ if(connection_fetch_from_buf((char *)&c,1,conn) < 0) return -1; - destaddr[destlen++] = c; - if(destlen > 500) { + conn->dest_tmp[conn->dest_tmplen++] = c; + if(conn->dest_tmplen > 500) { log(LOG_NOTICE,"ap_handshake_process_socks(): dest_addr too long!"); ap_handshake_socks_reply(conn, SOCKS4_REQUEST_REJECT); - destlen = 0; return -1; } if(!c) { /* we found the null; we're done */ - conn->dest_addr = strdup(destaddr); - destlen = 0; + conn->dest_addr = strdup(conn->dest_tmp); log(LOG_NOTICE,"ap_handshake_process_socks(): successfully read dest addr '%s'", conn->dest_addr); break; diff --git a/src/or/or.h b/src/or/or.h index 7bfba7246e..d6c051b3c7 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -213,6 +213,9 @@ typedef struct char *dest_addr; uint16_t dest_port; + + char dest_tmp[512]; + int dest_tmplen; /* used by OR, to keep state while connect()ing: Kludge. */ |