Added check for null return when calling EVP_CIPHER_CTX_new
diff --git a/build.sh b/build.sh
old mode 100644
new mode 100755
diff --git a/src/openssl.c b/src/openssl.c
index c8e668d..75bc5eb 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -36,6 +36,7 @@
#endif
ctx = EVP_CIPHER_CTX_new();
+ if (ctx == NULL) goto errorReturn;
// Setup the IV/Nonce and put it into the message
@@ -119,6 +120,7 @@
cn_cbor_errback cbor_error;
ctx = EVP_CIPHER_CTX_new();
+ if (ctx == NULL) goto errorReturn;
switch (cbKey*8) {
case 128:
@@ -215,6 +217,7 @@
int TSize = 128 / 8;
ctx = EVP_CIPHER_CTX_new();
+ if (ctx == NULL) goto errorReturn;
// Setup the IV/Nonce and put it into the message
@@ -307,6 +310,7 @@
// Make it first so we can clean it up
ctx = EVP_CIPHER_CTX_new();
+ if (ctx == NULL) goto errorReturn;
// Setup the IV/Nonce and put it into the message
@@ -397,6 +401,7 @@
#endif
ctx = EVP_CIPHER_CTX_new();
+ if (ctx == NULL) goto errorReturn;
rgbOut = COSE_CALLOC(16, 1, context);
CHECK_CONDITION(rgbOut != NULL, COSE_ERR_OUT_OF_MEMORY);
@@ -469,6 +474,7 @@
// Setup and run the OpenSSL code
ctx = EVP_CIPHER_CTX_new();
+ if (ctx == NULL) goto errorReturn;
CHECK_CONDITION(EVP_EncryptInit_ex(ctx, pcipher, NULL, pbKey, rgbIV), COSE_ERR_CRYPTO_FAIL);
TSize /= 8;
@@ -558,6 +564,7 @@
UNUSED(pcose);
ctx = EVP_CIPHER_CTX_new();
+ if (ctx == NULL) goto errorReturn;
switch (cbitKey) {
case 128: