diff options
author | Jakub Jelen <jjelen@redhat.com> | 2022-01-28 11:51:48 +0100 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2022-01-31 18:58:23 +0900 |
commit | 904e168bdb2ac4cbfe32db86a6cd11ab462340ad (patch) | |
tree | a5e627306fe4f094e26c4152e8b4e3d51493d04b /random | |
parent | 77512c510bf744b341d3173e65e22b9dd0b5df03 (diff) | |
download | libgcrypt-904e168bdb2ac4cbfe32db86a6cd11ab462340ad.tar.gz |
random: Avoid dereference of the ec before checking for NULL
* random/jitterentropy-noise.c (jent_memaccess): Move check before
dereferencing the pointer.
--
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Diffstat (limited to 'random')
-rw-r--r-- | random/jitterentropy-noise.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/random/jitterentropy-noise.c b/random/jitterentropy-noise.c index 75443a8f..9cb1b39f 100644 --- a/random/jitterentropy-noise.c +++ b/random/jitterentropy-noise.c @@ -189,17 +189,19 @@ static void jent_memaccess(struct rand_data *ec, uint64_t loop_cnt) uint32_t u[4]; uint8_t b[sizeof(uint32_t) * 4]; } prngState = { .u = {0x8e93eec0, 0xce65608a, 0xa8d46b46, 0xe83cef69} }; - uint32_t addressMask = ec->memmask; + uint32_t addressMask; uint64_t acc_loop_cnt; + if (NULL == ec || NULL == ec->mem) + return; + + addressMask = ec->memmask; + /* Ensure that macros cannot overflow jent_loop_shuffle() */ BUILD_BUG_ON((MAX_ACC_LOOP_BIT + MIN_ACC_LOOP_BIT) > 63); acc_loop_cnt = jent_loop_shuffle(ec, MAX_ACC_LOOP_BIT, MIN_ACC_LOOP_BIT); - if (NULL == ec || NULL == ec->mem) - return; - /* * Mix the current data into prngState * |