From: Vsevolod Stakhov Date: Fri, 15 Jan 2016 16:11:53 +0000 (+0000) Subject: Add workaround for bug in valgrind and rdrand X-Git-Tag: 1.1.0~28 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=248d1ceb588fd27efe424dbd40fa1a779d6529c2;p=rspamd.git Add workaround for bug in valgrind and rdrand --- diff --git a/contrib/libottery/ottery_entropy_rdrand.c b/contrib/libottery/ottery_entropy_rdrand.c index 62e158c83..c5f12609b 100644 --- a/contrib/libottery/ottery_entropy_rdrand.c +++ b/contrib/libottery/ottery_entropy_rdrand.c @@ -19,6 +19,7 @@ defined(_M_IX86) || \ defined(__INTEL_COMPILER) +extern int ottery_valgrind_; /** Helper: invoke the RDRAND instruction to get 4 random bytes in the output * value. Return 0 on success, and an error on failure. */ static int @@ -39,7 +40,7 @@ ottery_get_entropy_rdrand(const struct ottery_entropy_config *cfg, uint32_t *up = (uint32_t *) out; (void) cfg; (void) state; - if (! (ottery_get_cpu_capabilities_() & OTTERY_CPUCAP_RAND)) + if (! (ottery_get_cpu_capabilities_() & OTTERY_CPUCAP_RAND) || ottery_valgrind_) return OTTERY_ERR_INIT_STRONG_RNG; while (outlen >= 4) { if ((err = rdrand(up))) diff --git a/contrib/libottery/ottery_global.c b/contrib/libottery/ottery_global.c index 3c814f5ec..6bd205b4f 100644 --- a/contrib/libottery/ottery_global.c +++ b/contrib/libottery/ottery_global.c @@ -20,6 +20,7 @@ /** Flag: true iff ottery_global_state_ is initialized. */ static int ottery_global_state_initialized_ = 0; +int ottery_valgrind_ = 0; /** A global state to use for the ottery_* functions that don't take a * state. */ static struct ottery_state ottery_global_state_; @@ -41,6 +42,9 @@ ottery_init(const struct ottery_config *cfg) int n = ottery_st_init(&ottery_global_state_, cfg); if (n == 0) ottery_global_state_initialized_ = 1; + if (getenv("VALGRIND")) { + ottery_valgrind_ = 1; + } return n; }