summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/ipmi/phosphor-ipmi-net/0012-crypt_algo-Null-check-on-Cipher-context.patch
blob: d4c6a3847a18221770fc9121a6d544d253f1e008 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
From 0b1184586b34ae40976e307d30fc44c3ed71dc11 Mon Sep 17 00:00:00 2001
From: P Dheeraj Srujan Kumar <p.dheeraj.srujan.kumar@intel.com>
Date: Fri, 25 Jun 2021 20:23:26 +0530
Subject: [PATCH] crypt_algo: Null check on Cipher context

There is no Null check performed while creating a new
Cipher contex. OPENSSL_zalloc can return NULL.

Tested: No regression observed

Change-Id: Ibc135adf9a20783c72116587ed3c45e3d457b3ad
Signed-off-by: P Dheeraj Srujan Kumar <p.dheeraj.srujan.kumar@intel.com>
---
 crypt_algo.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/crypt_algo.cpp b/crypt_algo.cpp
index c51465f..d5be1cb 100644
--- a/crypt_algo.cpp
+++ b/crypt_algo.cpp
@@ -103,6 +103,11 @@ std::vector<uint8_t> AlgoAES128::decryptData(const uint8_t* iv,
     // Initializes Cipher context
     EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
 
+    if (!ctx)
+    {
+        throw std::runtime_error("EVP_CIPHER_CTX failed");
+    }
+
     auto cleanupFunc = [](EVP_CIPHER_CTX* ctx) { EVP_CIPHER_CTX_free(ctx); };
 
     std::unique_ptr<EVP_CIPHER_CTX, decltype(cleanupFunc)> ctxPtr(ctx,
@@ -164,6 +169,11 @@ std::vector<uint8_t> AlgoAES128::encryptData(const uint8_t* input,
     // Initializes Cipher context
     EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
 
+    if (!ctx)
+    {
+        throw std::runtime_error("EVP_CIPHER_CTX failed");
+    }
+
     auto cleanupFunc = [](EVP_CIPHER_CTX* ctx) { EVP_CIPHER_CTX_free(ctx); };
 
     std::unique_ptr<EVP_CIPHER_CTX, decltype(cleanupFunc)> ctxPtr(ctx,
-- 
2.17.1