]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/GenSec: Fix potential null pointer dereference
authorHao Wu <hao.a.wu@intel.com>
Mon, 18 Dec 2017 08:08:52 +0000 (16:08 +0800)
committerHao Wu <hao.a.wu@intel.com>
Mon, 25 Dec 2017 01:54:56 +0000 (09:54 +0800)
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/C/GenSec/GenSec.c

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