Skip to content

Commit

Permalink
Add locking to CRYPTO_secure_used
Browse files Browse the repository at this point in the history
Coverity issue 1551719 noted CRYPTO_secure_used referenced a shared
variable without taking the appropriate read lock.  Add that.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from #22802)

(cherry picked from commit 7eae6ee)
  • Loading branch information
nhorman committed Dec 1, 2023
1 parent f766869 commit e934d62
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crypto/mem_sec.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,17 @@ int CRYPTO_secure_allocated(const void *ptr)

size_t CRYPTO_secure_used(void)
{
size_t ret = 0;

#ifndef OPENSSL_NO_SECURE_MEMORY
return secure_mem_used;
#else
return 0;
if (!CRYPTO_THREAD_read_lock(sec_malloc_lock))
return 0;

ret = secure_mem_used;

CRYPTO_THREAD_unlock(sec_malloc_lock);
#endif /* OPENSSL_NO_SECURE_MEMORY */
return ret;
}

size_t CRYPTO_secure_actual_size(void *ptr)
Expand Down

0 comments on commit e934d62

Please sign in to comment.