From: "Zhiguang Liu" <zhiguang.liu@intel.com>
To: devel@edk2.groups.io
Cc: Bob Feng <bob.c.feng@intel.com>, Liming Gao <liming.gao@intel.com>
Subject: [PATCH] BaseTools: Check the fread function and avoid dead loop
Date: Fri, 10 May 2019 09:50:32 +0800 [thread overview]
Message-ID: <20190510015032.2948-1-zhiguang.liu@intel.com> (raw)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1789
If the input file is not a valid file, it may cause dead loop,
because the return of fread function is not checked.
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
BaseTools/Source/C/VolInfo/VolInfo.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/BaseTools/Source/C/VolInfo/VolInfo.c b/BaseTools/Source/C/VolInfo/VolInfo.c
index d8216c61e8..ffe0b47f03 100644
--- a/BaseTools/Source/C/VolInfo/VolInfo.c
+++ b/BaseTools/Source/C/VolInfo/VolInfo.c
@@ -751,6 +751,7 @@ Returns:
UINTN Signature[2];
UINTN BytesRead;
UINT32 Size;
+ size_t ReadSize;
BytesRead = 0;
Size = 0;
@@ -764,7 +765,10 @@ Returns:
//
// Read the header
//
- fread (&VolumeHeader, sizeof (EFI_FIRMWARE_VOLUME_HEADER) - sizeof (EFI_FV_BLOCK_MAP_ENTRY), 1, InputFile);
+ ReadSize = fread (&VolumeHeader, sizeof (EFI_FIRMWARE_VOLUME_HEADER) - sizeof (EFI_FV_BLOCK_MAP_ENTRY), 1, InputFile);
+ if (ReadSize != 1) {
+ return EFI_ABORTED;
+ }
BytesRead = sizeof (EFI_FIRMWARE_VOLUME_HEADER) - sizeof (EFI_FV_BLOCK_MAP_ENTRY);
Signature[0] = VolumeHeader.Signature;
Signature[1] = 0;
@@ -1053,7 +1057,10 @@ Returns:
printf ("Revision: 0x%04X\n", VolumeHeader.Revision);
do {
- fread (&BlockMap, sizeof (EFI_FV_BLOCK_MAP_ENTRY), 1, InputFile);
+ ReadSize = fread (&BlockMap, sizeof (EFI_FV_BLOCK_MAP_ENTRY), 1, InputFile);
+ if (ReadSize != 1) {
+ return EFI_ABORTED;
+ }
BytesRead += sizeof (EFI_FV_BLOCK_MAP_ENTRY);
if (BlockMap.NumBlocks != 0) {
--
2.21.0.windows.1
next reply other threads:[~2019-05-10 1:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-10 1:50 Zhiguang Liu [this message]
2019-05-10 8:16 ` [PATCH] BaseTools: Check the fread function and avoid dead loop Bob Feng
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=20190510015032.2948-1-zhiguang.liu@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