summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-09-28 09:25:17 -0400
committerNick Mathewson <nickm@torproject.org>2017-09-28 09:25:17 -0400
commita64d79ca4c5699be161a54d94e0e6c0f7d06db7c (patch)
tree5d0fa776b824fe9bd30014e92259c7d0805b3e34
parent9727a9248a474909c0ad53be9d55cd39b69d0611 (diff)
downloadtor-a64d79ca4c5699be161a54d94e0e6c0f7d06db7c.tar.gz
tor-a64d79ca4c5699be161a54d94e0e6c0f7d06db7c.zip
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.
-rw-r--r--src/common/address.c10
-rw-r--r--src/common/compat.c2
-rw-r--r--src/common/compress.c3
-rw-r--r--src/common/compress_lzma.c8
-rw-r--r--src/common/crypto.c5
-rw-r--r--src/common/crypto_curve25519.c3
-rw-r--r--src/common/crypto_ed25519.c13
-rw-r--r--src/common/crypto_pwbox.c2
-rw-r--r--src/common/crypto_s2k.c10
-rw-r--r--src/common/tortls.c3
-rw-r--r--src/common/util.c6
-rw-r--r--src/common/util_format.c5
12 files changed, 50 insertions, 20 deletions
diff --git a/src/common/address.c b/src/common/address.c
index aa61b5423b..dbe129be59 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 ab1fbc64fe..7fe97488e3 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 472268a439..110eb65867 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 2bdbbe1d45..6426ede4fd 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 1730619f83..6fe3c661c8 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 f5c2acb877..8793fa6274 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 969cc1047b..94b23e31b9 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 db8892e376..12acc9331c 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 4db6762ef7..b2fcca54c4 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 8727b605b3..197c5e8d3b 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 bcb1449a18..5ff7e104d6 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 1f7b8b03aa..e51757a4e8 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