Make sure any ENGINE control commands make local copies of string
[openssl.git] / crypto / engine / hw_nuron.c
index 26720121547c9d28b01afd11cbfe44f911ce3d33..130b6d8b40571e40bdd034d80dc4d16e3974392a 100644 (file)
 #define NURON_LIB_NAME "nuron engine"
 #include "hw_nuron_err.c"
 
-static const char def_NURON_LIBNAME[] = "nuronssl";
-static const char *NURON_LIBNAME = def_NURON_LIBNAME;
+static const char *NURON_LIBNAME = NULL;
+static const char *get_NURON_LIBNAME(void)
+       {
+       if(NURON_LIBNAME)
+               return NURON_LIBNAME;
+       return "nuronssl";
+       }
+static void free_NURON_LIBNAME(void)
+       {
+       if(NURON_LIBNAME)
+               OPENSSL_free((void*)NURON_LIBNAME);
+       NURON_LIBNAME = NULL;
+       }
+static long set_NURON_LIBNAME(const char *name)
+       {
+       free_NURON_LIBNAME();
+       return (((NURON_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
+       }
 static const char *NURON_F1 = "nuron_mod_exp";
 
 /* The definitions for control commands specific to this engine */
@@ -90,6 +106,7 @@ static DSO *pvDSOHandle = NULL;
 
 static int nuron_destroy(ENGINE *e)
        {
+       free_NURON_LIBNAME();
        ERR_unload_NURON_strings();
        return 1;
        }
@@ -102,7 +119,7 @@ static int nuron_init(ENGINE *e)
                return 0;
                }
 
-       pvDSOHandle = DSO_load(NULL, NURON_LIBNAME, NULL,
+       pvDSOHandle = DSO_load(NULL, get_NURON_LIBNAME(), NULL,
                DSO_FLAG_NAME_TRANSLATION_EXT_ONLY);
        if(!pvDSOHandle)
                {
@@ -122,6 +139,7 @@ static int nuron_init(ENGINE *e)
 
 static int nuron_finish(ENGINE *e)
        {
+       free_NURON_LIBNAME();
        if(pvDSOHandle == NULL)
                {
                NURONerr(NURON_F_NURON_FINISH,NURON_R_NOT_LOADED);
@@ -153,8 +171,7 @@ static int nuron_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
                        NURONerr(NURON_F_NURON_CTRL,NURON_R_ALREADY_LOADED);
                        return 0;
                        }
-               NURON_LIBNAME = (const char *)p;
-               return 1;
+               return set_NURON_LIBNAME((const char *)p);
        default:
                break;
                }