summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHao Wu <hao.a.wu@intel.com>2016-10-11 10:13:26 +0800
committerHao Wu <hao.a.wu@intel.com>2016-11-08 16:36:14 +0800
commit2cb874352423fcfd180199e6de8298567dff8e7f (patch)
treed3b40ebfb24a78cb936a77005aff890c592d0a39
parent02875ba228545f506cb40cfc8a20a4e067fb2a9f (diff)
downloadedk2-2cb874352423fcfd180199e6de8298567dff8e7f.zip
edk2-2cb874352423fcfd180199e6de8298567dff8e7f.tar.gz
edk2-2cb874352423fcfd180199e6de8298567dff8e7f.tar.bz2
BaseTools/GenFfs: Avoid possible NULL pointer dereference
Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
-rw-r--r--BaseTools/Source/C/GenFfs/GenFfs.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/BaseTools/Source/C/GenFfs/GenFfs.c b/BaseTools/Source/C/GenFfs/GenFfs.c
index 9a738cb..78e5097 100644
--- a/BaseTools/Source/C/GenFfs/GenFfs.c
+++ b/BaseTools/Source/C/GenFfs/GenFfs.c
@@ -1,7 +1,7 @@
/** @file
This file contains functions required to generate a Firmware File System file.
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -842,7 +842,7 @@ Returns:
);
}
- if (EFI_ERROR (Status)) {
+ if (EFI_ERROR (Status) || (FileBuffer == NULL)) {
goto Finish;
}
@@ -915,22 +915,24 @@ Returns:
//
// Open output file to write ffs data.
//
- remove(OutputFileName);
- FfsFile = fopen (LongFilePath (OutputFileName), "wb");
- if (FfsFile == NULL) {
- Error (NULL, 0, 0001, "Error opening file", OutputFileName);
- goto Finish;
- }
- //
- // write header
- //
- fwrite (&FfsFileHeader, 1, HeaderSize, FfsFile);
- //
- // write data
- //
- fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);
+ if (OutputFileName != NULL) {
+ remove(OutputFileName);
+ FfsFile = fopen (LongFilePath (OutputFileName), "wb");
+ if (FfsFile == NULL) {
+ Error (NULL, 0, 0001, "Error opening file", OutputFileName);
+ goto Finish;
+ }
+ //
+ // write header
+ //
+ fwrite (&FfsFileHeader, 1, HeaderSize, FfsFile);
+ //
+ // write data
+ //
+ fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);
- fclose (FfsFile);
+ fclose (FfsFile);
+ }
Finish:
if (InputFileName != NULL) {