From ec042c3dc7de615af088a108e3af488bf72724fd Mon Sep 17 00:00:00 2001 From: ligd Date: Mon, 15 Mar 2021 17:18:38 +0800 Subject: [PATCH] crypto: fix asan report error random_pool.c:466:14: runtime error: left shift of 305919453 by 17 places cannot be represented in type 'long int' random_pool.c:178:11: runtime error: shift exponent 32 is too large for 32-bit type 'unsigned int' Change-Id: I714f42b68f4af43249946aed8537cd848e569194 Signed-off-by: ligd --- crypto/random_pool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/random_pool.c b/crypto/random_pool.c index 3c58c3b4ee..bdb109c960 100644 --- a/crypto/random_pool.c +++ b/crypto/random_pool.c @@ -175,7 +175,7 @@ static void addentropy(FAR const uint32_t *buf, size_t n, bool inc_new) uint32_t i; rotate = g_rng.rd_rotate; - w = ROTL_32(*buf, rotate); + w = rotate ? ROTL_32(*buf, rotate) : *buf; i = g_rng.rd_addptr = (g_rng.rd_addptr - 1) & POOL_MASK; /* Normal round, we add 7 bits of rotation to the pool. @@ -463,7 +463,7 @@ void up_rngaddentropy(enum rnd_source_t kindof, FAR const uint32_t *buf, */ clock_gettime(CLOCK_REALTIME, &ts); - tbuf[0] = ROTL_32(ts.tv_nsec, 17) ^ ROTL_32(ts.tv_sec, 3); + tbuf[0] = ROTL_32((uint32_t)ts.tv_nsec, 17) ^ ROTL_32(ts.tv_sec, 3); tbuf[0] += ROTL_32(kindof, 27); tbuf[0] += ROTL_32((uintptr_t)&tbuf[0], 11);