Fix Kloxwork Issue : NULL check after new
A unique pointer of EVP_CIPHER_CTX is created using EVP_CIPHER_CTX_new()
which could return NULL.
This Commit adds a NULL check to avoid NULL pointer dereferencing and
returns memory error.
Signed-off-by: P Dheeraj Srujan Kumar <p.dheeraj.srujan.kumar@intel.com>
Change-Id: Icbc599210034feb6f7b3c35542bcfff205987628
diff --git a/user_channel/passwd_mgr.cpp b/user_channel/passwd_mgr.cpp
index 345f3cc..939f48f 100644
--- a/user_channel/passwd_mgr.cpp
+++ b/user_channel/passwd_mgr.cpp
@@ -177,6 +177,12 @@
EVP_CIPHER_CTX_new(), ::EVP_CIPHER_CTX_free);
EVP_CIPHER_CTX_set_padding(ctx.get(), 1);
+ if (!ctx)
+ {
+ log<level::DEBUG>("Error: EVP_CIPHER_CTX is NULL");
+ return -ENOMEM;
+ }
+
// Set key & IV
int retval = EVP_CipherInit_ex(ctx.get(), cipher, NULL, key, iv,
static_cast<int>(doEncrypt));