[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Move around some LCOV_EXCLs in src/common



commit a64d79ca4c5699be161a54d94e0e6c0f7d06db7c
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Sep 28 09:25:17 2017 -0400

    Move around some LCOV_EXCLs in src/common
    
    Apparently, my compiler now generates coverage markers for
    label-only lines, so we need to exclude those too if they are meant
    to be unreachable.
---
 src/common/address.c           | 10 ++++++----
 src/common/compat.c            |  2 +-
 src/common/compress.c          |  3 ++-
 src/common/compress_lzma.c     |  8 ++++++--
 src/common/crypto.c            |  5 +++--
 src/common/crypto_curve25519.c |  3 +++
 src/common/crypto_ed25519.c    | 13 +++++++++++--
 src/common/crypto_pwbox.c      |  2 +-
 src/common/crypto_s2k.c        | 10 +++++++---
 src/common/tortls.c            |  3 ++-
 src/common/util.c              |  6 ++++--
 src/common/util_format.c       |  5 ++++-
 12 files changed, 50 insertions(+), 20 deletions(-)

diff --git a/src/common/address.c b/src/common/address.c
index aa61b5423..dbe129be5 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -907,8 +907,8 @@ tor_addr_is_loopback(const tor_addr_t *addr)
       return (tor_addr_to_ipv4h(addr) & 0xff000000) == 0x7f000000;
     case AF_UNSPEC:
       return 0;
-    default:
       /* LCOV_EXCL_START */
+    default:
       tor_fragile_assert();
       return 0;
       /* LCOV_EXCL_STOP */
@@ -1031,8 +1031,10 @@ tor_addr_copy_tight(tor_addr_t *dest, const tor_addr_t *src)
       memcpy(dest->addr.in6_addr.s6_addr, src->addr.in6_addr.s6_addr, 16);
     case AF_UNSPEC:
       break;
+      // LCOV_EXCL_START
     default:
-      tor_fragile_assert(); // LCOV_EXCL_LINE
+      tor_fragile_assert();
+      // LCOV_EXCL_STOP
     }
 }
 
@@ -1138,8 +1140,8 @@ tor_addr_compare_masked(const tor_addr_t *addr1, const tor_addr_t *addr2,
           return 0;
         else
           return 1;
-      default:
         /* LCOV_EXCL_START */
+      default:
         tor_fragile_assert();
         return 0;
         /* LCOV_EXCL_STOP */
@@ -1194,8 +1196,8 @@ tor_addr_hash(const tor_addr_t *addr)
     return 0x4e4d5342;
   case AF_INET6:
     return siphash24g(&addr->addr.in6_addr.s6_addr, 16);
-  default:
     /* LCOV_EXCL_START */
+  default:
     tor_fragile_assert();
     return 0;
     /* LCOV_EXCL_STOP */
diff --git a/src/common/compat.c b/src/common/compat.c
index ab1fbc64f..7fe97488e 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -3350,8 +3350,8 @@ get_total_system_memory_impl(void)
   tor_free(s);
   return result * 1024;
 
- err:
   /* LCOV_EXCL_START Can't reach this unless proc is broken. */
+ err:
   tor_free(s);
   close(fd);
   return 0;
diff --git a/src/common/compress.c b/src/common/compress.c
index 472268a43..110eb6586 100644
--- a/src/common/compress.c
+++ b/src/common/compress.c
@@ -188,8 +188,9 @@ tor_compress_impl(int compress,
                "Error while %scompresing data: bad input?",
                compress?"":"un");
         goto err; // bad data.
-      default:
+
         // LCOV_EXCL_START
+      default:
         tor_assert_nonfatal_unreached();
         goto err;
         // LCOV_EXCL_STOP
diff --git a/src/common/compress_lzma.c b/src/common/compress_lzma.c
index 2bdbbe1d4..6426ede4f 100644
--- a/src/common/compress_lzma.c
+++ b/src/common/compress_lzma.c
@@ -158,8 +158,10 @@ tor_lzma_state_size_precalc(int compress, compression_level_t level)
 
   return (size_t)memory_usage;
 
+ // LCOV_EXCL_START
  err:
-  return 0; // LCOV_EXCL_LINE
+  return 0;
+ // LCOV_EXCL_STOP
 }
 #endif /* defined(HAVE_LZMA) */
 
@@ -212,9 +214,11 @@ tor_lzma_compress_new(int compress,
   atomic_counter_add(&total_lzma_allocation, result->allocation);
   return result;
 
+ /* LCOV_EXCL_START */
  err:
-  tor_free(result); // LCOV_EXCL_LINE
+  tor_free(result);
   return NULL;
+ /* LCOV_EXCL_STOP */
 #else /* !(defined(HAVE_LZMA)) */
   (void)compress;
   (void)method;
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 1730619f8..6fe3c661c 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1798,8 +1798,8 @@ crypto_digest_algorithm_get_name(digest_algorithm_t alg)
       return "sha3-256";
     case DIGEST_SHA3_512:
       return "sha3-512";
-    default:
       // LCOV_EXCL_START
+    default:
       tor_fragile_assert();
       return "??unknown_digest??";
       // LCOV_EXCL_STOP
@@ -2447,9 +2447,10 @@ crypto_dh_new(int dh_type)
 #endif /* defined(OPENSSL_1_1_API) */
 
   return res;
- err:
+
   /* LCOV_EXCL_START
    * This error condition is only reached when an allocation fails */
+ err:
   crypto_log_errors(LOG_WARN, "creating DH object");
   if (res->dh) DH_free(res->dh); /* frees p and g too */
   tor_free(res);
diff --git a/src/common/crypto_curve25519.c b/src/common/crypto_curve25519.c
index f5c2acb87..8793fa627 100644
--- a/src/common/crypto_curve25519.c
+++ b/src/common/crypto_curve25519.c
@@ -318,8 +318,11 @@ curve25519_basepoint_spot_check(void)
   }
 
   goto end;
+ // LCOV_EXCL_START -- we can only hit this code if there is a bug in our
+ // curve25519-basepoint implementation.
  fail:
   r = -1;
+ // LCOV_EXCL_STOP
  end:
   curve25519_use_ed = save_use_ed;
   return r;
