Lutz Jaenicke schrieb: > On Sat, Jun 15, 2002 at 07:38:40PM -0400, Geoff Thorpe wrote: > >>On Fri, 14 Jun 2002, [ISO-8859-15] G�tz Babin-Ebell wrote: >> >>>In the ..._ctrl()-Function of the engines a passed string >>>is only referenced and not copyed. >>>This is bad if the buffer with the passed data is overwritten... >> >>[snip] >> >>Could you please; >> (a) put this into the bug-tracker,
> I have already bounced the report into the request tracker when I read it. > (It was assigned ticket #98.) >> (b) use "-u" context diffs so they're easier to follow > That's indeed true. Sorry for that. (Please see attachment) Bye Goetz -- Goetz Babin-Ebell, TC TrustCenter AG, http://www.trustcenter.de Sonninstr. 24-28, 20097 Hamburg, Germany Tel.: +49-(0)40 80 80 26 -0, Fax: +49-(0)40 80 80 26 -126
diff -u -r openssl-0.9.7-stable-SNAP-20020618/crypto/engine/eng_dyn.c
openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/eng_dyn.c
--- openssl-0.9.7-stable-SNAP-20020618/crypto/engine/eng_dyn.c Thu Nov 22 11:08:49
2001
+++ openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/eng_dyn.c Tue Jun 18
+14:08:05 2002
@@ -157,6 +157,10 @@
dynamic_data_ctx *ctx = (dynamic_data_ctx *)ptr;
if(ctx->dynamic_dso)
DSO_free(ctx->dynamic_dso);
+ if (ctx->DYNAMIC_LIBNAME)
+ OPENSSL_free((void*)(ctx->DYNAMIC_LIBNAME));
+ if (ctx->engine_id)
+ OPENSSL_free((void*)(ctx->engine_id));
OPENSSL_free(ctx);
}
}
@@ -169,7 +173,7 @@
{
dynamic_data_ctx *c;
c = OPENSSL_malloc(sizeof(dynamic_data_ctx));
- if(!ctx)
+ if(!c)
{
ENGINEerr(ENGINE_F_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
return 0;
@@ -310,8 +314,13 @@
/* a NULL 'p' or a string of zero-length is the same thing */
if(p && (strlen((const char *)p) < 1))
p = NULL;
- ctx->DYNAMIC_LIBNAME = (const char *)p;
- return 1;
+ if (ctx->DYNAMIC_LIBNAME)
+ OPENSSL_free((void*)(ctx->DYNAMIC_LIBNAME));
+ if (p)
+ ctx->DYNAMIC_LIBNAME = BUF_strdup(p);
+ else
+ ctx->DYNAMIC_LIBNAME = NULL;
+ return ctx->DYNAMIC_LIBNAME != NULL ? 1 : 0;
case DYNAMIC_CMD_NO_VCHECK:
ctx->no_vcheck = ((i == 0) ? 0 : 1);
return 1;
@@ -319,8 +328,13 @@
/* a NULL 'p' or a string of zero-length is the same thing */
if(p && (strlen((const char *)p) < 1))
p = NULL;
- ctx->engine_id = (const char *)p;
- return 1;
+ if (ctx->engine_id)
+ OPENSSL_free((void*)(ctx->engine_id));
+ if (p)
+ ctx->engine_id = BUF_strdup(p);
+ else
+ ctx->engine_id = NULL;
+ return ctx->engine_id != NULL ? 1 : 0;
case DYNAMIC_CMD_LIST_ADD:
if((i < 0) || (i > 2))
{
diff -u -r openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_4758_cca.c
openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_4758_cca.c
--- openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_4758_cca.c Wed May 22
10:03:17 2002
+++ openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_4758_cca.c Tue Jun 18
+14:08:28 2002
@@ -124,8 +124,27 @@
/* static variables */
/*------------------*/
-static const char def_CCA4758_LIB_NAME[] = CCA_LIB_NAME;
-static const char *CCA4758_LIB_NAME = def_CCA4758_LIB_NAME;
+static const char *CCA4758_LIB_NAME = NULL;
+static const char *get_CCA4758_LIB_NAME()
+{
+ if (CCA4758_LIB_NAME)
+ return CCA4758_LIB_NAME;
+ else
+ return CCA_LIB_NAME;
+}
+static void free_CCA4758_LIB_NAME()
+{
+ if (CCA4758_LIB_NAME)
+ OPENSSL_free((char*)CCA4758_LIB_NAME);
+ CCA4758_LIB_NAME = NULL;
+}
+static long set_CCA4758_LIB_NAME(const char *newName)
+{
+ if (CCA4758_LIB_NAME)
+ OPENSSL_free((char*)CCA4758_LIB_NAME);
+ return (CCA4758_LIB_NAME = BUF_strdup(newName)) != NULL ? 1 : 0;
+}
+
#ifndef OPENSSL_NO_RSA
static const char* n_keyRecordRead = CSNDKRR;
static const char* n_digitalSignatureGenerate = CSNDDSG;
@@ -232,6 +251,7 @@
static int ibm_4758_cca_destroy(ENGINE *e)
{
ERR_unload_CCA4758_strings();
+ free_CCA4758_LIB_NAME();
return 1;
}
@@ -243,7 +263,7 @@
goto err;
}
- dso = DSO_load(NULL, CCA4758_LIB_NAME , NULL, 0);
+ dso = DSO_load(NULL, get_CCA4758_LIB_NAME() , NULL, 0);
if(!dso)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
@@ -299,7 +319,8 @@
static int ibm_4758_cca_finish(ENGINE *e)
{
- if(dso)
+ free_CCA4758_LIB_NAME();
+ if(!dso)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH,
CCA4758_R_NOT_LOADED);
@@ -319,7 +340,7 @@
publicKeyExtract = (F_PUBLICKEYEXTRACT)0;
pkaEncrypt = (F_PKAENCRYPT)0;
pkaDecrypt = (F_PKADECRYPT)0;
- return 1;
+ return 1;
}
static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
@@ -340,8 +361,7 @@
CCA4758_R_ALREADY_LOADED);
return 0;
}
- CCA4758_LIB_NAME = (const char *)p;
- return 1;
+ return set_CCA4758_LIB_NAME((const char*)p);
default:
break;
}
diff -u -r openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_aep.c
openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_aep.c
--- openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_aep.c Thu Mar 7 21:07:44
2002
+++ openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_aep.c Tue Jun 18
+14:09:04 2002
@@ -71,6 +71,7 @@
#include <openssl/crypto.h>
#include <openssl/dso.h>
#include <openssl/engine.h>
+#include <openssl/buffer.h>
#ifndef OPENSSL_NO_HW
#ifndef OPENSSL_NO_HW_AEP
@@ -363,7 +364,26 @@
/* These are the static string constants for the DSO file name and the function
* symbol names to bind to.
*/
-static const char *AEP_LIBNAME = "aep";
+static const char *AEP_LIBNAME = NULL;
+static const char *get_AEP_LIBNAME()
+{
+ if (AEP_LIBNAME)
+ return AEP_LIBNAME;
+ else
+ return "aep";
+}
+static void free_AEP_LIBNAME()
+{
+ if (AEP_LIBNAME)
+ OPENSSL_free((char*)AEP_LIBNAME);
+ AEP_LIBNAME = NULL;
+}
+static long set_AEP_LIBNAME(const char *newName)
+{
+ if (AEP_LIBNAME)
+ OPENSSL_free((char*)AEP_LIBNAME);
+ return (AEP_LIBNAME = BUF_strdup(newName)) != NULL ? 1 : 0;
+}
static const char *AEP_F1 = "AEP_ModExp";
static const char *AEP_F2 = "AEP_ModExpCrt";
@@ -412,7 +432,7 @@
}
/* Attempt to load libaep.so. */
- aep_dso = DSO_load(NULL, AEP_LIBNAME, NULL, 0);
+ aep_dso = DSO_load(NULL, get_AEP_LIBNAME(), NULL, 0);
if(aep_dso == NULL)
{
@@ -474,6 +494,7 @@
/* Destructor (complements the "ENGINE_aep()" constructor) */
static int aep_destroy(ENGINE *e)
{
+ free_AEP_LIBNAME();
ERR_unload_AEPHK_strings();
return 1;
}
@@ -483,6 +504,7 @@
int to_return = 0, in_use;
AEP_RV rv;
+ free_AEP_LIBNAME();
if(aep_dso == NULL)
{
AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_NOT_LOADED);
@@ -549,8 +571,7 @@
AEPHK_R_ALREADY_LOADED);
return 0;
}
- AEP_LIBNAME = (const char *)p;
- return 1;
+ return set_AEP_LIBNAME((const char*)p);
default:
break;
}
diff -u -r openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_atalla.c
openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_atalla.c
--- openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_atalla.c Thu Feb 7
21:02:45 2002
+++ openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_atalla.c Tue Jun 18
+14:09:16 2002
@@ -286,8 +286,27 @@
* atasi.dll on win32). For the purposes of testing, I have created a symbollic
* link called "libatasi.so" so that we can use native name-translation - a
* better solution will be needed. */
-static const char def_ATALLA_LIBNAME[] = "atasi";
-static const char *ATALLA_LIBNAME = def_ATALLA_LIBNAME;
+static const char *ATALLA_LIBNAME = NULL;
+static const char *get_ATALLA_LIBNAME()
+{
+ if (ATALLA_LIBNAME)
+ return ATALLA_LIBNAME;
+ else
+ return "atasi";
+}
+static void free_ATALLA_LIBNAME()
+{
+ if (ATALLA_LIBNAME)
+ OPENSSL_free((char*)ATALLA_LIBNAME);
+ ATALLA_LIBNAME = NULL;
+}
+static long set_ATALLA_LIBNAME(const char *newName)
+{
+ if (ATALLA_LIBNAME)
+ OPENSSL_free((char*)ATALLA_LIBNAME);
+ return (ATALLA_LIBNAME = BUF_strdup(newName) )!= NULL ? 1 : 0;
+}
+
static const char *ATALLA_F1 = "ASI_GetHardwareConfig";
static const char *ATALLA_F2 = "ASI_RSAPrivateKeyOpFn";
static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics";
@@ -299,6 +318,7 @@
* functs or reasons won't lead to a segfault (they simply get displayed
* without corresponding string data because none will be found). */
ERR_unload_ATALLA_strings();
+ free_ATALLA_LIBNAME();
return 1;
}
@@ -324,7 +344,7 @@
* drivers really use - for now a symbollic link needs to be
* created on the host system from libatasi.so to atasi.so on
* unix variants. */
- atalla_dso = DSO_load(NULL, ATALLA_LIBNAME, NULL, 0);
+ atalla_dso = DSO_load(NULL, get_ATALLA_LIBNAME(), NULL, 0);
if(atalla_dso == NULL)
{
ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_NOT_LOADED);
@@ -364,6 +384,7 @@
static int atalla_finish(ENGINE *e)
{
+ free_ATALLA_LIBNAME();
if(atalla_dso == NULL)
{
ATALLAerr(ATALLA_F_ATALLA_FINISH,ATALLA_R_NOT_LOADED);
@@ -397,8 +418,7 @@
ATALLAerr(ATALLA_F_ATALLA_CTRL,ATALLA_R_ALREADY_LOADED);
return 0;
}
- ATALLA_LIBNAME = (const char *)p;
- return 1;
+ return set_ATALLA_LIBNAME((const char *)p);
default:
break;
}
diff -u -r openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_cswift.c
openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_cswift.c
--- openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_cswift.c Thu Feb 7
21:02:46 2002
+++ openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_cswift.c Tue Jun 18
+14:09:41 2002
@@ -280,8 +280,26 @@
t_swReleaseAccContext *p_CSwift_ReleaseAccContext = NULL;
/* Used in the DSO operations. */
-static const char def_CSWIFT_LIBNAME[] = "swift";
-static const char *CSWIFT_LIBNAME = def_CSWIFT_LIBNAME;
+static const char *CSWIFT_LIBNAME = NULL;
+static const char *get_CSWIFT_LIBNAME()
+{
+ if (CSWIFT_LIBNAME)
+ return CSWIFT_LIBNAME;
+ else
+ return "swift";
+}
+static void free_CSWIFT_LIBNAME()
+{
+ if (CSWIFT_LIBNAME)
+ OPENSSL_free((char*)CSWIFT_LIBNAME);
+ CSWIFT_LIBNAME = NULL;
+}
+static long set_CSWIFT_LIBNAME(const char *newName)
+{
+ free_CSWIFT_LIBNAME();
+ return (CSWIFT_LIBNAME = BUF_strdup(newName)) != NULL ? 1 : 0;
+}
+
static const char *CSWIFT_F1 = "swAcquireAccContext";
static const char *CSWIFT_F2 = "swAttachKeyParam";
static const char *CSWIFT_F3 = "swSimpleRequest";
@@ -314,6 +332,7 @@
static int cswift_destroy(ENGINE *e)
{
ERR_unload_CSWIFT_strings();
+ free_CSWIFT_LIBNAME();
return 1;
}
@@ -332,7 +351,7 @@
goto err;
}
/* Attempt to load libswift.so/swift.dll/whatever. */
- cswift_dso = DSO_load(NULL, CSWIFT_LIBNAME, NULL, 0);
+ cswift_dso = DSO_load(NULL, get_CSWIFT_LIBNAME(), NULL, 0);
if(cswift_dso == NULL)
{
CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_NOT_LOADED);
@@ -377,6 +396,7 @@
static int cswift_finish(ENGINE *e)
{
+ free_CSWIFT_LIBNAME();
if(cswift_dso == NULL)
{
CSWIFTerr(CSWIFT_F_CSWIFT_FINISH,CSWIFT_R_NOT_LOADED);
@@ -411,8 +431,7 @@
CSWIFTerr(CSWIFT_F_CSWIFT_CTRL,CSWIFT_R_ALREADY_LOADED);
return 0;
}
- CSWIFT_LIBNAME = (const char *)p;
- return 1;
+ return set_CSWIFT_LIBNAME((const char*)p);
default:
break;
}
diff -u -r openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_ncipher.c
openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_ncipher.c
--- openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_ncipher.c Thu Feb 7
21:02:47 2002
+++ openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_ncipher.c Tue Jun 18
+14:09:49 2002
@@ -422,8 +422,26 @@
static HWCryptoHook_ModExpCRT_t *p_hwcrhk_ModExpCRT = NULL;
/* Used in the DSO operations. */
-static const char def_HWCRHK_LIBNAME[] = "nfhwcrhk";
-static const char *HWCRHK_LIBNAME = def_HWCRHK_LIBNAME;
+static const char *HWCRHK_LIBNAME = NULL;
+static void free_HWCRHK_LIBNAME()
+{
+ if (HWCRHK_LIBNAME)
+ OPENSSL_free((char*)HWCRHK_LIBNAME);
+ HWCRHK_LIBNAME = NULL;
+}
+static const char *get_HWCRHK_LIBNAME()
+{
+ if (HWCRHK_LIBNAME)
+ return HWCRHK_LIBNAME;
+ else
+ return "nfhwcrhk";
+}
+static long set_HWCRHK_LIBNAME(const char *newName)
+{
+ free_HWCRHK_LIBNAME();
+ return (HWCRHK_LIBNAME = BUF_strdup(newName)) != NULL ? 1 : 0;
+}
+
static const char *n_hwcrhk_Init = "HWCryptoHook_Init";
static const char *n_hwcrhk_Finish = "HWCryptoHook_Finish";
static const char *n_hwcrhk_ModExp = "HWCryptoHook_ModExp";
@@ -470,6 +488,7 @@
static int hwcrhk_destroy(ENGINE *e)
{
ERR_unload_HWCRHK_strings();
+ free_HWCRHK_LIBNAME();
return 1;
}
@@ -494,7 +513,7 @@
goto err;
}
/* Attempt to load libnfhwcrhk.so/nfhwcrhk.dll/whatever. */
- hwcrhk_dso = DSO_load(NULL, HWCRHK_LIBNAME, NULL, 0);
+ hwcrhk_dso = DSO_load(NULL, get_HWCRHK_LIBNAME(), NULL, 0);
if(hwcrhk_dso == NULL)
{
HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DSO_FAILURE);
@@ -586,6 +605,7 @@
static int hwcrhk_finish(ENGINE *e)
{
int to_return = 1;
+ free_HWCRHK_LIBNAME();
if(hwcrhk_dso == NULL)
{
HWCRHKerr(HWCRHK_F_HWCRHK_FINISH,HWCRHK_R_NOT_LOADED);
@@ -634,8 +654,7 @@
HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
- HWCRHK_LIBNAME = (const char *)p;
- return 1;
+ return set_HWCRHK_LIBNAME((const char*)p);
case ENGINE_CTRL_SET_LOGSTREAM:
{
BIO *bio = (BIO *)p;
diff -u -r openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_nuron.c
openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_nuron.c
--- openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_nuron.c Thu Feb 7 21:02:47
2002
+++ openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_nuron.c Tue Jun 18
+14:09:55 2002
@@ -69,8 +69,26 @@
#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()
+{
+ if (NURON_LIBNAME)
+ return NURON_LIBNAME;
+ else
+ return "nuronssl";
+}
+static void free_NURON_LIBNAME()
+{
+ if (NURON_LIBNAME)
+ OPENSSL_free((char*)NURON_LIBNAME);
+ NURON_LIBNAME = NULL;
+}
+static long set_NURON_LIBNAME(const char *newName)
+{
+ free_NURON_LIBNAME();
+ return (NURON_LIBNAME = BUF_strdup(newName)) != NULL ? 1 : 0;
+}
+
static const char *NURON_F1 = "nuron_mod_exp";
/* The definitions for control commands specific to this engine */
@@ -91,6 +109,7 @@
static int nuron_destroy(ENGINE *e)
{
ERR_unload_NURON_strings();
+ free_NURON_LIBNAME();
return 1;
}
@@ -102,7 +121,7 @@
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 +141,7 @@
static int nuron_finish(ENGINE *e)
{
+ free_NURON_LIBNAME();
if(pvDSOHandle == NULL)
{
NURONerr(NURON_F_NURON_FINISH,NURON_R_NOT_LOADED);
@@ -153,8 +173,7 @@
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;
}
diff -u -r openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_ubsec.c
openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_ubsec.c
--- openssl-0.9.7-stable-SNAP-20020618/crypto/engine/hw_ubsec.c Thu Feb 7 21:37:55
2002
+++ openssl-0.9.7-stable-SNAP-20020618_new/crypto/engine/hw_ubsec.c Tue Jun 18
+14:10:06 2002
@@ -304,7 +304,26 @@
* symbol names to bind to.
*/
-static const char *UBSEC_LIBNAME = "ubsec";
+static const char *UBSEC_LIBNAME = NULL;
+static const char *get_UBSEC_LIBNAME()
+{
+ if (UBSEC_LIBNAME)
+ return UBSEC_LIBNAME;
+ else
+ return "ubsec";
+}
+static void free_UBSEC_LIBNAME()
+{
+ if (UBSEC_LIBNAME)
+ OPENSSL_free((char*)UBSEC_LIBNAME);
+ UBSEC_LIBNAME = NULL;
+}
+static long set_UBSEC_LIBNAME(const char *newName)
+{
+ free_UBSEC_LIBNAME();
+ return (UBSEC_LIBNAME = BUF_strdup(newName)) != NULL ? 1 : 0;
+}
+
static const char *UBSEC_F1 = "ubsec_bytes_to_bits";
static const char *UBSEC_F2 = "ubsec_bits_to_bytes";
static const char *UBSEC_F3 = "ubsec_open";
@@ -329,6 +348,7 @@
static int ubsec_destroy(ENGINE *e)
{
ERR_unload_UBSEC_strings();
+ free_UBSEC_LIBNAME();
return 1;
}
@@ -364,7 +384,7 @@
/*
* Attempt to load libubsec.so/ubsec.dll/whatever.
*/
- ubsec_dso = DSO_load(NULL, UBSEC_LIBNAME, NULL, 0);
+ ubsec_dso = DSO_load(NULL, get_UBSEC_LIBNAME(), NULL, 0);
if(ubsec_dso == NULL)
{
UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE);
@@ -459,6 +479,7 @@
static int ubsec_finish(ENGINE *e)
{
+ free_UBSEC_LIBNAME();
if(ubsec_dso == NULL)
{
UBSECerr(UBSEC_F_UBSEC_FINISH, UBSEC_R_NOT_LOADED);
@@ -508,8 +529,7 @@
UBSECerr(UBSEC_F_UBSEC_CTRL,UBSEC_R_ALREADY_LOADED);
return 0;
}
- UBSEC_LIBNAME = (const char *)p;
- return 1;
+ return set_UBSEC_LIBNAME((const char *)p);
default:
break;
}
smime.p7s
Description: S/MIME Cryptographic Signature
