diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-06-29 17:44:29 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-06-29 17:45:27 -0400 |
commit | 05c424f4b830e98595b33397b58504462dbda8db (patch) | |
tree | f2d36e4b49a885ba4d45c74a2e7e71a9596311a6 /src/or/buffers.c | |
parent | 5d43a1572094868e598541f9ce686546c910f071 (diff) | |
download | tor-05c424f4b830e98595b33397b58504462dbda8db.tar.gz tor-05c424f4b830e98595b33397b58504462dbda8db.zip |
Refactor fetch_from_buf_socks() to be greedy
Previously, fetch_from_buf_socks() might return 0 if there was still
data on the buffer and a subsequent call to fetch_from_buf_socks()
would return 1. This was making some of the socks5 unit tests
harder to write, and could potentially have caused misbehavior with
some overly verbose SOCKS implementations. Now,
fetch_from_buf_socks() does as much processing as it can, and
returns 0 only if it really needs more data. This brings it into
line with the evbuffer socks implementation.
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r-- | src/or/buffers.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 44a492addc..1310b4215b 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -1544,9 +1544,7 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req, else if (n_drain > 0) buf_remove_from_front(buf, n_drain); - } while (res == 0 && buf->head && - buf->datalen > buf->head->datalen && - want_length < buf->head->datalen); + } while (res == 0 && buf->head && want_length < buf->datalen); return res; } @@ -1690,6 +1688,7 @@ parse_socks(const char *data, size_t datalen, socks_request_t *req, } *drain_out = 2u + usernamelen + 1u + passlen; req->got_auth = 1; + *want_length_out = 7; /* Minimal socks5 sommand. */ return 0; } else if (req->auth_type == SOCKS_USER_PASS) { /* unknown version byte */ @@ -1749,8 +1748,8 @@ parse_socks(const char *data, size_t datalen, socks_request_t *req, } /* we know the method; read in the request */ log_debug(LD_APP,"socks5: checking request"); - if (datalen < 8) {/* basic info plus >=2 for addr plus 2 for port */ - *want_length_out = 8; + if (datalen < 7) {/* basic info plus >=1 for addr plus 2 for port */ + *want_length_out = 7; return 0; /* not yet */ } req->command = (unsigned char) *(data+1); @@ -1891,7 +1890,7 @@ parse_socks(const char *data, size_t datalen, socks_request_t *req, return -1; } log_debug(LD_APP,"socks4: Username not here yet."); - *want_length_out = datalen+1024; /* ???? */ + *want_length_out = datalen+1024; /* More than we need, but safe */ return 0; } authend = next; @@ -1919,7 +1918,7 @@ parse_socks(const char *data, size_t datalen, socks_request_t *req, return -1; } log_debug(LD_APP,"socks4: Destaddr not all here yet."); - *want_length_out = datalen + 1024; + *want_length_out = datalen + 1024; /* More than we need, but safe */ return 0; } if (MAX_SOCKS_ADDR_LEN <= next-startaddr) { |