* [PATCH] BaseTools: Check the fread function and avoid dead loop
@ 2019-05-10 1:50 Zhiguang Liu
2019-05-10 8:16 ` Bob Feng
0 siblings, 1 reply; 2+ messages in thread
From: Zhiguang Liu @ 2019-05-10 1:50 UTC (permalink / raw)
To: devel; +Cc: Bob Feng, Liming Gao
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] BaseTools: Check the fread function and avoid dead loop
2019-05-10 1:50 [PATCH] BaseTools: Check the fread function and avoid dead loop Zhiguang Liu
@ 2019-05-10 8:16 ` Bob Feng
0 siblings, 0 replies; 2+ messages in thread
From: Bob Feng @ 2019-05-10 8:16 UTC (permalink / raw)
To: Liu, Zhiguang, devel@edk2.groups.io; +Cc: Gao, Liming
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
-----Original Message-----
From: Liu, Zhiguang
Sent: Friday, May 10, 2019 9:51 AM
To: devel@edk2.groups.io
Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [PATCH] BaseTools: Check the fread function and avoid dead loop
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-05-10 8:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-10 1:50 [PATCH] BaseTools: Check the fread function and avoid dead loop Zhiguang Liu
2019-05-10 8:16 ` Bob Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox