diff options
author | Doug Hogan <[email protected]> | 2019-01-03 21:20:47 -0800 |
---|---|---|
committer | Doug Hogan <[email protected]> | 2019-01-08 01:11:57 -0800 |
commit | b645e20dac3b5c228316abde02bd7dedfd6bcf59 (patch) | |
tree | 1ac295fe69377e2bde35bde7f143581f646c85dd /lib/crypto/c_src/engine.c | |
parent | 1ad4eb810f83a43c531eebafd8784a2c76d7869e (diff) | |
download | otp-b645e20dac3b5c228316abde02bd7dedfd6bcf59.tar.gz otp-b645e20dac3b5c228316abde02bd7dedfd6bcf59.tar.bz2 otp-b645e20dac3b5c228316abde02bd7dedfd6bcf59.zip |
Revamp engine_get_first_nif()
* Add error handling for all Erlang calls.
Diffstat (limited to 'lib/crypto/c_src/engine.c')
-rw-r--r-- | lib/crypto/c_src/engine.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/crypto/c_src/engine.c b/lib/crypto/c_src/engine.c index 5f742757e8..4cbb8dc683 100644 --- a/lib/crypto/c_src/engine.c +++ b/lib/crypto/c_src/engine.c @@ -573,26 +573,38 @@ ERL_NIF_TERM engine_unregister_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ERL_NIF_TERM engine_get_first_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {/* (Engine) */ #ifdef HAS_ENGINE_SUPPORT - ERL_NIF_TERM ret; + ERL_NIF_TERM ret, result; ENGINE *engine; ErlNifBinary engine_bin; - struct engine_ctx *ctx; + struct engine_ctx *ctx = NULL; - engine = ENGINE_get_first(); - if(!engine) { - enif_alloc_binary(0, &engine_bin); + if (argc != 1) + goto bad_arg; + + if ((engine = ENGINE_get_first()) == NULL) { + if (!enif_alloc_binary(0, &engine_bin)) + goto err; engine_bin.size = 0; return enif_make_tuple2(env, atom_ok, enif_make_binary(env, &engine_bin)); } - ctx = enif_alloc_resource(engine_ctx_rtype, sizeof(struct engine_ctx)); + if ((ctx = enif_alloc_resource(engine_ctx_rtype, sizeof(struct engine_ctx))) == NULL) + goto err; ctx->engine = engine; ctx->id = NULL; - ret = enif_make_resource(env, ctx); + result = enif_make_resource(env, ctx); + ret = enif_make_tuple2(env, atom_ok, result); + goto done; + + bad_arg: + err: + ret = enif_make_badarg(env); + + done: enif_release_resource(ctx); + return ret; - return enif_make_tuple2(env, atom_ok, ret); #else return atom_notsup; #endif |