BaseTools/GenFfs: Fix return too early when input file is of size 0

Commit 2cb8743524 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>
This commit is contained in:
Hao Wu 2016-11-09 23:00:01 +08:00
parent 8009b2e47f
commit b390737ad0
1 changed files with 9 additions and 2 deletions

View File

@ -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
//
if (FileBuffer != NULL) {
fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);
}
fclose (FfsFile);
}