aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/c_src/crypto_callback.c
diff options
context:
space:
mode:
authorDoug Hogan <[email protected]>2019-01-04 00:24:10 -0800
committerDoug Hogan <[email protected]>2019-01-08 01:11:58 -0800
commita8382439ac61e942bd36c228e533864814f53666 (patch)
tree16d8129a0fee46df774d2c461928eab0d3a12c39 /lib/crypto/c_src/crypto_callback.c
parentc1c98585b05f82a41d81aa24b20936be931a7082 (diff)
downloadotp-a8382439ac61e942bd36c228e533864814f53666.tar.gz
otp-a8382439ac61e942bd36c228e533864814f53666.tar.bz2
otp-a8382439ac61e942bd36c228e533864814f53666.zip
Revamp get_crypto_callbacks()
* Add sanity overflow check
Diffstat (limited to 'lib/crypto/c_src/crypto_callback.c')
-rw-r--r--lib/crypto/c_src/crypto_callback.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/crypto/c_src/crypto_callback.c b/lib/crypto/c_src/crypto_callback.c
index dda8b32deb..ed5a1a6226 100644
--- a/lib/crypto/c_src/crypto_callback.c
+++ b/lib/crypto/c_src/crypto_callback.c
@@ -171,19 +171,26 @@ DLLEXPORT struct crypto_callbacks* get_crypto_callbacks(int nlocks)
#ifdef OPENSSL_THREADS
if (nlocks > 0) {
int i;
- lock_vec = enif_alloc(nlocks*sizeof(*lock_vec));
- if (lock_vec==NULL) return NULL;
- memset(lock_vec, 0, nlocks*sizeof(*lock_vec));
-
+
+ if ((size_t)nlocks > SIZE_MAX / sizeof(*lock_vec))
+ goto err;
+ if ((lock_vec = enif_alloc((size_t)nlocks * sizeof(*lock_vec))) == NULL)
+ goto err;
+
+ memset(lock_vec, 0, (size_t)nlocks * sizeof(*lock_vec));
+
for (i=nlocks-1; i>=0; --i) {
- lock_vec[i] = enif_rwlock_create("crypto_stat");
- if (lock_vec[i]==NULL) return NULL;
+ if ((lock_vec[i] = enif_rwlock_create("crypto_stat")) == NULL)
+ goto err;
}
}
#endif
is_initialized = 1;
}
return &the_struct;
+
+ err:
+ return NULL;
}
#ifdef HAVE_DYNAMIC_CRYPTO_LIB