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

Make sure any ENGINE control commands make local copies of string

pointers passed to them whenever necessary. Otherwise it is possible the
caller may have overwritten (or deallocated) the original string data
when a later ENGINE operation tries to use the stored values.

Submitted by: Götz Babin-Ebell <babinebell@trustcenter.de>
Reviewed by: Geoff Thorpe
PR: 98
parent a947f2d2
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -92,6 +92,12 @@
 
 Changes between 0.9.6d and 0.9.7  [XX xxx 2002]

  *) Make sure any ENGINE control commands make local copies of string
     pointers passed to them whenever necessary. Otherwise it is possible
     the caller may have overwritten (or deallocated) the original string
     data when a later ENGINE operation tries to use the stored values.
     [Götz Babin-Ebell <babinebell@trustcenter.de>]

  *) Improve diagnostics in file reading and command-line digests.
     [Ben Laurie aided and abetted by Solar Designer <solar@openwall.com>]

+19 −5
Original line number Diff line number Diff line
@@ -157,6 +157,10 @@ static void dynamic_data_ctx_free_func(void *parent, void *ptr,
		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 @@ static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
	{
	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 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
		/* 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 ? 1 : 0);
	case DYNAMIC_CMD_NO_VCHECK:
		ctx->no_vcheck = ((i == 0) ? 0 : 1);
		return 1;
@@ -319,8 +328,13 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
		/* 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 ? 1 : 0);
	case DYNAMIC_CMD_LIST_ADD:
		if((i < 0) || (i > 2))
			{
+23 −6
Original line number Diff line number Diff line
@@ -124,8 +124,24 @@ static F_RANDOMNUMBERGENERATE randomNumberGenerate;

/* 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(void)
	{
	if(CCA4758_LIB_NAME)
		return CCA4758_LIB_NAME;
	return CCA_LIB_NAME;
	}
static void free_CCA4758_LIB_NAME(void)
	{
	if(CCA4758_LIB_NAME)
		OPENSSL_free((void*)CCA4758_LIB_NAME);
	CCA4758_LIB_NAME = NULL;
	}
static long set_CCA4758_LIB_NAME(const char *name)
	{
	free_CCA4758_LIB_NAME();
	return (((CCA4758_LIB_NAME = BUF_strdup(name)) != NULL) ? 1 : 0);
	}
#ifndef OPENSSL_NO_RSA
static const char* n_keyRecordRead = CSNDKRR;
static const char* n_digitalSignatureGenerate = CSNDDSG;
@@ -232,6 +248,7 @@ void ENGINE_load_4758cca(void)
static int ibm_4758_cca_destroy(ENGINE *e)
	{
	ERR_unload_CCA4758_strings();
	free_CCA4758_LIB_NAME();
	return 1;
	}

@@ -243,7 +260,7 @@ static int ibm_4758_cca_init(ENGINE *e)
		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 +316,8 @@ err:

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);
@@ -340,8 +358,7 @@ static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
					CCA4758_R_ALREADY_LOADED);
			return 0;
			}
		CCA4758_LIB_NAME = (const char *)p;
		return 1;
		return set_CCA4758_LIB_NAME((const char *)p);
	default:
		break;
		}
+22 −4
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ typedef int pid_t;
#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,24 @@ static DSO *aep_dso = NULL;
/* 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(void)
	{
	if(AEP_LIBNAME)
		return AEP_LIBNAME;
	return "aep";
	}
static void free_AEP_LIBNAME(void)
	{
	if(AEP_LIBNAME)
		OPENSSL_free((void*)AEP_LIBNAME);
	AEP_LIBNAME = NULL;
	}
static long set_AEP_LIBNAME(const char *name)
	{
	free_AEP_LIBNAME();
	return ((AEP_LIBNAME = BUF_strdup(name)) != NULL ? 1 : 0);
	}

static const char *AEP_F1    = "AEP_ModExp";
static const char *AEP_F2    = "AEP_ModExpCrt";
@@ -412,7 +430,7 @@ static int aep_init(ENGINE *e)
		}
	/* 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 +492,7 @@ static int aep_init(ENGINE *e)
/* Destructor (complements the "ENGINE_aep()" constructor) */
static int aep_destroy(ENGINE *e)
	{
	free_AEP_LIBNAME();
	ERR_unload_AEPHK_strings();
	return 1;
	}
@@ -549,8 +568,7 @@ static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
				AEPHK_R_ALREADY_LOADED);
			return 0;
			}
		AEP_LIBNAME = (const char *)p;
		return 1;
		return set_AEP_LIBNAME((const char*)p);
	default:
		break;
		}
+22 −5
Original line number Diff line number Diff line
@@ -286,8 +286,24 @@ static tfnASI_GetPerformanceStatistics *p_Atalla_GetPerformanceStatistics = NULL
 * 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(void)
	{
		if(ATALLA_LIBNAME)
			return ATALLA_LIBNAME;
		return "atasi";
	}
static void free_ATALLA_LIBNAME(void)
	{
		if(ATALLA_LIBNAME)
			OPENSSL_free((void*)ATALLA_LIBNAME);
		ATALLA_LIBNAME = NULL;
	}
static long set_ATALLA_LIBNAME(const char *name)
	{
	free_ATALLA_LIBNAME();
	return (((ATALLA_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
	}
static const char *ATALLA_F1 = "ASI_GetHardwareConfig";
static const char *ATALLA_F2 = "ASI_RSAPrivateKeyOpFn";
static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics";
@@ -295,6 +311,7 @@ static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics";
/* Destructor (complements the "ENGINE_atalla()" constructor) */
static int atalla_destroy(ENGINE *e)
	{
	free_ATALLA_LIBNAME();
	/* Unload the atalla error strings so any error state including our
	 * functs or reasons won't lead to a segfault (they simply get displayed
	 * without corresponding string data because none will be found). */
@@ -324,7 +341,7 @@ static int atalla_init(ENGINE *e)
	 * 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 +381,7 @@ err:

static int atalla_finish(ENGINE *e)
	{
	free_ATALLA_LIBNAME();
	if(atalla_dso == NULL)
		{
		ATALLAerr(ATALLA_F_ATALLA_FINISH,ATALLA_R_NOT_LOADED);
@@ -397,8 +415,7 @@ static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
			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;
		}
Loading