From 5e4d53d535a3cc9903250b3df0caa829f1c5e4bf Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 26 Oct 2009 21:59:34 -0400 Subject: 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). --- src/common/crypto.c | 3 --- src/or/circuitbuild.c | 5 ++--- src/or/connection.c | 2 +- src/or/control.c | 2 +- src/or/rendcommon.c | 3 ++- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/common/crypto.c b/src/common/crypto.c index 5a39a1ab0..4c880f6b6 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -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; } diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c index 40c3a6b87..91fa9d8db 100644 --- a/src/or/circuitbuild.c +++ b/src/or/circuitbuild.c @@ -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); diff --git a/src/or/connection.c b/src/or/connection.c index ca71373f0..aca9b8b11 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -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)); diff --git a/src/or/control.c b/src/or/control.c index 0f744f7b9..d4b0bdb86 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -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); } diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c index c7eb2a9d0..9055f981b 100644 --- a/src/or/rendcommon.c +++ b/src/or/rendcommon.c @@ -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, -- cgit v1.2.3