X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=crypto%2Fengine%2Feng_lib.c;h=18a66646458a9aa033abfdde32ce936229f75f57;hb=4cfe3df1f56367ca08e09befaf2f1fe3075c9a92;hp=6dabdfdb35c01691f3ed76b243975ba1ca760d00;hpb=b6d1e52d454bb321153c70cf763945d4b0d4f78e;p=openssl.git diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c index 6dabdfdb35..18a6664645 100644 --- a/crypto/engine/eng_lib.c +++ b/crypto/engine/eng_lib.c @@ -56,11 +56,8 @@ * */ -#include -#include "cryptlib.h" #include "eng_int.h" -#include /* FIXME: This shouldn't be needed */ -#include +#include /* The "new"/"free" stuff first */ @@ -81,13 +78,37 @@ 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->store_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; if(e == NULL) { - ENGINEerr(ENGINE_F_ENGINE_FREE, + ENGINEerr(ENGINE_F_ENGINE_FREE_UTIL, ERR_R_PASSED_NULL_PARAMETER); return 0; } @@ -104,6 +125,9 @@ int engine_free_util(ENGINE *e, int locked) abort(); } #endif + /* Free up any dynamically allocated public key methods */ + engine_pkey_meths_free(e); + engine_pkey_asn1_meths_free(e); /* Give the ENGINE a chance to do any structural cleanup corresponding * to allocation it did in its constructor (eg. unload error strings) */ if(e->destroy) @@ -124,37 +148,50 @@ int ENGINE_free(ENGINE *e) * cleanup can register a "cleanup" callback here. That way we don't get linker * bloat by referring to all *possible* cleanups, but any linker bloat into code * "X" will cause X's cleanup function to end up here. */ -static STACK_OF(ENGINE_CLEANUP_CB) *cleanup_stack = NULL; +static STACK_OF(ENGINE_CLEANUP_ITEM) *cleanup_stack = NULL; static int int_cleanup_check(int create) { if(cleanup_stack) return 1; if(!create) return 0; - cleanup_stack = sk_ENGINE_CLEANUP_CB_new_null(); + cleanup_stack = sk_ENGINE_CLEANUP_ITEM_new_null(); return (cleanup_stack ? 1 : 0); } +static ENGINE_CLEANUP_ITEM *int_cleanup_item(ENGINE_CLEANUP_CB *cb) + { + ENGINE_CLEANUP_ITEM *item = OPENSSL_malloc(sizeof( + ENGINE_CLEANUP_ITEM)); + if(!item) return NULL; + item->cb = cb; + return item; + } void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb) { + ENGINE_CLEANUP_ITEM *item; if(!int_cleanup_check(1)) return; - sk_ENGINE_CLEANUP_CB_insert(cleanup_stack, cb, 0); + item = int_cleanup_item(cb); + if(item) + sk_ENGINE_CLEANUP_ITEM_insert(cleanup_stack, item, 0); } void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb) { + ENGINE_CLEANUP_ITEM *item; if(!int_cleanup_check(1)) return; - sk_ENGINE_CLEANUP_CB_push(cleanup_stack, cb); + item = int_cleanup_item(cb); + if(item) + sk_ENGINE_CLEANUP_ITEM_push(cleanup_stack, item); } /* The API function that performs all cleanup */ +static void engine_cleanup_cb_free(ENGINE_CLEANUP_ITEM *item) + { + (*(item->cb))(); + OPENSSL_free(item); + } void ENGINE_cleanup(void) { if(int_cleanup_check(0)) { - int loop = 0, num = sk_ENGINE_CLEANUP_CB_num(cleanup_stack); - while(loop < num) - { - ENGINE_CLEANUP_CB *cb = sk_ENGINE_CLEANUP_CB_value( - cleanup_stack, loop++); - (*cb)(); - } - sk_ENGINE_CLEANUP_CB_free(cleanup_stack); + sk_ENGINE_CLEANUP_ITEM_pop_free(cleanup_stack, + engine_cleanup_cb_free); cleanup_stack = NULL; } /* FIXME: This should be handled (somehow) through RAND, eg. by it @@ -283,3 +320,13 @@ const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e) { return e->cmd_defns; } + +/* eng_lib.o is pretty much linked into anything that touches ENGINE already, so + * put the "static_state" hack here. */ + +static int internal_static_hack = 0; + +void *ENGINE_get_static_state(void) + { + return &internal_static_hack; + }