Skip to content

Commit

Permalink
card-epass2003: Check OpenSSL functions for error
Browse files Browse the repository at this point in the history
Thanks Coverity
CID 424593, 424594
  • Loading branch information
xhanulik committed Mar 21, 2024
1 parent a94af7f commit 993e646
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/libopensc/card-epass2003.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ openssl_enc(const EVP_CIPHER * cipher, const unsigned char *key, const unsigned
ctx = EVP_CIPHER_CTX_new();
if (ctx == NULL)
goto out;
EVP_EncryptInit_ex(ctx, cipher, NULL, key, iv_tmp);
EVP_CIPHER_CTX_set_padding(ctx, 0);

if (!EVP_EncryptInit_ex(ctx, cipher, NULL, key, iv_tmp) ||
!EVP_CIPHER_CTX_set_padding(ctx, 0))
goto out;

if (!EVP_EncryptUpdate(ctx, output, &outl, input, (int)length))
goto out;
Expand All @@ -304,8 +306,7 @@ openssl_enc(const EVP_CIPHER * cipher, const unsigned char *key, const unsigned

r = SC_SUCCESS;
out:
if (ctx)
EVP_CIPHER_CTX_free(ctx);
EVP_CIPHER_CTX_free(ctx);
return r;
}

Expand All @@ -323,8 +324,10 @@ openssl_dec(const EVP_CIPHER * cipher, const unsigned char *key, const unsigned
ctx = EVP_CIPHER_CTX_new();
if (ctx == NULL)
goto out;
EVP_DecryptInit_ex(ctx, cipher, NULL, key, iv_tmp);
EVP_CIPHER_CTX_set_padding(ctx, 0);

if (!EVP_DecryptInit_ex(ctx, cipher, NULL, key, iv_tmp) ||
!EVP_CIPHER_CTX_set_padding(ctx, 0))
goto out;

if (!EVP_DecryptUpdate(ctx, output, &outl, input, (int)length))
goto out;
Expand All @@ -334,8 +337,7 @@ openssl_dec(const EVP_CIPHER * cipher, const unsigned char *key, const unsigned

r = SC_SUCCESS;
out:
if (ctx)
EVP_CIPHER_CTX_free(ctx);
EVP_CIPHER_CTX_free(ctx);
return r;
}

Expand Down

0 comments on commit 993e646

Please sign in to comment.