Skip to content

Commit

Permalink
Fix dsa & rsa signature dupctx() so that ctx->propq is strduped
Browse files Browse the repository at this point in the history
Discovered when fixing up ecdsa code.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #13520)
  • Loading branch information
slontis committed Dec 3, 2020
1 parent 2833202 commit c2386b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions providers/implementations/signature/dsa.c
Expand Up @@ -85,7 +85,6 @@ typedef struct {
/* main digest */
EVP_MD *md;
EVP_MD_CTX *mdctx;
size_t mdsize;
int operation;
} PROV_DSA_CTX;

Expand Down Expand Up @@ -361,7 +360,6 @@ static void dsa_freectx(void *vpdsactx)
ctx->propq = NULL;
ctx->mdctx = NULL;
ctx->md = NULL;
ctx->mdsize = 0;
DSA_free(ctx->dsa);
OPENSSL_free(ctx);
}
Expand All @@ -382,6 +380,7 @@ static void *dsa_dupctx(void *vpdsactx)
dstctx->dsa = NULL;
dstctx->md = NULL;
dstctx->mdctx = NULL;
dstctx->propq = NULL;

if (srcctx->dsa != NULL && !DSA_up_ref(srcctx->dsa))
goto err;
Expand All @@ -397,6 +396,11 @@ static void *dsa_dupctx(void *vpdsactx)
|| !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx))
goto err;
}
if (srcctx->propq != NULL) {
dstctx->propq = OPENSSL_strdup(srcctx->propq);
if (dstctx->propq == NULL)
goto err;
}

return dstctx;
err:
Expand Down
7 changes: 7 additions & 0 deletions providers/implementations/signature/rsa.c
Expand Up @@ -870,6 +870,7 @@ static void *rsa_dupctx(void *vprsactx)
dstctx->md = NULL;
dstctx->mdctx = NULL;
dstctx->tbuf = NULL;
dstctx->propq = NULL;

if (srcctx->rsa != NULL && !RSA_up_ref(srcctx->rsa))
goto err;
Expand All @@ -890,6 +891,12 @@ static void *rsa_dupctx(void *vprsactx)
goto err;
}

if (srcctx->propq != NULL) {
dstctx->propq = OPENSSL_strdup(srcctx->propq);
if (dstctx->propq == NULL)
goto err;
}

return dstctx;
err:
rsa_freectx(dstctx);
Expand Down

0 comments on commit c2386b8

Please sign in to comment.