summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-10-26 21:59:34 -0400
committerNick Mathewson <nickm@torproject.org>2009-10-26 22:40:41 -0400
commit5e4d53d535a3cc9903250b3df0caa829f1c5e4bf (patch)
treedcbab7d722ce4d818f6666365ac3d6aecdf9df24
parentcec698d29ed51ed219f907e12538e6945e535e4a (diff)
downloadtor-5e4d53d535a3cc9903250b3df0caa829f1c5e4bf.tar.gz
tor-5e4d53d535a3cc9903250b3df0caa829f1c5e4bf.zip
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).
-rw-r--r--src/common/crypto.c3
-rw-r--r--src/or/circuitbuild.c5
-rw-r--r--src/or/connection.c2
-rw-r--r--src/or/control.c2
-rw-r--r--src/or/rendcommon.c3
5 files changed, 6 insertions, 9 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 5a39a1ab0c..4c880f6b6f 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 40c3a6b87f..91fa9d8db5 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 ca71373f00..aca9b8b116 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 0f744f7b96..d4b0bdb866 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 c7eb2a9d08..9055f981bb 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,