[tor-commits] [tor/master] Mark some tests in parse_socks.c as unreachable (BUG, LCOV)

nickm at torproject.org nickm at torproject.org
Wed Sep 27 15:16:48 UTC 2017


commit 14124f82dfbdf68e202f6e5f8220e6567e7a9d1e
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Sep 27 11:15:03 2017 -0400

    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.
---
 src/or/proto_socks.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/or/proto_socks.c b/src/or/proto_socks.c
index f92d61491..3fb3a131d 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)",





More information about the tor-commits mailing list