diff options
author | Doug Hogan <[email protected]> | 2019-01-03 21:32:05 -0800 |
---|---|---|
committer | Doug Hogan <[email protected]> | 2019-01-08 01:11:57 -0800 |
commit | b43336cffe8c90ad259a75aa79fa79637d83cc4e (patch) | |
tree | 1abcf63085e8cda0e39a6d8d49136b92c09c447f /lib/crypto/c_src/engine.c | |
parent | c94b99aea4c7aaa296153c038117c9360a57ff50 (diff) | |
download | otp-b43336cffe8c90ad259a75aa79fa79637d83cc4e.tar.gz otp-b43336cffe8c90ad259a75aa79fa79637d83cc4e.tar.bz2 otp-b43336cffe8c90ad259a75aa79fa79637d83cc4e.zip |
Revamp engine_get_id_nif()
* Add error handling for all Erlang calls.
* Change size from int to size_t since it's assigned to sizeof().
Diffstat (limited to 'lib/crypto/c_src/engine.c')
-rw-r--r-- | lib/crypto/c_src/engine.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/crypto/c_src/engine.c b/lib/crypto/c_src/engine.c index 5067f34eec..88471e7f91 100644 --- a/lib/crypto/c_src/engine.c +++ b/lib/crypto/c_src/engine.c @@ -658,28 +658,34 @@ ERL_NIF_TERM engine_get_id_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv #ifdef HAS_ENGINE_SUPPORT ErlNifBinary engine_id_bin; const char *engine_id; - int size; - struct engine_ctx *ctx; + size_t size; + struct engine_ctx *ctx = NULL; // Get Engine - if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) { - PRINTF_ERR0("engine_get_id_nif Leaved: Parameter not an engine resource object"); - return enif_make_badarg(env); - } + if (argc != 1) + goto bad_arg; + if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) + goto bad_arg; - engine_id = ENGINE_get_id(ctx->engine); - if (!engine_id) { - enif_alloc_binary(0, &engine_id_bin); + if ((engine_id = ENGINE_get_id(ctx->engine)) == NULL) { + if (!enif_alloc_binary(0, &engine_id_bin)) + goto err; engine_id_bin.size = 0; return enif_make_binary(env, &engine_id_bin); } size = strlen(engine_id); - enif_alloc_binary(size, &engine_id_bin); + if (!enif_alloc_binary(size, &engine_id_bin)) + goto err; engine_id_bin.size = size; memcpy(engine_id_bin.data, engine_id, size); return enif_make_binary(env, &engine_id_bin); + + bad_arg: + err: + return enif_make_badarg(env); + #else return atom_notsup; #endif |