aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Hogan <[email protected]>2019-01-03 21:33:27 -0800
committerDoug Hogan <[email protected]>2019-01-08 01:11:57 -0800
commit262d1f56caeab592fa28ff78bdee3a9149d1b13b (patch)
treedec5a67fa91d211fbd55271af6d9f3f767c8ba6b
parentb43336cffe8c90ad259a75aa79fa79637d83cc4e (diff)
downloadotp-262d1f56caeab592fa28ff78bdee3a9149d1b13b.tar.gz
otp-262d1f56caeab592fa28ff78bdee3a9149d1b13b.tar.bz2
otp-262d1f56caeab592fa28ff78bdee3a9149d1b13b.zip
Revamp engine_get_name_nif()
* Add error handling for all Erlang calls. * Change size from int to size_t.
-rw-r--r--lib/crypto/c_src/engine.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/crypto/c_src/engine.c b/lib/crypto/c_src/engine.c
index 88471e7f91..541e8beb9b 100644
--- a/lib/crypto/c_src/engine.c
+++ b/lib/crypto/c_src/engine.c
@@ -696,28 +696,34 @@ ERL_NIF_TERM engine_get_name_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar
#ifdef HAS_ENGINE_SUPPORT
ErlNifBinary engine_name_bin;
const char *engine_name;
- int size;
+ size_t size;
struct engine_ctx *ctx;
// 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_name = ENGINE_get_name(ctx->engine);
- if (!engine_name) {
- enif_alloc_binary(0, &engine_name_bin);
+ if ((engine_name = ENGINE_get_name(ctx->engine)) == NULL) {
+ if (!enif_alloc_binary(0, &engine_name_bin))
+ goto err;
engine_name_bin.size = 0;
return enif_make_binary(env, &engine_name_bin);
}
size = strlen(engine_name);
- enif_alloc_binary(size, &engine_name_bin);
+ if (!enif_alloc_binary(size, &engine_name_bin))
+ goto err;
engine_name_bin.size = size;
memcpy(engine_name_bin.data, engine_name, size);
return enif_make_binary(env, &engine_name_bin);
+
+ bad_arg:
+ err:
+ return enif_make_badarg(env);
+
#else
return atom_notsup;
#endif