diff options
author | Doug Hogan <[email protected]> | 2019-01-03 17:51:25 -0800 |
---|---|---|
committer | Doug Hogan <[email protected]> | 2019-01-08 00:08:22 -0800 |
commit | 6b9ad247b06449d415e3085c20a2d2978d8ad981 (patch) | |
tree | 820402084c178647e7d63106f408238a9a7fddd4 /lib/crypto/c_src/rc4.c | |
parent | b276e51d590985b7596f77c28ea8ab6d23f1d8b5 (diff) | |
download | otp-6b9ad247b06449d415e3085c20a2d2978d8ad981.tar.gz otp-6b9ad247b06449d415e3085c20a2d2978d8ad981.tar.bz2 otp-6b9ad247b06449d415e3085c20a2d2978d8ad981.zip |
Revamp rc4_set_key()
* Bounds check key.size before casting.
Diffstat (limited to 'lib/crypto/c_src/rc4.c')
-rw-r--r-- | lib/crypto/c_src/rc4.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/crypto/c_src/rc4.c b/lib/crypto/c_src/rc4.c index 483c87b04b..d5b32d88bd 100644 --- a/lib/crypto/c_src/rc4.c +++ b/lib/crypto/c_src/rc4.c @@ -25,15 +25,27 @@ ERL_NIF_TERM rc4_set_key(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) #ifndef OPENSSL_NO_RC4 ErlNifBinary key; ERL_NIF_TERM ret; + RC4_KEY *rc4_key; CHECK_NO_FIPS_MODE(); - if (!enif_inspect_iolist_as_binary(env,argv[0], &key)) { - return enif_make_badarg(env); - } - RC4_set_key((RC4_KEY*)enif_make_new_binary(env, sizeof(RC4_KEY), &ret), - key.size, key.data); + if (argc != 1) + goto bad_arg; + if (!enif_inspect_iolist_as_binary(env, argv[0], &key)) + goto bad_arg; + if (key.size > INT_MAX) + goto bad_arg; + + if ((rc4_key = (RC4_KEY*)enif_make_new_binary(env, sizeof(RC4_KEY), &ret)) == NULL) + goto err; + + RC4_set_key(rc4_key, (int)key.size, key.data); return ret; + + bad_arg: + err: + return enif_make_badarg(env); + #else return enif_raise_exception(env, atom_notsup); #endif |