mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Remove checks for array existence. (CID 410..415)
In C, the code "char x[10]; if (x) {...}" always takes the true branch of the if statement. Coverity notices this now. In some cases, we were testing arrays to make sure that an operation we wanted to do would suceed. Those cases are now always-true. In some cases, we were testing arrays to see if something was _set_. Those caes are now tests for strlen(s), or tests for !tor_mem_is_zero(d,len).
This commit is contained in:
parent
cec698d29e
commit
5e4d53d535
@ -1260,9 +1260,6 @@ crypto_cipher_set_key(crypto_cipher_env_t *env, const char *key)
|
||||
tor_assert(env);
|
||||
tor_assert(key);
|
||||
|
||||
if (!env->key)
|
||||
return -1;
|
||||
|
||||
memcpy(env->key, key, CIPHER_KEY_LEN);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1015,8 +1015,7 @@ circuit_list_path_impl(origin_circuit_t *circ, int verbose, int verbose_names)
|
||||
router_get_verbose_nickname(elt, ri);
|
||||
} else if ((rs = router_get_consensus_status_by_id(id))) {
|
||||
routerstatus_get_verbose_nickname(elt, rs);
|
||||
} else if (hop->extend_info->nickname &&
|
||||
is_legal_nickname(hop->extend_info->nickname)) {
|
||||
} else if (is_legal_nickname(hop->extend_info->nickname)) {
|
||||
elt[0] = '$';
|
||||
base16_encode(elt+1, HEX_DIGEST_LEN+1, id, DIGEST_LEN);
|
||||
elt[HEX_DIGEST_LEN+1]= '~';
|
||||
@ -1228,7 +1227,7 @@ circuit_handle_first_hop(origin_circuit_t *circ)
|
||||
|
||||
if (!n_conn) {
|
||||
/* not currently connected in a useful way. */
|
||||
const char *name = firsthop->extend_info->nickname ?
|
||||
const char *name = strlen(firsthop->extend_info->nickname) ?
|
||||
firsthop->extend_info->nickname : fmt_addr(&firsthop->extend_info->addr);
|
||||
log_info(LD_CIRC, "Next router is %s: %s ", safe_str(name), msg?msg:"???");
|
||||
circ->_base.n_hop = extend_info_dup(firsthop->extend_info);
|
||||
|
@ -566,7 +566,7 @@ connection_about_to_close_connection(connection_t *conn)
|
||||
rep_hist_note_disconnect(or_conn->identity_digest, now);
|
||||
control_event_or_conn_status(or_conn, OR_CONN_EVENT_CLOSED,
|
||||
tls_error_to_orconn_end_reason(or_conn->tls_error));
|
||||
} else if (or_conn->identity_digest) {
|
||||
} else if (!tor_digest_is_zero(or_conn->identity_digest)) {
|
||||
rep_hist_note_connection_died(or_conn->identity_digest, now);
|
||||
control_event_or_conn_status(or_conn, OR_CONN_EVENT_CLOSED,
|
||||
tls_error_to_orconn_end_reason(or_conn->tls_error));
|
||||
|
@ -2263,7 +2263,7 @@ handle_control_attachstream(control_connection_t *conn, uint32_t len,
|
||||
char* exit_digest;
|
||||
if (circ->build_state &&
|
||||
circ->build_state->chosen_exit &&
|
||||
circ->build_state->chosen_exit->identity_digest) {
|
||||
!tor_digest_is_zero(circ->build_state->chosen_exit->identity_digest)) {
|
||||
exit_digest = circ->build_state->chosen_exit->identity_digest;
|
||||
r = router_get_by_digest(exit_digest);
|
||||
}
|
||||
|
@ -1245,7 +1245,8 @@ rend_cache_store_v2_desc_as_client(const char *desc,
|
||||
/* Decode/decrypt introduction points. */
|
||||
if (intro_content) {
|
||||
if (rend_query->auth_type != REND_NO_AUTH &&
|
||||
rend_query->descriptor_cookie) {
|
||||
!tor_mem_is_zero(rend_query->descriptor_cookie,
|
||||
sizeof(rend_query->descriptor_cookie))) {
|
||||
char *ipos_decrypted = NULL;
|
||||
size_t ipos_decrypted_size;
|
||||
if (rend_decrypt_introduction_points(&ipos_decrypted,
|
||||
|
Loading…
Reference in New Issue
Block a user