mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Try to fix new coverity warnings in unit tests.
This commit is contained in:
+6
-3
@@ -473,18 +473,19 @@ bench_digest(void)
|
||||
for (int i = 0; lens[i] > 0; ++i) {
|
||||
reset_perftime();
|
||||
start = perftime();
|
||||
int failures = 0;
|
||||
for (int j = 0; j < N; ++j) {
|
||||
switch (alg) {
|
||||
case DIGEST_SHA1:
|
||||
crypto_digest(out, buf, lens[i]);
|
||||
failures += crypto_digest(out, buf, lens[i]) < 0;
|
||||
break;
|
||||
case DIGEST_SHA256:
|
||||
case DIGEST_SHA3_256:
|
||||
crypto_digest256(out, buf, lens[i], alg);
|
||||
failures += crypto_digest256(out, buf, lens[i], alg) < 0;
|
||||
break;
|
||||
case DIGEST_SHA512:
|
||||
case DIGEST_SHA3_512:
|
||||
crypto_digest512(out, buf, lens[i], alg);
|
||||
failures += crypto_digest512(out, buf, lens[i], alg) < 0;
|
||||
break;
|
||||
default:
|
||||
tor_assert(0);
|
||||
@@ -494,6 +495,8 @@ bench_digest(void)
|
||||
printf("%s(%d): %.2f ns per call\n",
|
||||
crypto_digest_algorithm_get_name(alg),
|
||||
lens[i], NANOCOUNT(start,end,N));
|
||||
if (failures)
|
||||
printf("ERROR: crypto_digest failed %d times.\n", failures);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ test_crypto_dh(void *arg)
|
||||
dh1_dup = crypto_dh_dup(dh1);
|
||||
s1len = crypto_dh_compute_secret(LOG_WARN, dh1_dup, p2, DH1024_KEY_LEN,
|
||||
s1, 50);
|
||||
tt_i64_op(s1len, OP_GE, 0);
|
||||
tt_mem_op(s1,OP_EQ, s2, s1len);
|
||||
|
||||
{
|
||||
|
||||
@@ -110,7 +110,11 @@ read_cert_from(const char *str)
|
||||
{
|
||||
size_t len = strlen(str);
|
||||
uint8_t *raw_cert = tor_malloc(len);
|
||||
size_t true_len = pem_decode(raw_cert, len, str, len, "CERTIFICATE");
|
||||
ssize_t true_len = pem_decode(raw_cert, len, str, len, "CERTIFICATE");
|
||||
if (true_len < 0) {
|
||||
tor_free(raw_cert);
|
||||
return NULL;
|
||||
}
|
||||
tor_x509_cert_t *cert = tor_x509_cert_decode(raw_cert, true_len);
|
||||
tor_free(raw_cert);
|
||||
if (! cert) {
|
||||
|
||||
@@ -91,9 +91,11 @@ test_x509_consume_ec_cert(void *arg)
|
||||
"+FSPvQIhAM7kY9Tlt0ELmyMnORPp1VJieXn/qhL5VoxGxSedTbny\n";
|
||||
const time_t now = 1535045321; /* when I'm writing this test. */
|
||||
tor_x509_cert_t *cert = cert_from_der64(certificate);
|
||||
crypto_pk_t *key = NULL;
|
||||
tt_assert(cert);
|
||||
|
||||
tt_ptr_op(NULL, OP_EQ, tor_tls_cert_get_key(cert));
|
||||
key = tor_tls_cert_get_key(cert);
|
||||
tt_ptr_op(NULL, OP_EQ, key); // Can't get an RSA key out of an EC cert.
|
||||
|
||||
/* It's a self-signed cert -- make sure it signed itself. */
|
||||
tt_assert(tor_tls_cert_is_valid(LOG_ERR, cert, cert, now, 0));
|
||||
@@ -105,6 +107,7 @@ test_x509_consume_ec_cert(void *arg)
|
||||
|
||||
done:
|
||||
tor_x509_cert_free(cert);
|
||||
crypto_pk_free(key);
|
||||
teardown_capture_of_logs();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user