diff --git a/src/common/crypto_ed25519.c b/src/common/crypto_ed25519.c
index 969cc1047..94b23e31b 100644
--- a/src/common/crypto_ed25519.c
+++ b/src/common/crypto_ed25519.c
@@ -293,9 +293,12 @@ ed25519_sign_prefixed,(ed25519_signature_t *signature_out,
 
   prefixed_msg = get_prefixed_msg(msg, msg_len, prefix_str,
                                   &prefixed_msg_len);
-  if (!prefixed_msg) {
+  if (BUG(!prefixed_msg)) {
+    /* LCOV_EXCL_START -- only possible when the message and prefix are
+     * ridiculously huge */
     log_warn(LD_GENERAL, "Failed to get prefixed msg.");
     return -1;
+    /* LCOV_EXCL_STOP */
   }
 
   retval = ed25519_sign(signature_out,
@@ -338,9 +341,12 @@ ed25519_checksig_prefixed(const ed25519_signature_t *signature,
 
   prefixed_msg = get_prefixed_msg(msg, msg_len, prefix_str,
                                   &prefixed_msg_len);
-  if (!prefixed_msg) {
+  if (BUG(!prefixed_msg)) {
+    /* LCOV_EXCL_START -- only possible when the message and prefix are
+     * ridiculously huge */
     log_warn(LD_GENERAL, "Failed to get prefixed msg.");
     return -1;
+    /* LCOV_EXCL_STOP */
   }
 
   retval = ed25519_checksig(signature,
@@ -718,8 +724,11 @@ ed25519_impl_spot_check,(void))
    */
   goto end;
 
+ // LCOV_EXCL_START -- We can only reach this if our ed25519 implementation is
+ // broken.
  fail:
   r = -1;
+ // LCOV_EXCL_STOP
  end:
   return r;
 }
diff --git a/src/common/crypto_pwbox.c b/src/common/crypto_pwbox.c
index db8892e37..12acc9331 100644
--- a/src/common/crypto_pwbox.c
+++ b/src/common/crypto_pwbox.c
@@ -107,7 +107,6 @@ crypto_pwbox(uint8_t **out, size_t *outlen_out,
   rv = 0;
   goto out;
 
- err:
   /* LCOV_EXCL_START
 
      This error case is often unreachable if we're correctly coded, unless
@@ -123,6 +122,7 @@ crypto_pwbox(uint8_t **out, size_t *outlen_out,
        - pwbox_encoded_encode can't fail unless we're using trunnel wrong,
          or it's buggy.
    */
+ err:
   tor_free(result);
   rv = -1;
   /* LCOV_EXCL_STOP */
diff --git a/src/common/crypto_s2k.c b/src/common/crypto_s2k.c
index 4db6762ef..b2fcca54c 100644
--- a/src/common/crypto_s2k.c
+++ b/src/common/crypto_s2k.c
@@ -86,9 +86,11 @@ secret_to_key_key_len(uint8_t type)
       return DIGEST_LEN;
     case S2K_TYPE_SCRYPT:
       return DIGEST256_LEN;
+    // LCOV_EXCL_START
     default:
-      tor_fragile_assert(); // LCOV_EXCL_LINE
-      return -1;            // LCOV_EXCL_LINE
+      tor_fragile_assert();
+      return -1;
+    // LCOV_EXCL_STOP
   }
 }
 
@@ -169,9 +171,11 @@ make_specifier(uint8_t *spec_out, uint8_t type, unsigned flags)
       /* r = 8; p = 2. */
       spec_out[SCRYPT_SPEC_LEN-1] = (3u << 4) | (1u << 0);
       break;
+    // LCOV_EXCL_START - we should have returned above.
     default:
-      tor_fragile_assert(); // LCOV_EXCL_LINE - we should have returned above.
+      tor_fragile_assert();
       return S2K_BAD_ALGORITHM;
+    // LCOV_EXCL_STOP
   }
 
   return speclen;
diff --git a/src/common/tortls.c b/src/common/tortls.c
index 8727b605b..197c5e8d3 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -444,8 +444,9 @@ tor_x509_name_new(const char *cname)
     goto error;
   /* LCOV_EXCL_BR_STOP */
   return name;
- error:
+
   /* LCOV_EXCL_START : these lines will only execute on out of memory errors*/
+ error:
   X509_NAME_free(name);
   return NULL;
   /* LCOV_EXCL_STOP */
diff --git a/src/common/util.c b/src/common/util.c
index bcb1449a1..5ff7e104d 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2980,8 +2980,9 @@ unescape_string(const char *s, char **result, size_t *size_out)
         *out = '\0';
         if (size_out) *size_out = out - *result;
         return cp+1;
-      case '\0':
+
         /* LCOV_EXCL_START -- we caught this in parse_config_from_line. */
+      case '\0':
         tor_fragile_assert();
         tor_free(*result);
         return NULL;
@@ -3029,8 +3030,9 @@ unescape_string(const char *s, char **result, size_t *size_out)
             *out++ = cp[1];
             cp += 2;
             break;
-          default:
+
             /* LCOV_EXCL_START */
+          default:
             /* we caught this above in the initial loop. */
             tor_assert_nonfatal_unreached();
             tor_free(*result); return NULL;
diff --git a/src/common/util_format.c b/src/common/util_format.c
index 1f7b8b03a..e51757a4e 100644
--- a/src/common/util_format.c
+++ b/src/common/util_format.c
@@ -266,10 +266,13 @@ base64_encode(char *dest, size_t destlen, const char *src, size_t srclen,
     ENCODE_N(3);
     ENCODE_PAD();
     break;
+  // LCOV_EXCL_START -- we can't reach this point, because we enforce
+  // 0 <= ncov_idx < 3 in the loop above.
   default:
     /* Something went catastrophically wrong. */
-    tor_fragile_assert(); // LCOV_EXCL_LINE
+    tor_fragile_assert();
     return -1;
+  // LCOV_EXCL_STOP
   }
 
 #undef ENCODE_N

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits