Skip to content

Commit 993e646

Browse files
committed
card-epass2003: Check OpenSSL functions for error
Thanks Coverity CID 424593, 424594
1 parent a94af7f commit 993e646

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/libopensc/card-epass2003.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,10 @@ openssl_enc(const EVP_CIPHER * cipher, const unsigned char *key, const unsigned
293293
ctx = EVP_CIPHER_CTX_new();
294294
if (ctx == NULL)
295295
goto out;
296-
EVP_EncryptInit_ex(ctx, cipher, NULL, key, iv_tmp);
297-
EVP_CIPHER_CTX_set_padding(ctx, 0);
296+
297+
if (!EVP_EncryptInit_ex(ctx, cipher, NULL, key, iv_tmp) ||
298+
!EVP_CIPHER_CTX_set_padding(ctx, 0))
299+
goto out;
298300

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

305307
r = SC_SUCCESS;
306308
out:
307-
if (ctx)
308-
EVP_CIPHER_CTX_free(ctx);
309+
EVP_CIPHER_CTX_free(ctx);
309310
return r;
310311
}
311312

@@ -323,8 +324,10 @@ openssl_dec(const EVP_CIPHER * cipher, const unsigned char *key, const unsigned
323324
ctx = EVP_CIPHER_CTX_new();
324325
if (ctx == NULL)
325326
goto out;
326-
EVP_DecryptInit_ex(ctx, cipher, NULL, key, iv_tmp);
327-
EVP_CIPHER_CTX_set_padding(ctx, 0);
327+
328+
if (!EVP_DecryptInit_ex(ctx, cipher, NULL, key, iv_tmp) ||
329+
!EVP_CIPHER_CTX_set_padding(ctx, 0))
330+
goto out;
328331

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

335338
r = SC_SUCCESS;
336339
out:
337-
if (ctx)
338-
EVP_CIPHER_CTX_free(ctx);
340+
EVP_CIPHER_CTX_free(ctx);
339341
return r;
340342
}
341343

0 commit comments

Comments
 (0)