public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Hao Wu <hao.a.wu@intel.com>
To: edk2-devel@lists.01.org
Cc: Hao Wu <hao.a.wu@intel.com>, Liming Gao <liming.gao@intel.com>,
	Yonghong Zhu <yonghong.zhu@intel.com>
Subject: [PATCH 2/2] BaseTools/GenSec: Return correct status when input file size is 0
Date: Thu, 10 Nov 2016 12:22:18 +0800	[thread overview]
Message-ID: <1478751738-16372-3-git-send-email-hao.a.wu@intel.com> (raw)
In-Reply-To: <1478751738-16372-1-git-send-email-hao.a.wu@intel.com>

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>
---
 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



  parent reply	other threads:[~2016-11-10  4:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-10  4:22 [PATCH 0/2] Handle input file of size 0 for GenFfs/GenSec tools Hao Wu
2016-11-10  4:22 ` [PATCH 1/2] BaseTools/GenFfs: Fix return too early when input file is of size 0 Hao Wu
2016-11-10  4:22 ` Hao Wu [this message]
2016-11-10  5:05 ` [PATCH 0/2] Handle input file of size 0 for GenFfs/GenSec tools Gao, Liming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478751738-16372-3-git-send-email-hao.a.wu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox