if (!ossl_prov_is_running())
return NULL;
- dstctx = OPENSSL_zalloc(sizeof(*srcctx));
- if (dstctx == NULL)
+ if ((dstctx = OPENSSL_memdup(srcctx, sizeof(*srcctx))) == NULL)
return NULL;
- *dstctx = *srcctx;
dstctx->dsa = NULL;
dstctx->propq = NULL;
+ dstctx->md = NULL;
+ dstctx->mdctx = NULL;
+ dstctx->sig = NULL;
if (srcctx->dsa != NULL && !DSA_up_ref(srcctx->dsa))
goto err;
goto err;
dstctx->md = srcctx->md;
- if (srcctx->mdctx != NULL) {
- dstctx->mdctx = EVP_MD_CTX_new();
- if (dstctx->mdctx == NULL
- || !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;
- }
+ if (srcctx->mdctx != NULL
+ && (dstctx->mdctx = EVP_MD_CTX_dup(srcctx->mdctx)) == NULL)
+ goto err;
+ if (srcctx->propq != NULL
+ && ((dstctx->propq = OPENSSL_strdup(srcctx->propq)) == NULL))
+ goto err;
+ if (srcctx->sig != NULL
+ && ((dstctx->sig = OPENSSL_memdup(srcctx->sig, srcctx->siglen)) == NULL))
+ goto err;
return dstctx;
err:
if (!OSSL_PARAM_get_octet_string(p.sig, (void **)&pdsactx->sig,
0, &pdsactx->siglen))
return 0;
+ /* The signature must not be empty */
+ if (pdsactx->siglen == 0) {
+ OPENSSL_free(pdsactx->sig);
+ pdsactx->sig = NULL;
+ return 0;
+ }
}
}
return 1;