From a1fe73a1c799547208e7c2218f1c99578cc41683 Mon Sep 17 00:00:00 2001
From: Yingke Liu <yingke.d.liu@intel.com>
Date: Wed, 1 Jul 2015 05:16:46 +0000
Subject: BaseTools: Checked return value of malloc for EfiCompress.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yingke Liu <yingke.d.liu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17775 6f19259b-4bc3-4df7-8a09-765794883524
---
 BaseTools/Source/C/Common/EfiCompress.c | 7 +++++++
 1 file changed, 7 insertions(+)

(limited to 'BaseTools/Source')

diff --git a/BaseTools/Source/C/Common/EfiCompress.c b/BaseTools/Source/C/Common/EfiCompress.c
index bd86d1276a..b225fee913 100644
--- a/BaseTools/Source/C/Common/EfiCompress.c
+++ b/BaseTools/Source/C/Common/EfiCompress.c
@@ -408,6 +408,9 @@ Returns:
   UINT32      i;
   
   mText       = malloc (WNDSIZ * 2 + MAXMATCH);
+  if (mText == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
   for (i = 0 ; i < WNDSIZ * 2 + MAXMATCH; i ++) {
     mText[i] = 0;
   }
@@ -418,6 +421,10 @@ Returns:
   mParent     = malloc (WNDSIZ * 2 * sizeof(*mParent));
   mPrev       = malloc (WNDSIZ * 2 * sizeof(*mPrev));
   mNext       = malloc ((MAX_HASH_VAL + 1) * sizeof(*mNext));
+  if (mLevel == NULL || mChildCount == NULL || mPosition == NULL ||
+    mParent == NULL || mPrev == NULL || mNext == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
   
   mBufSiz = 16 * 1024U;
   while ((mBuf = malloc(mBufSiz)) == NULL) {
-- 
cgit v1.2.3