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 1/2] BaseTools/GenFfs: Fix return too early when input file is of size 0
Date: Thu, 10 Nov 2016 12:22:17 +0800 [thread overview]
Message-ID: <1478751738-16372-2-git-send-email-hao.a.wu@intel.com> (raw)
In-Reply-To: <1478751738-16372-1-git-send-email-hao.a.wu@intel.com>
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>
---
BaseTools/Source/C/GenFfs/GenFfs.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/BaseTools/Source/C/GenFfs/GenFfs.c b/BaseTools/Source/C/GenFfs/GenFfs.c
index 78e5097..c5d657b 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);
}
--
1.9.5.msysgit.0
next prev 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 ` Hao Wu [this message]
2016-11-10 4:22 ` [PATCH 2/2] BaseTools/GenSec: Return correct status when input file size is 0 Hao Wu
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-2-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