mirror of
https://github.com/QuasarApp/openssl.git
synced 2025-05-06 22:49:40 +00:00
Add some check for malloc failure in the CAPI engine
In the CAPI engine there were some unchecked calls to OPENSSL_strdup(). GH Issue #830 Reviewed-by: Richard Levitte <levitte@openssl.org>
This commit is contained in:
parent
15b083e44e
commit
690b462126
@ -295,6 +295,7 @@ static int capi_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
|
|||||||
int ret = 1;
|
int ret = 1;
|
||||||
CAPI_CTX *ctx;
|
CAPI_CTX *ctx;
|
||||||
BIO *out;
|
BIO *out;
|
||||||
|
LPSTR tmpstr;
|
||||||
if (capi_idx == -1) {
|
if (capi_idx == -1) {
|
||||||
CAPIerr(CAPI_F_CAPI_CTRL, CAPI_R_ENGINE_NOT_INITIALIZED);
|
CAPIerr(CAPI_F_CAPI_CTRL, CAPI_R_ENGINE_NOT_INITIALIZED);
|
||||||
return 0;
|
return 0;
|
||||||
@ -323,9 +324,15 @@ static int capi_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CAPI_CMD_STORE_NAME:
|
case CAPI_CMD_STORE_NAME:
|
||||||
OPENSSL_free(ctx->storename);
|
tmpstr = OPENSSL_strdup(p);
|
||||||
ctx->storename = OPENSSL_strdup(p);
|
if (tmpstr != NULL) {
|
||||||
CAPI_trace(ctx, "Setting store name to %s\n", p);
|
OPENSSL_free(ctx->storename);
|
||||||
|
ctx->storename = tmpstr;
|
||||||
|
CAPI_trace(ctx, "Setting store name to %s\n", p);
|
||||||
|
} else {
|
||||||
|
CAPIerr(CAPI_F_CAPI_CTRL, ERR_R_MALLOC_FAILURE);
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CAPI_CMD_STORE_FLAGS:
|
case CAPI_CMD_STORE_FLAGS:
|
||||||
@ -345,8 +352,14 @@ static int capi_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CAPI_CMD_DEBUG_FILE:
|
case CAPI_CMD_DEBUG_FILE:
|
||||||
ctx->debug_file = OPENSSL_strdup(p);
|
tmpstr = OPENSSL_strdup(p);
|
||||||
CAPI_trace(ctx, "Setting debug file to %s\n", ctx->debug_file);
|
if (tmpstr != NULL) {
|
||||||
|
ctx->debug_file = tmpstr;
|
||||||
|
CAPI_trace(ctx, "Setting debug file to %s\n", ctx->debug_file);
|
||||||
|
} else {
|
||||||
|
CAPIerr(CAPI_F_CAPI_CTRL, ERR_R_MALLOC_FAILURE);
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CAPI_CMD_KEYTYPE:
|
case CAPI_CMD_KEYTYPE:
|
||||||
@ -1625,6 +1638,8 @@ static void capi_ctx_free(CAPI_CTX * ctx)
|
|||||||
static int capi_ctx_set_provname(CAPI_CTX * ctx, LPSTR pname, DWORD type,
|
static int capi_ctx_set_provname(CAPI_CTX * ctx, LPSTR pname, DWORD type,
|
||||||
int check)
|
int check)
|
||||||
{
|
{
|
||||||
|
LPSTR tmpcspname;
|
||||||
|
|
||||||
CAPI_trace(ctx, "capi_ctx_set_provname, name=%s, type=%d\n", pname, type);
|
CAPI_trace(ctx, "capi_ctx_set_provname, name=%s, type=%d\n", pname, type);
|
||||||
if (check) {
|
if (check) {
|
||||||
HCRYPTPROV hprov;
|
HCRYPTPROV hprov;
|
||||||
@ -1648,8 +1663,13 @@ static int capi_ctx_set_provname(CAPI_CTX * ctx, LPSTR pname, DWORD type,
|
|||||||
}
|
}
|
||||||
CryptReleaseContext(hprov, 0);
|
CryptReleaseContext(hprov, 0);
|
||||||
}
|
}
|
||||||
|
tmpcspname = OPENSSL_strdup(pname);
|
||||||
|
if (tmpcspname == NULL) {
|
||||||
|
CAPIerr(CAPI_F_CAPI_CTX_SET_PROVNAME, ERR_R_MALLOC_FAILURE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
OPENSSL_free(ctx->cspname);
|
OPENSSL_free(ctx->cspname);
|
||||||
ctx->cspname = OPENSSL_strdup(pname);
|
ctx->cspname = tmpcspname;
|
||||||
ctx->csptype = type;
|
ctx->csptype = type;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user