diff options
author | Erlang/OTP <[email protected]> | 2018-08-09 17:28:31 +0200 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2018-08-09 17:28:31 +0200 |
commit | a076883bc29832dc6f2c2a465781440abf4effdb (patch) | |
tree | 8f78aa0c660c1a0fbe29f7dfd2688156cd5f35a6 | |
parent | 4800273fc10934eac12411f7b613a57c76262157 (diff) | |
parent | 806a409df7cf2b07a39b3876fd36099579df126a (diff) | |
download | otp-a076883bc29832dc6f2c2a465781440abf4effdb.tar.gz otp-a076883bc29832dc6f2c2a465781440abf4effdb.tar.bz2 otp-a076883bc29832dc6f2c2a465781440abf4effdb.zip |
Merge branch 'john/crypto/fix-segfault-on-badarg/OTP-15194/ERL-673' into maint-20
* john/crypto/fix-segfault-on-badarg/OTP-15194/ERL-673:
crypto: Fix crash in compute_key(ecdh, ...) on badarg
-rw-r--r-- | lib/crypto/c_src/crypto.c | 2 | ||||
-rw-r--r-- | lib/crypto/test/crypto_SUITE.erl | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c index 94a207cba6..6e855939f7 100644 --- a/lib/crypto/c_src/crypto.c +++ b/lib/crypto/c_src/crypto.c @@ -3757,7 +3757,7 @@ static ERL_NIF_TERM ecdh_compute_key_nif(ErlNifEnv* env, int argc, const ERL_NIF int i; EC_GROUP *group; const BIGNUM *priv_key; - EC_POINT *my_ecpoint; + EC_POINT *my_ecpoint = NULL; EC_KEY *other_ecdh = NULL; if (!get_ec_key(env, argv[1], argv[2], atom_undefined, &key)) diff --git a/lib/crypto/test/crypto_SUITE.erl b/lib/crypto/test/crypto_SUITE.erl index 6dab459df6..c07e937737 100644 --- a/lib/crypto/test/crypto_SUITE.erl +++ b/lib/crypto/test/crypto_SUITE.erl @@ -31,6 +31,7 @@ suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> [app, + {group, api_errors}, appup, {group, fips}, {group, non_fips}, @@ -169,7 +170,8 @@ groups() -> {no_aes_ige256, [], [no_support, no_block]}, {no_chacha20_poly1305, [], [no_support, no_aead]}, {no_rc2_cbc, [], [no_support, no_block]}, - {no_rc4, [], [no_support, no_stream]} + {no_rc4, [], [no_support, no_stream]}, + {api_errors, [], [api_errors_ecdh]} ]. %%------------------------------------------------------------------- @@ -237,6 +239,8 @@ init_per_group(non_fips, Config) -> _NotEnabled -> NonFIPSConfig end; +init_per_group(api_errors, Config) -> + Config; init_per_group(GroupName, Config) -> case atom_to_list(GroupName) of "no_" ++ TypeStr -> @@ -2491,3 +2495,14 @@ parse_rsp_cmac(Type, Key0, Msg0, Mlen0, Tlen, MAC0, Next, Acc) -> I -> parse_rsp(Type, Next, [{Type, Key, Msg, I, MAC}|Acc]) end. + +api_errors_ecdh(Config) when is_list(Config) -> + %% Check that we don't segfault when fed garbage. + Test = fun(Others, Curve) -> + {_Pub, Priv} = crypto:generate_key(ecdh, Curve), + crypto:compute_key(ecdh, Others, Priv, Curve) + end, + Others = [gurka, 0, <<0>>], + Curves = [gaffel, 0, sect571r1], + [_= (catch Test(O, C)) || O <- Others, C <- Curves], + ok. |