[edk2] [PATCH 17/17] BaseTools/GenSec: Fix potential null pointer dereference

Hao Wu posted 17 patches 7 years ago
[edk2] [PATCH 17/17] BaseTools/GenSec: Fix potential null pointer dereference
Posted by Hao Wu 7 years ago
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 BaseTools/Source/C/GenSec/GenSec.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec/GenSec.c
index 01d3bc4448..fb5bc5e992 100644
--- a/BaseTools/Source/C/GenSec/GenSec.c
+++ b/BaseTools/Source/C/GenSec/GenSec.c
@@ -1333,10 +1333,20 @@ Returns:
       DummyFileSize = ftell (DummyFile);
       fseek (DummyFile, 0, SEEK_SET);
       DummyFileBuffer = (UINT8 *) malloc (DummyFileSize);
+      if (DummyFileBuffer == NULL) {
+        fclose(DummyFile);
+        Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated");
+        goto Finish;
+      }
+
       fread(DummyFileBuffer, 1, DummyFileSize, DummyFile);
       fclose(DummyFile);
       DebugMsg (NULL, 0, 9, "Dummy files", "the dummy file name is %s and the size is %u bytes", DummyFileName, (unsigned) DummyFileSize);
 
+      if (InputFileName == NULL) {
+        Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated");
+        goto Finish;
+      }
       InFile = fopen(LongFilePath(InputFileName[0]), "rb");
       if (InFile == NULL) {
         Error (NULL, 0, 0001, "Error opening file", InputFileName[0]);
@@ -1347,6 +1357,12 @@ Returns:
       InFileSize = ftell (InFile);
       fseek (InFile, 0, SEEK_SET);
       InFileBuffer = (UINT8 *) malloc (InFileSize);
+      if (InFileBuffer == NULL) {
+        fclose(InFile);
+        Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated");
+        goto Finish;
+      }
+
       fread(InFileBuffer, 1, InFileSize, InFile);
       fclose(InFile);
       DebugMsg (NULL, 0, 9, "Input files", "the input file name is %s and the size is %u bytes", InputFileName[0], (unsigned) InFileSize);
-- 
2.12.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel