From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8DF8B81C93 for ; Wed, 9 Nov 2016 20:22:25 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP; 09 Nov 2016 20:22:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,616,1473145200"; d="scan'208";a="784684331" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.34]) by FMSMGA003.fm.intel.com with ESMTP; 09 Nov 2016 20:22:27 -0800 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Liming Gao , Yonghong Zhu Date: Thu, 10 Nov 2016 12:22:18 +0800 Message-Id: <1478751738-16372-3-git-send-email-hao.a.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1478751738-16372-1-git-send-email-hao.a.wu@intel.com> References: <1478751738-16372-1-git-send-email-hao.a.wu@intel.com> Subject: [PATCH 2/2] BaseTools/GenSec: Return correct status when input file size is 0 X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Nov 2016 04:22:25 -0000 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu --- BaseTools/Source/C/GenSec/GenSec.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec/GenSec.c index 87d4fa8..9129b50 100644 --- a/BaseTools/Source/C/GenSec/GenSec.c +++ b/BaseTools/Source/C/GenSec/GenSec.c @@ -897,17 +897,23 @@ 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 // if (CompareGuid (VendorGuid, &mZeroGuid) == 0) { -- 1.9.5.msysgit.0