]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Remove checks for array existence. (CID 410..415)
authorNick Mathewson <nickm@torproject.org>
Tue, 27 Oct 2009 01:59:34 +0000 (21:59 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 27 Oct 2009 02:40:41 +0000 (22:40 -0400)
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
src/or/circuitbuild.c
src/or/connection.c
src/or/control.c
src/or/rendcommon.c

index 5a39a1ab0c23a2bf2604db373ba10a2d1dcbf5fa..4c880f6b6f4c1bd6a9d3d402ad9555d9eb54ce9e 100644 (file)
@@ -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;
 }
index 40c3a6b87f4de35c7e2188d9cbdfd55fec0fcb5d..91fa9d8db57d65d250866a78019ae2dd221ccf98 100644 (file)
@@ -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);
index ca71373f00a05fcd28fd28e80915665ef477aa84..aca9b8b116a0e0cc7585ac49349a2fb46224b9be 100644 (file)
@@ -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));
index 0f744f7b960a657a9b6b43858dd5bcfd54582571..d4b0bdb86639ab47d9df03b92d82fb881dc69aba 100644 (file)
@@ -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);
     }
index c7eb2a9d08214102db6ef54c9d7590ec2bbd517a..9055f981bb53900519562f820a8f26fa7b40db72 100644 (file)
@@ -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,