Prevent calling code from doing the allocation of the ENGINE structure.
authorGeoff Thorpe <geoff@openssl.org>
Fri, 26 May 2000 15:21:47 +0000 (15:21 +0000)
committerGeoff Thorpe <geoff@openssl.org>
Fri, 26 May 2000 15:21:47 +0000 (15:21 +0000)
This was a bad idea in the first place, in particular it would have made
it trickier to implement error-handling, particularly when shutting down
third-party shared libraries etc.

crypto/engine/engine.h
crypto/engine/engine_list.c

index ad4f3f539c2eca9a5dce125fed0ff959b00fdb86..a85776a8e6e75de5c0abe81ea1410df581dd6e07 100644 (file)
@@ -133,8 +133,17 @@ ENGINE *ENGINE_by_id(const char *id);
  * implementations of things prior to using it directly or adding
  * it to the builtin ENGINE list in OpenSSL. These are also here
  * so that the ENGINE structure doesn't have to be exposed and
- * break binary compatibility! */
+ * break binary compatibility!
+ *
+ * NB: I'm changing ENGINE_new to force the ENGINE structure to
+ * be allocated from within OpenSSL. See the comment for
+ * ENGINE_get_struct_size().
+ */
+#if 0
 ENGINE *ENGINE_new(ENGINE *e);
+#else
+ENGINE *ENGINE_new(void);
+#endif
 int ENGINE_free(ENGINE *e);
 int ENGINE_set_id(ENGINE *e, const char *id);
 int ENGINE_set_name(ENGINE *e, const char *name);
@@ -164,8 +173,14 @@ BN_MOD_EXP_CRT ENGINE_get_BN_mod_exp_crt(ENGINE *e);
  * structure (for good reason). However, if the caller wishes to use
  * its own memory allocation or use a static array, the following call
  * should be used to check the amount of memory the ENGINE structure
- * will occupy. This will make the code more future-proof. */
+ * will occupy. This will make the code more future-proof.
+ *
+ * NB: I'm "#if 0"-ing this out because it's better to force the use of
+ * internally allocated memory. See similar change in ENGINE_new().
+ */
+#if 0
 int ENGINE_get_struct_size(void);
+#endif
 
 /* FUNCTIONAL functions. These functions deal with ENGINE structures
  * that have (or will) be initialised for use. Broadly speaking, the
index 03d9a1261610f8d18f888d300b05f244904e3e8e..484e89c8f8f2d9c0510449101cab0207eb3e4e06 100644 (file)
@@ -335,6 +335,9 @@ ENGINE *ENGINE_by_id(const char *id)
        return iterator;
        }
 
+/* As per the comments in engine.h, it is generally better all round
+ * if the ENGINE structure is allocated within this framework. */
+#if 0
 int ENGINE_get_struct_size(void)
        {
        return sizeof(ENGINE);
@@ -362,6 +365,23 @@ ENGINE *ENGINE_new(ENGINE *e)
        ret->struct_ref = 1;
        return ret;
        }
+#else
+ENGINE *ENGINE_new(void)
+       {
+       ENGINE *ret;
+
+       ret = (ENGINE *)Malloc(sizeof(ENGINE));
+       if(ret == NULL)
+               {
+               ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE);
+               return NULL;
+               }
+       memset(ret, 0, sizeof(ENGINE));
+       ret->flags = ENGINE_FLAGS_MALLOCED;
+       ret->struct_ref = 1;
+       return ret;
+       }
+#endif
 
 int ENGINE_free(ENGINE *e)
        {