aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Hogan <[email protected]>2019-01-03 19:27:59 -0800
committerDoug Hogan <[email protected]>2019-01-08 00:08:22 -0800
commite084364e9e41cbc1933a5c0646ce6ad42f4ff8d1 (patch)
tree744289311e538529c89869226bd9375af72f6902
parent96787650f6616db15b737627fff66feaf63a4f69 (diff)
downloadotp-e084364e9e41cbc1933a5c0646ce6ad42f4ff8d1.tar.gz
otp-e084364e9e41cbc1933a5c0646ce6ad42f4ff8d1.tar.bz2
otp-e084364e9e41cbc1933a5c0646ce6ad42f4ff8d1.zip
Revamp rand_seed_nif()
* Bounds check before casting.
-rw-r--r--lib/crypto/c_src/rand.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/crypto/c_src/rand.c b/lib/crypto/c_src/rand.c
index 4f3c8dd500..dd1a7a1600 100644
--- a/lib/crypto/c_src/rand.c
+++ b/lib/crypto/c_src/rand.c
@@ -130,12 +130,19 @@ ERL_NIF_TERM rand_uniform_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[
}
ERL_NIF_TERM rand_seed_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
-{
+{/* (Seed) */
ErlNifBinary seed_bin;
+ if (argc != 1)
+ goto bad_arg;
if (!enif_inspect_binary(env, argv[0], &seed_bin))
- return enif_make_badarg(env);
- RAND_seed(seed_bin.data,seed_bin.size);
+ goto bad_arg;
+ if (seed_bin.size > INT_MAX)
+ goto bad_arg;
+
+ RAND_seed(seed_bin.data, (int)seed_bin.size);
return atom_ok;
-}
+ bad_arg:
+ return enif_make_badarg(env);
+}