Browse Source

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.
Nick Mathewson 6 years ago
parent
commit
14124f82df
1 changed files with 12 additions and 3 deletions
  1. 12 3
      src/or/proto_socks.c

+ 12 - 3
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);
           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);
             socks_request_set_socks5_error(req, SOCKS5_GENERAL_ERROR);
             log_warn(LD_APP,
             log_warn(LD_APP,
                      "socks5 IP takes %d bytes, which doesn't fit in %d. "
                      "socks5 IP takes %d bytes, which doesn't fit in %d. "
                      "Rejecting.",
                      "Rejecting.",
                      (int)strlen(tmpbuf)+1,(int)MAX_SOCKS_ADDR_LEN);
                      (int)strlen(tmpbuf)+1,(int)MAX_SOCKS_ADDR_LEN);
             return -1;
             return -1;
+            /* LCOV_EXCL_STOP */
           }
           }
           strlcpy(req->address,tmpbuf,sizeof(req->address));
           strlcpy(req->address,tmpbuf,sizeof(req->address));
           req->port = ntohs(get_uint16(data+4+addrlen));
           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;
             *want_length_out = 7+len;
             return 0; /* not yet */
             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);
             socks_request_set_socks5_error(req, SOCKS5_GENERAL_ERROR);
             log_warn(LD_APP,
             log_warn(LD_APP,
                      "socks5 hostname is %d bytes, which doesn't fit in "
                      "socks5 hostname is %d bytes, which doesn't fit in "
                      "%d. Rejecting.", len+1,MAX_SOCKS_ADDR_LEN);
                      "%d. Rejecting.", len+1,MAX_SOCKS_ADDR_LEN);
             return -1;
             return -1;
+            /* LCOV_EXCL_STOP */
           }
           }
           memcpy(req->address,data+5,len);
           memcpy(req->address,data+5,len);
           req->address[len] = 0;
           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.");
         log_debug(LD_APP,"socks4: destip not in form 0.0.0.x.");
         in.s_addr = htonl(destip);
         in.s_addr = htonl(destip);
         tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
         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.",
           log_debug(LD_APP,"socks4 addr (%d bytes) too long. Rejecting.",
                     (int)strlen(tmpbuf));
                     (int)strlen(tmpbuf));
           return -1;
           return -1;
+          /* LCOV_EXCL_STOP */
         }
         }
         log_debug(LD_APP,
         log_debug(LD_APP,
                   "socks4: successfully read destip (%s)",
                   "socks4: successfully read destip (%s)",