Skip to content

Commit

Permalink
When the "dynamic" ENGINE loads another ENGINE from a shared-library, it
Browse files Browse the repository at this point in the history
essentially overwrites itself with the new ENGINE, with the exception of
reference counts, ex_data structures, and other 'admin' elements. However
if the new ENGINE doesn't populate certain elements, there's the risk of
the "dynamic" ENGINE's elements showing through - the "cmd_defns" were just
one of the possibilities. This implements a more comprehensive cleanup.
  • Loading branch information
Geoff Thorpe committed Nov 22, 2001
1 parent 329636d commit e4a6cf4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crypto/engine/eng_dyn.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx)
fns.lock_fns.dynlock_create_cb = CRYPTO_get_dynlock_create_callback();
fns.lock_fns.dynlock_lock_cb = CRYPTO_get_dynlock_lock_callback();
fns.lock_fns.dynlock_destroy_cb = CRYPTO_get_dynlock_destroy_callback();
/* Now that we've loaded the dynamic engine, initialise the command
array to contain none */
ENGINE_set_cmd_defns(e, dynamic_cmd_defns_empty);
/* Now that we've loaded the dynamic engine, make sure no "dynamic"
* ENGINE elements will show through. */
engine_set_all_null(e);

/* Try to bind the ENGINE onto our own ENGINE structure */
if(!ctx->bind_engine(e, ctx->engine_id, &fns))
Expand Down
5 changes: 5 additions & 0 deletions crypto/engine/eng_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ int engine_unlocked_init(ENGINE *e);
int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers);
int engine_free_util(ENGINE *e, int locked);

/* This function will reset all "set"able values in an ENGINE to NULL. This
* won't touch reference counts or ex_data, but is equivalent to calling all the
* ENGINE_set_***() functions with a NULL value. */
void engine_set_all_null(ENGINE *e);

/* NB: Bitwise OR-able values for the "flags" variable in ENGINE are now exposed
* in engine.h. */

Expand Down
23 changes: 23 additions & 0 deletions crypto/engine/eng_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ ENGINE *ENGINE_new(void)
return ret;
}

/* Placed here (close proximity to ENGINE_new) so that modifications to the
* elements of the ENGINE structure are more likely to be caught and changed
* here. */
void engine_set_all_null(ENGINE *e)
{
e->id = NULL;
e->name = NULL;
e->rsa_meth = NULL;
e->dsa_meth = NULL;
e->dh_meth = NULL;
e->rand_meth = NULL;
e->ciphers = NULL;
e->digests = NULL;
e->destroy = NULL;
e->init = NULL;
e->finish = NULL;
e->ctrl = NULL;
e->load_privkey = NULL;
e->load_pubkey = NULL;
e->cmd_defns = NULL;
e->flags = 0;
}

int engine_free_util(ENGINE *e, int locked)
{
int i;
Expand Down

0 comments on commit e4a6cf4

Please sign in to comment.