mirror of https://github.com/acidanthera/audk.git
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> Reviewed-by: Bob Feng <bob.c.feng@intel.com>
This commit is contained in:
parent
6b74ccf0f8
commit
ae3c247dbc
|
@ -751,6 +751,7 @@ Returns:
|
||||||
UINTN Signature[2];
|
UINTN Signature[2];
|
||||||
UINTN BytesRead;
|
UINTN BytesRead;
|
||||||
UINT32 Size;
|
UINT32 Size;
|
||||||
|
size_t ReadSize;
|
||||||
|
|
||||||
BytesRead = 0;
|
BytesRead = 0;
|
||||||
Size = 0;
|
Size = 0;
|
||||||
|
@ -764,7 +765,10 @@ Returns:
|
||||||
//
|
//
|
||||||
// Read the header
|
// 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);
|
BytesRead = sizeof (EFI_FIRMWARE_VOLUME_HEADER) - sizeof (EFI_FV_BLOCK_MAP_ENTRY);
|
||||||
Signature[0] = VolumeHeader.Signature;
|
Signature[0] = VolumeHeader.Signature;
|
||||||
Signature[1] = 0;
|
Signature[1] = 0;
|
||||||
|
@ -1053,7 +1057,10 @@ Returns:
|
||||||
printf ("Revision: 0x%04X\n", VolumeHeader.Revision);
|
printf ("Revision: 0x%04X\n", VolumeHeader.Revision);
|
||||||
|
|
||||||
do {
|
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);
|
BytesRead += sizeof (EFI_FV_BLOCK_MAP_ENTRY);
|
||||||
|
|
||||||
if (BlockMap.NumBlocks != 0) {
|
if (BlockMap.NumBlocks != 0) {
|
||||||
|
|
Loading…
Reference in New Issue