diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-09-15 16:40:11 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-09-15 16:40:11 -0400 |
commit | 76c33f7ff46df47df0cc880595c4d943d50f019b (patch) | |
tree | 11448ec9afd6990160ce6212c020d3c2630448d6 /src/test | |
parent | c1deabd3b0c9e2701696afc80ac8392f0efda2c7 (diff) | |
parent | a28e239b171c1a69fd32b6583bca0559f7116445 (diff) | |
download | tor-76c33f7ff46df47df0cc880595c4d943d50f019b.tar.gz tor-76c33f7ff46df47df0cc880595c4d943d50f019b.zip |
Merge branch 'scan-build-032'
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/bench.c | 1 | ||||
-rw-r--r-- | src/test/test_addr.c | 2 | ||||
-rw-r--r-- | src/test/test_config.c | 1 | ||||
-rw-r--r-- | src/test/test_consdiff.c | 19 | ||||
-rw-r--r-- | src/test/test_crypto.c | 3 | ||||
-rw-r--r-- | src/test/test_dir.c | 6 | ||||
-rw-r--r-- | src/test/test_hs_client.c | 8 | ||||
-rw-r--r-- | src/test/test_hs_common.c | 3 | ||||
-rw-r--r-- | src/test/test_hs_descriptor.c | 1 | ||||
-rw-r--r-- | src/test/test_hs_intropoint.c | 4 | ||||
-rw-r--r-- | src/test/test_hs_service.c | 16 | ||||
-rw-r--r-- | src/test/test_options.c | 6 | ||||
-rw-r--r-- | src/test/test_rendcache.c | 1 | ||||
-rw-r--r-- | src/test/test_shared_random.c | 2 | ||||
-rw-r--r-- | src/test/test_tortls.c | 1 | ||||
-rw-r--r-- | src/test/test_util.c | 3 |
16 files changed, 57 insertions, 20 deletions
diff --git a/src/test/bench.c b/src/test/bench.c index 718c0b9038..b7b123eee2 100644 --- a/src/test/bench.c +++ b/src/test/bench.c @@ -200,6 +200,7 @@ bench_onion_ntor_impl(void) curve25519_public_key_generate(&keypair2.pubkey, &keypair2.seckey); dimap_add_entry(&keymap, keypair1.pubkey.public_key, &keypair1); dimap_add_entry(&keymap, keypair2.pubkey.public_key, &keypair2); + crypto_rand((char *)nodeid, sizeof(nodeid)); reset_perftime(); start = perftime(); diff --git a/src/test/test_addr.c b/src/test/test_addr.c index 9cf497f874..e1a40b7e60 100644 --- a/src/test/test_addr.c +++ b/src/test/test_addr.c @@ -760,7 +760,9 @@ test_addr_ip6_helpers(void *arg) /* get interface addresses */ r = get_interface_address6(LOG_DEBUG, AF_INET, &t1); + tt_int_op(r, OP_LE, 0); // "it worked or it didn't" i = get_interface_address6(LOG_DEBUG, AF_INET6, &t2); + tt_int_op(i, OP_LE, 0); // "it worked or it didn't" TT_BLATHER(("v4 address: %s (family=%d)", fmt_addr(&t1), tor_addr_family(&t1))); diff --git a/src/test/test_config.c b/src/test/test_config.c index e154127dc2..9351f41653 100644 --- a/src/test/test_config.c +++ b/src/test/test_config.c @@ -704,6 +704,7 @@ test_config_parse_transport_plugin_line(void *arg) tt_int_op(r, OP_LT, 0); r = parse_transport_line(options, "transport_1,transport_2 proxy 1.2.3.4:567", 1, 1); + tt_int_op(r, OP_LT, 0); /* No port error exit */ r = parse_transport_line(options, "transport_1 socks5 1.2.3.4", 1, 0); diff --git a/src/test/test_consdiff.c b/src/test/test_consdiff.c index 5188e04e4d..fda3a7f186 100644 --- a/src/test/test_consdiff.c +++ b/src/test/test_consdiff.c @@ -19,28 +19,29 @@ test_consdiff_smartlist_slice(void *arg) { smartlist_t *sl = smartlist_new(); smartlist_slice_t *sls; + int items[6] = {0,0,0,0,0,0}; /* Create a regular smartlist. */ (void)arg; - smartlist_add(sl, (void*)1); - smartlist_add(sl, (void*)2); - smartlist_add(sl, (void*)3); - smartlist_add(sl, (void*)4); - smartlist_add(sl, (void*)5); + smartlist_add(sl, &items[1]); + smartlist_add(sl, &items[2]); + smartlist_add(sl, &items[3]); + smartlist_add(sl, &items[4]); + smartlist_add(sl, &items[5]); /* See if the slice was done correctly. */ sls = smartlist_slice(sl, 2, 5); tt_ptr_op(sl, OP_EQ, sls->list); - tt_ptr_op((void*)3, OP_EQ, smartlist_get(sls->list, sls->offset)); - tt_ptr_op((void*)5, OP_EQ, + tt_ptr_op(&items[3], OP_EQ, smartlist_get(sls->list, sls->offset)); + tt_ptr_op(&items[5], OP_EQ, smartlist_get(sls->list, sls->offset + (sls->len-1))); tor_free(sls); /* See that using -1 as the end does get to the last element. */ sls = smartlist_slice(sl, 2, -1); tt_ptr_op(sl, OP_EQ, sls->list); - tt_ptr_op((void*)3, OP_EQ, smartlist_get(sls->list, sls->offset)); - tt_ptr_op((void*)5, OP_EQ, + tt_ptr_op(&items[3], OP_EQ, smartlist_get(sls->list, sls->offset)); + tt_ptr_op(&items[5], OP_EQ, smartlist_get(sls->list, sls->offset + (sls->len-1))); done: diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c index 18778b5e38..c8443fd3bb 100644 --- a/src/test/test_crypto.c +++ b/src/test/test_crypto.c @@ -1406,6 +1406,7 @@ test_crypto_digests(void *arg) AUTHORITY_SIGNKEY_A_DIGEST, HEX_DIGEST_LEN); r = crypto_pk_get_common_digests(k, &pkey_digests); + tt_int_op(r, OP_EQ, 0); tt_mem_op(hex_str(pkey_digests.d[DIGEST_SHA1], DIGEST_LEN),OP_EQ, AUTHORITY_SIGNKEY_A_DIGEST, HEX_DIGEST_LEN); @@ -2594,6 +2595,8 @@ test_crypto_ed25519_testvectors(void *arg) ed25519_signature_t sig; int sign; + memset(&curvekp, 0xd0, sizeof(curvekp)); + #define DECODE(p,s) base16_decode((char*)(p),sizeof(p),(s),strlen(s)) #define EQ(a,h) test_memeq_hex((const char*)(a), (h)) diff --git a/src/test/test_dir.c b/src/test/test_dir.c index 81ba5f66c4..2d48cfc3c4 100644 --- a/src/test/test_dir.c +++ b/src/test/test_dir.c @@ -2252,6 +2252,7 @@ test_dir_networkstatus_compute_bw_weights_v10(void *arg) tt_i64_op(G+M+E+D, OP_EQ, T); ret = networkstatus_compute_bw_weights_v10(chunks, G, M, E, D, T, weight_scale); + tt_assert(ret); tt_str_op(smartlist_get(chunks, 0), OP_EQ, "bandwidth-weights Wbd=883 Wbe=0 " "Wbg=3673 Wbm=10000 Wdb=10000 Web=10000 Wed=8233 Wee=10000 Weg=8233 " "Wem=10000 Wgb=10000 Wgd=883 Wgg=6327 Wgm=6327 Wmb=10000 Wmd=883 Wme=0 " @@ -2268,6 +2269,7 @@ test_dir_networkstatus_compute_bw_weights_v10(void *arg) tt_i64_op(G+M+E+D, OP_EQ, T); ret = networkstatus_compute_bw_weights_v10(chunks, G, M, E, D, T, weight_scale); + tt_assert(ret); tt_str_op(smartlist_get(chunks, 0), OP_EQ, "bandwidth-weights Wbd=0 Wbe=0 " "Wbg=4194 Wbm=10000 Wdb=10000 Web=10000 Wed=10000 Wee=10000 Weg=10000 " "Wem=10000 Wgb=10000 Wgd=0 Wgg=5806 Wgm=5806 Wmb=10000 Wmd=0 Wme=0 " @@ -2284,6 +2286,7 @@ test_dir_networkstatus_compute_bw_weights_v10(void *arg) tt_i64_op(G+M+E+D, OP_EQ, T); ret = networkstatus_compute_bw_weights_v10(chunks, G, M, E, D, T, weight_scale); + tt_assert(ret); tt_str_op(smartlist_get(chunks, 0), OP_EQ, "bandwidth-weights Wbd=317 " "Wbe=5938 Wbg=0 Wbm=10000 Wdb=10000 Web=10000 Wed=9366 Wee=4061 " "Weg=9366 Wem=4061 Wgb=10000 Wgd=317 Wgg=10000 Wgm=10000 Wmb=10000 " @@ -2304,6 +2307,7 @@ test_dir_networkstatus_compute_bw_weights_v10(void *arg) "Wbe=0 Wbg=0 Wbm=10000 Wdb=10000 Web=10000 Wed=3333 Wee=10000 Weg=3333 " "Wem=10000 Wgb=10000 Wgd=3333 Wgg=10000 Wgm=10000 Wmb=10000 Wmd=3333 " "Wme=0 Wmg=0 Wmm=10000\n"); + tt_assert(ret); done: SMARTLIST_FOREACH(chunks, char *, cp, tor_free(cp)); @@ -3366,7 +3370,7 @@ mock_get_options(void) static void reset_routerstatus(routerstatus_t *rs, const char *hex_identity_digest, - int32_t ipv4_addr) + uint32_t ipv4_addr) { memset(rs, 0, sizeof(routerstatus_t)); base16_decode(rs->identity_digest, sizeof(rs->identity_digest), diff --git a/src/test/test_hs_client.c b/src/test/test_hs_client.c index 16b2d604fd..38878d6ed5 100644 --- a/src/test/test_hs_client.c +++ b/src/test/test_hs_client.c @@ -218,7 +218,8 @@ test_e2e_rend_circuit_setup_legacy(void *arg) done: connection_free_(conn); - tor_free(TO_CIRCUIT(or_circ)->n_chan); + if (or_circ) + tor_free(TO_CIRCUIT(or_circ)->n_chan); circuit_free(TO_CIRCUIT(or_circ)); } @@ -227,7 +228,7 @@ static void test_e2e_rend_circuit_setup(void *arg) { uint8_t ntor_key_seed[DIGEST256_LEN] = {0}; - origin_circuit_t *or_circ; + origin_circuit_t *or_circ = NULL; int retval; connection_t *conn = NULL; @@ -287,7 +288,8 @@ test_e2e_rend_circuit_setup(void *arg) done: connection_free_(conn); - tor_free(TO_CIRCUIT(or_circ)->n_chan); + if (or_circ) + tor_free(TO_CIRCUIT(or_circ)->n_chan); circuit_free(TO_CIRCUIT(or_circ)); } diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c index 2d63dff250..22fed12f1e 100644 --- a/src/test/test_hs_common.c +++ b/src/test/test_hs_common.c @@ -716,6 +716,7 @@ test_hid_serv_request_tracker(void *arg) /* Add another request with very short key */ retval = hs_lookup_last_hid_serv_request(hsdir, "l", now, 1); + tt_int_op(retval, OP_EQ, now); tt_int_op(strmap_size(request_tracker),OP_EQ, 3); /* Try deleting entries with a dummy key. Check that our previous requests @@ -1588,7 +1589,7 @@ helper_test_hsdir_sync(networkstatus_t *ns, tt_int_op(smartlist_len(desc->previous_hsdirs), OP_EQ, 6); /* 3) Initialize client time */ - now = helper_set_consensus_and_system_time(ns, client_position); + helper_set_consensus_and_system_time(ns, client_position); cleanup_nodelist(); SMARTLIST_FOREACH(ns->routerstatus_list, diff --git a/src/test/test_hs_descriptor.c b/src/test/test_hs_descriptor.c index 7f0d1dd189..9ec183db06 100644 --- a/src/test/test_hs_descriptor.c +++ b/src/test/test_hs_descriptor.c @@ -90,6 +90,7 @@ test_cert_encoding(void *arg) pos += b64_cert_len; tt_int_op(strcmpstart(pos, "-----END ED25519 CERT-----"), OP_EQ, 0); pos += strlen("-----END ED25519 CERT-----"); + tt_str_op(pos, OP_EQ, ""); } done: diff --git a/src/test/test_hs_intropoint.c b/src/test/test_hs_intropoint.c index 2cce8a3703..1e570630c0 100644 --- a/src/test/test_hs_intropoint.c +++ b/src/test/test_hs_intropoint.c @@ -783,7 +783,7 @@ static void test_received_introduce1_handling(void *arg) { int ret; - uint8_t *request = NULL, buf[128]; + uint8_t *request = NULL, buf[128];; trn_cell_introduce1_t *cell = NULL; or_circuit_t *circ = NULL; @@ -796,6 +796,7 @@ test_received_introduce1_handling(void *arg) /* Too small request length. An INTRODUCE1 expect at the very least a * DIGEST_LEN size. */ { + memset(buf, 0, sizeof(buf)); circ = helper_create_intro_circuit(); ret = hs_intro_received_introduce1(circ, buf, DIGEST_LEN - 1); tt_int_op(ret, OP_EQ, -1); @@ -809,6 +810,7 @@ test_received_introduce1_handling(void *arg) { circ = helper_create_intro_circuit(); uint8_t test[2]; /* Too small request. */ + memset(test, 0, sizeof(test)); ret = handle_introduce1(circ, test, sizeof(test)); tor_free(circ->p_chan); circuit_free(TO_CIRCUIT(circ)); diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c index 05ced17ff7..ca6af43ba7 100644 --- a/src/test/test_hs_service.c +++ b/src/test/test_hs_service.c @@ -425,7 +425,7 @@ test_service_intro_point(void *arg) /* Test functions that uses a service intropoints map with that previously * created object (non legacy). */ { - uint8_t garbage[DIGEST256_LEN] = {0}; + ed25519_public_key_t garbage = { {0} }; hs_service_intro_point_t *query; service = hs_service_new(get_options()); @@ -436,8 +436,7 @@ test_service_intro_point(void *arg) service_intro_point_add(service->desc_current->intro_points.map, ip); query = service_intro_point_find(service, &ip->auth_key_kp.pubkey); tt_mem_op(query, OP_EQ, ip, sizeof(hs_service_intro_point_t)); - query = service_intro_point_find(service, - (const ed25519_public_key_t *) garbage); + query = service_intro_point_find(service, &garbage); tt_ptr_op(query, OP_EQ, NULL); /* While at it, can I find the descriptor with the intro point? */ @@ -677,6 +676,8 @@ test_intro_established(void *arg) circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_S_ESTABLISH_INTRO, flags); + tt_assert(circ); + /* Test a wrong purpose. */ TO_CIRCUIT(circ)->purpose = CIRCUIT_PURPOSE_S_INTRO; setup_full_capture_of_logs(LOG_WARN); @@ -724,7 +725,8 @@ test_intro_established(void *arg) tt_int_op(TO_CIRCUIT(circ)->purpose, OP_EQ, CIRCUIT_PURPOSE_S_INTRO); done: - circuit_free(TO_CIRCUIT(circ)); + if (circ) + circuit_free(TO_CIRCUIT(circ)); hs_free_all(); UNMOCK(circuit_mark_for_close_); } @@ -793,6 +795,7 @@ test_introduce2(void *arg) dummy_state = tor_malloc_zero(sizeof(or_state_t)); circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_S_INTRO, flags); + tt_assert(circ); /* Test a wrong purpose. */ TO_CIRCUIT(circ)->purpose = CIRCUIT_PURPOSE_S_ESTABLISH_INTRO; @@ -844,7 +847,8 @@ test_introduce2(void *arg) done: or_state_free(dummy_state); dummy_state = NULL; - circuit_free(TO_CIRCUIT(circ)); + if (circ) + circuit_free(TO_CIRCUIT(circ)); hs_free_all(); UNMOCK(circuit_mark_for_close_); } @@ -1264,6 +1268,7 @@ test_upload_descriptors(void *arg) ret = parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC", &mock_ns.valid_after); + tt_int_op(ret, OP_EQ, 0); ret = parse_rfc1123_time("Sat, 26 Oct 1985 14:00:00 UTC", &mock_ns.fresh_until); tt_int_op(ret, OP_EQ, 0); @@ -1339,6 +1344,7 @@ test_revision_counter_state(void *arg) &desc_two->blinded_kp.pubkey, &service_found); tt_int_op(service_found, OP_EQ, 0); + tt_u64_op(cached_rev_counter, OP_EQ, 0); /* Now let's try with the right pubkeys */ cached_rev_counter =check_state_line_for_service_rev_counter(state_line_one, diff --git a/src/test/test_options.c b/src/test/test_options.c index 6e7ff8f682..bb5cf685de 100644 --- a/src/test/test_options.c +++ b/src/test/test_options.c @@ -659,6 +659,7 @@ test_options_validate__logs(void *ignored) tt_str_op(tdata->opt->Logs->key, OP_EQ, "Log"); tt_str_op(tdata->opt->Logs->value, OP_EQ, "notice stdout"); tor_free(msg); + tt_int_op(ret, OP_EQ, -1); free_options_test_data(tdata); tdata = get_options_test_data(""); @@ -669,6 +670,7 @@ test_options_validate__logs(void *ignored) tt_str_op(tdata->opt->Logs->key, OP_EQ, "Log"); tt_str_op(tdata->opt->Logs->value, OP_EQ, "warn stdout"); tor_free(msg); + tt_int_op(ret, OP_EQ, -1); free_options_test_data(tdata); tdata = get_options_test_data(""); @@ -678,6 +680,7 @@ test_options_validate__logs(void *ignored) ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg); tt_assert(!tdata->opt->Logs); tor_free(msg); + tt_int_op(ret, OP_EQ, -1); free_options_test_data(tdata); tdata = get_options_test_data(""); @@ -686,6 +689,7 @@ test_options_validate__logs(void *ignored) ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 1, &msg); tt_assert(!tdata->opt->Logs); tor_free(msg); + tt_int_op(ret, OP_EQ, -1); free_options_test_data(tdata); tdata = get_options_test_data(""); @@ -694,6 +698,7 @@ test_options_validate__logs(void *ignored) ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg); tt_assert(!tdata->opt->Logs); tor_free(msg); + tt_int_op(ret, OP_EQ, -1); free_options_test_data(tdata); tdata = get_options_test_data(""); @@ -703,6 +708,7 @@ test_options_validate__logs(void *ignored) tdata->opt->Logs = cl; ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg); tt_int_op((intptr_t)tdata->opt->Logs, OP_EQ, (intptr_t)cl); + tt_int_op(ret, OP_EQ, -1); done: quiet_level = orig_quiet_level; diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c index 0db52292c7..9354dd0480 100644 --- a/src/test/test_rendcache.c +++ b/src/test/test_rendcache.c @@ -58,6 +58,7 @@ test_rend_cache_lookup_entry(void *data) tt_int_op(ret, OP_EQ, 0); ret = rend_cache_lookup_entry(service_id, 2, &entry); + tt_int_op(ret, OP_EQ, 0); tt_assert(entry); tt_int_op(entry->len, OP_EQ, strlen(desc_holder->desc_str)); tt_str_op(entry->desc, OP_EQ, desc_holder->desc_str); diff --git a/src/test/test_shared_random.c b/src/test/test_shared_random.c index 4c303cbb35..a9d58e6b8b 100644 --- a/src/test/test_shared_random.c +++ b/src/test/test_shared_random.c @@ -1231,6 +1231,8 @@ test_keep_commit(void *arg) state = get_sr_state(); } + crypto_rand((char*)fp, sizeof(fp)); + /* Test this very important function that tells us if we should keep a * commit or not in our state. Most of it depends on the phase and what's * in the commit so we'll change the commit as we go. */ diff --git a/src/test/test_tortls.c b/src/test/test_tortls.c index d9f1ebdd89..d04a767170 100644 --- a/src/test/test_tortls.c +++ b/src/test/test_tortls.c @@ -1378,6 +1378,7 @@ test_tortls_evaluate_ecgroup_for_tls(void *ignored) ret = evaluate_ecgroup_for_tls("P224"); // tt_int_op(ret, OP_EQ, 1); This varies between machines + tt_assert(ret == 0 || ret == 1); done: (void)0; diff --git a/src/test/test_util.c b/src/test/test_util.c index 1a74473898..db629bcb6b 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -2179,10 +2179,13 @@ test_util_parse_integer(void *arg) tt_int_op(1,OP_EQ, i); tt_assert(DBL_TO_U64(d) == 0); d = tor_parse_double(" ", 0, (double)UINT64_MAX,&i,NULL); + tt_double_op(fabs(d), OP_LT, 1e-10); tt_int_op(0,OP_EQ, i); d = tor_parse_double(".0a", 0, (double)UINT64_MAX,&i,NULL); + tt_double_op(fabs(d), OP_LT, 1e-10); tt_int_op(0,OP_EQ, i); d = tor_parse_double(".0a", 0, (double)UINT64_MAX,&i,&cp); + tt_double_op(fabs(d), OP_LT, 1e-10); tt_int_op(1,OP_EQ, i); d = tor_parse_double("-.0", 0, (double)UINT64_MAX,&i,NULL); tt_int_op(1,OP_EQ, i); |