Commit e4a6cf42 authored by Geoff Thorpe's avatar Geoff Thorpe
Browse files

When the "dynamic" ENGINE loads another ENGINE from a shared-library, it

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.
parent 329636d6
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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))
+5 −0
Original line number Diff line number Diff line
@@ -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. */

+23 −0
Original line number Diff line number Diff line
@@ -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;