Skip to content

Commit

Permalink
Fix Coverity issue CID 488133
Browse files Browse the repository at this point in the history
A free() was used indtead of the proper OPENSSL_free()

While there reformatted the code to better conform to our style.

Signed-off-by: Simo Sorce <simo@redhat.com>
  • Loading branch information
simo5 committed Mar 19, 2024
1 parent 9884399 commit 7645f18
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,37 +470,38 @@ static P11PROV_PK11_URI *p11prov_encoder_private_key_to_asn1(P11PROV_CTX *pctx,
P11PROV_OBJ *key)
{
P11PROV_PK11_URI *out = NULL;
char *uri = NULL;
size_t uri_len;
int ret = RET_OSSL_ERR;

char *uri = p11prov_key_to_uri(pctx, key);
uri = p11prov_key_to_uri(pctx, key);
if (!uri) {
goto error;
goto done;
}

size_t uri_len = strlen(uri);
uri_len = strlen(uri);
P11PROV_debug("uri=%s", uri);

out = P11PROV_PK11_URI_new();
if (!out) {
goto error;
goto done;
}

if (!ASN1_STRING_set(out->desc, P11PROV_DESCS_URI_FILE,
sizeof(P11PROV_DESCS_URI_FILE) - 1)) {
goto error;
goto done;
}
if (!ASN1_STRING_set(out->uri, uri, uri_len)) {
goto error;
goto done;
}

goto done;

error:
P11PROV_PK11_URI_free(out);
out = NULL;
ret = RET_OSSL_OK;

done:
if (uri) {
free(uri);
OPENSSL_free(uri);
if (ret != RET_OSSL_OK) {
P11PROV_PK11_URI_free(out);
out = NULL;
}
return out;
}
Expand Down

0 comments on commit 7645f18

Please sign in to comment.