summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-09-27 11:15:03 -0400
committerNick Mathewson <nickm@torproject.org>2017-09-27 11:16:20 -0400
commit14124f82dfbdf68e202f6e5f8220e6567e7a9d1e (patch)
tree8d4960d28ca8db5b4c61918e50d74c9bd140bb13
parent5427365907ef42a25ba1f3de072dcd6244e7a75b (diff)
downloadtor-14124f82dfbdf68e202f6e5f8220e6567e7a9d1e.tar.gz
tor-14124f82dfbdf68e202f6e5f8220e6567e7a9d1e.zip
Mark some tests in parse_socks.c as unreachable (BUG, LCOV)
These tests aren't reachable, given their actual arguments. I'm going to mark them as BUG(), and as unreachable with LCOV.
-rw-r--r--src/or/proto_socks.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/or/proto_socks.c b/src/or/proto_socks.c
index f92d614918..3fb3a131d9 100644
--- a/src/or/proto_socks.c
+++ b/src/or/proto_socks.c
@@ -340,13 +340,16 @@ parse_socks(const char *data, size_t datalen, socks_request_t *req,
tor_addr_to_str(tmpbuf, &destaddr, sizeof(tmpbuf), 1);
- if (strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
+ if (BUG(strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN)) {
+ /* LCOV_EXCL_START -- This branch is unreachable, given the
+ * size of tmpbuf and the actual value of MAX_SOCKS_ADDR_LEN */
socks_request_set_socks5_error(req, SOCKS5_GENERAL_ERROR);
log_warn(LD_APP,
"socks5 IP takes %d bytes, which doesn't fit in %d. "
"Rejecting.",
(int)strlen(tmpbuf)+1,(int)MAX_SOCKS_ADDR_LEN);
return -1;
+ /* LCOV_EXCL_STOP */
}
strlcpy(req->address,tmpbuf,sizeof(req->address));
req->port = ntohs(get_uint16(data+4+addrlen));
@@ -375,12 +378,15 @@ parse_socks(const char *data, size_t datalen, socks_request_t *req,
*want_length_out = 7+len;
return 0; /* not yet */
}
- if (len+1 > MAX_SOCKS_ADDR_LEN) {
+ if (BUG(len+1 > MAX_SOCKS_ADDR_LEN)) {
+ /* LCOV_EXCL_START -- unreachable, since len is at most 255,
+ * and MAX_SOCKS_ADDR_LEN is 256. */
socks_request_set_socks5_error(req, SOCKS5_GENERAL_ERROR);
log_warn(LD_APP,
"socks5 hostname is %d bytes, which doesn't fit in "
"%d. Rejecting.", len+1,MAX_SOCKS_ADDR_LEN);
return -1;
+ /* LCOV_EXCL_STOP */
}
memcpy(req->address,data+5,len);
req->address[len] = 0;
@@ -443,10 +449,13 @@ parse_socks(const char *data, size_t datalen, socks_request_t *req,
log_debug(LD_APP,"socks4: destip not in form 0.0.0.x.");
in.s_addr = htonl(destip);
tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
- if (strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
+ if (BUG(strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN)) {
+ /* LCOV_EXCL_START -- This branch is unreachable, given the
+ * size of tmpbuf and the actual value of MAX_SOCKS_ADDR_LEN */
log_debug(LD_APP,"socks4 addr (%d bytes) too long. Rejecting.",
(int)strlen(tmpbuf));
return -1;
+ /* LCOV_EXCL_STOP */
}
log_debug(LD_APP,
"socks4: successfully read destip (%s)",