summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHao Wu <hao.a.wu@intel.com>2016-11-09 23:00:01 +0800
committerHao Wu <hao.a.wu@intel.com>2016-11-10 16:28:33 +0800
commitb390737ad03a354f5d11954950a580df715e2935 (patch)
tree294d67d84835f12771abb1f6d67efc455bffe06e
parent8009b2e47ff4d877879b6dded83a4d9adb4445d2 (diff)
downloadedk2-platforms-b390737ad03a354f5d11954950a580df715e2935.tar.xz
BaseTools/GenFfs: Fix return too early when input file is of size 0
Commit 2cb874352423fcfd180199e6de8298567dff8e7f eliminates possible NULL pointer dereference in GenFfs tool source codes. However, it doesn't correctly handle the case when the input file is of size 0. This will lead to possible build issues. This commits refine the logic to handle the above case. 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.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/BaseTools/Source/C/GenFfs/GenFfs.c b/BaseTools/Source/C/GenFfs/GenFfs.c
index 78e5097fb4..c5d657bd09 100644
--- a/BaseTools/Source/C/GenFfs/GenFfs.c
+++ b/BaseTools/Source/C/GenFfs/GenFfs.c
@@ -842,7 +842,12 @@ Returns:
);
}
- if (EFI_ERROR (Status) || (FileBuffer == NULL)) {
+ if (EFI_ERROR (Status)) {
+ goto Finish;
+ }
+
+ if (FileBuffer == NULL && FileSize != 0) {
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");
goto Finish;
}
@@ -929,7 +934,9 @@ Returns:
//
// write data
//
- fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);
+ if (FileBuffer != NULL) {
+ fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);
+ }
fclose (FfsFile);
}