mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Nuke uses of memcmp outside of unit tests
We want to be saying fast_mem{cmp,eq,neq} when we're doing a
comparison that's allowed to exit early, or tor_mem{cmp,eq,neq} when
we need a data-invariant timing. Direct use of memcmp tends to imply
that we haven't thought about the issue.
This commit is contained in:
+2
-1
@@ -41,6 +41,7 @@
|
||||
#include "aes.h"
|
||||
#include "util.h"
|
||||
#include "torlog.h"
|
||||
#include "di_ops.h"
|
||||
|
||||
#ifdef ANDROID
|
||||
/* Android's OpenSSL seems to have removed all of its Engine support. */
|
||||
@@ -257,7 +258,7 @@ evaluate_ctr_for_aes(void)
|
||||
for (i=0; i<16; ++i)
|
||||
AES_ctr128_encrypt(&zero[i], &output[i], 1, &key, ivec, ivec_tmp, &pos);
|
||||
|
||||
if (memcmp(output, encrypt_zero, 16)) {
|
||||
if (fast_memneq(output, encrypt_zero, 16)) {
|
||||
/* Counter mode is buggy */
|
||||
log_notice(LD_CRYPTO, "This OpenSSL has a buggy version of counter mode; "
|
||||
"not using it.");
|
||||
|
||||
+1
-1
@@ -2269,7 +2269,7 @@ compare_routerinfo_by_ip_and_bw_(const void **a, const void **b)
|
||||
else if (first->addr > second->addr)
|
||||
return 1;
|
||||
|
||||
/* Potentially, this next bit could cause k n lg n memcmp calls. But in
|
||||
/* Potentially, this next bit could cause k n lg n memeq calls. But in
|
||||
* reality, we will almost never get here, since addresses will usually be
|
||||
* different. */
|
||||
|
||||
|
||||
+4
-3
@@ -224,7 +224,8 @@ static int
|
||||
geoip_ipv6_compare_entries_(const void **_a, const void **_b)
|
||||
{
|
||||
const geoip_ipv6_entry_t *a = *_a, *b = *_b;
|
||||
return memcmp(a->ip_low.s6_addr, b->ip_low.s6_addr, sizeof(struct in6_addr));
|
||||
return fast_memcmp(a->ip_low.s6_addr, b->ip_low.s6_addr,
|
||||
sizeof(struct in6_addr));
|
||||
}
|
||||
|
||||
/** bsearch helper: return -1, 1, or 0 based on comparison of an IPv6
|
||||
@@ -235,10 +236,10 @@ geoip_ipv6_compare_key_to_entry_(const void *_key, const void **_member)
|
||||
const struct in6_addr *addr = (struct in6_addr *)_key;
|
||||
const geoip_ipv6_entry_t *entry = *_member;
|
||||
|
||||
if (memcmp(addr->s6_addr, entry->ip_low.s6_addr,
|
||||
if (fast_memcmp(addr->s6_addr, entry->ip_low.s6_addr,
|
||||
sizeof(struct in6_addr)) < 0)
|
||||
return -1;
|
||||
else if (memcmp(addr->s6_addr, entry->ip_high.s6_addr,
|
||||
else if (fast_memcmp(addr->s6_addr, entry->ip_high.s6_addr,
|
||||
sizeof(struct in6_addr)) > 0)
|
||||
return 1;
|
||||
else
|
||||
|
||||
+1
-1
@@ -479,7 +479,7 @@ microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
|
||||
if (PREDICT_UNLIKELY(
|
||||
md->bodylen < 9 || fast_memneq(md->body, "onion-key", 9) != 0)) {
|
||||
/* XXXX once bug 2022 is solved, we can kill this block and turn it
|
||||
* into just the tor_assert(!memcmp) */
|
||||
* into just the tor_assert(fast_memeq) */
|
||||
off_t avail = cache->cache_content->size - md->off;
|
||||
char *bad_str;
|
||||
tor_assert(avail >= 0);
|
||||
|
||||
+1
-1
@@ -4436,7 +4436,7 @@ update_consensus_router_descriptor_downloads(time_t now, int is_vote,
|
||||
sd->signed_descriptor_digest, DIGEST_LEN)) {
|
||||
/* We have a descriptor with this digest, but either there is no
|
||||
* entry in routerlist with the same ID (!ri), or there is one,
|
||||
* but the identity digest differs (memcmp).
|
||||
* but the identity digest differs (memneq).
|
||||
*/
|
||||
smartlist_add(no_longer_old, sd);
|
||||
++n_in_oldrouters; /* We have it in old_routers. */
|
||||
|
||||
Reference in New Issue
Block a user