From c52f00d6e1e14b9eaf5c5a58501f075d2a64920c Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Thu, 10 Nov 2016 09:43:07 +0800 Subject: BaseTools/GenSec: Return correct status when input file size is 0 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/GenSec/GenSec.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'BaseTools/Source') diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec/GenSec.c index 87d4fa88b9..9129b5067e 100644 --- a/BaseTools/Source/C/GenSec/GenSec.c +++ b/BaseTools/Source/C/GenSec/GenSec.c @@ -897,16 +897,22 @@ Returns: return Status; } - if (FileBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - if (InputLength == 0) { - free (FileBuffer); + if (FileBuffer != NULL) { + free (FileBuffer); + } Error (NULL, 0, 2000, "Invalid parameter", "the size of input file %s can't be zero", InputFileName); return EFI_NOT_FOUND; } + // + // InputLength != 0, but FileBuffer == NULL means out of resources. + // + if (FileBuffer == NULL) { + Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); + return EFI_OUT_OF_RESOURCES; + } + // // Now data is in FileBuffer + Offset // -- cgit v1.2.3