summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/C/GenSec
diff options
context:
space:
mode:
authorHao Wu <hao.a.wu@intel.com>2017-12-18 16:08:52 +0800
committerHao Wu <hao.a.wu@intel.com>2017-12-25 09:54:56 +0800
commitc40dbe5e7bf9f3f841d4f1c717c245e99854b786 (patch)
tree665a8eaa3cc841d78dd2b5b8f4a0cbe85e466aa9 /BaseTools/Source/C/GenSec
parentae0fbb7f5ad41866bca89320f501282e173b373d (diff)
downloadedk2-c40dbe5e7bf9f3f841d4f1c717c245e99854b786.tar.gz
edk2-c40dbe5e7bf9f3f841d4f1c717c245e99854b786.tar.bz2
edk2-c40dbe5e7bf9f3f841d4f1c717c245e99854b786.zip
BaseTools/GenSec: Fix potential null pointer dereference
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>
Diffstat (limited to 'BaseTools/Source/C/GenSec')
-rw-r--r--BaseTools/Source/C/GenSec/GenSec.c16
1 files changed, 16 insertions, 0 deletions
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);