From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: bob.c.feng@intel.com) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by groups.io with SMTP; Fri, 10 May 2019 01:17:04 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 May 2019 01:17:04 -0700 X-ExtLoop1: 1 Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga004.fm.intel.com with ESMTP; 10 May 2019 01:17:04 -0700 Received: from fmsmsx111.amr.corp.intel.com (10.18.116.5) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 10 May 2019 01:17:04 -0700 Received: from shsmsx106.ccr.corp.intel.com (10.239.4.159) by fmsmsx111.amr.corp.intel.com (10.18.116.5) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 10 May 2019 01:17:03 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.129]) by SHSMSX106.ccr.corp.intel.com ([169.254.10.213]) with mapi id 14.03.0415.000; Fri, 10 May 2019 16:16:46 +0800 From: "Bob Feng" To: "Liu, Zhiguang" , "devel@edk2.groups.io" CC: "Gao, Liming" Subject: Re: [PATCH] BaseTools: Check the fread function and avoid dead loop Thread-Topic: [PATCH] BaseTools: Check the fread function and avoid dead loop Thread-Index: AQHVBtLVlNOvg6KCkkKLl3CoVPCSS6ZkA6ug Date: Fri, 10 May 2019 08:16:45 +0000 Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D16010A667@SHSMSX101.ccr.corp.intel.com> References: <20190510015032.2948-1-zhiguang.liu@intel.com> In-Reply-To: <20190510015032.2948-1-zhiguang.liu@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: bob.c.feng@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bob Feng -----Original Message----- From: Liu, Zhiguang=20 Sent: Friday, May 10, 2019 9:51 AM To: devel@edk2.groups.io Cc: Feng, Bob C ; Gao, Liming Subject: [PATCH] BaseTools: Check the fread function and avoid dead loop REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D1789 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 Cc: Bob Feng Cc: Liming Gao --- 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/VolI= nfo/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; =20 BytesRead =3D 0; Size =3D 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 =3D fread (&VolumeHeader, sizeof (EFI_FIRMWARE_VOLUME_HEADER)=20 + - sizeof (EFI_FV_BLOCK_MAP_ENTRY), 1, InputFile); if (ReadSize !=3D 1) { + return EFI_ABORTED; + } BytesRead =3D sizeof (EFI_FIRMWARE_VOLUME_HEADER) - sizeof (EFI_FV_B= LOCK_MAP_ENTRY); Signature[0] =3D VolumeHeader.Signature; Signature[1] =3D 0; @@ -1053,7 +1057,10 @@ Returns: printf ("Revision: 0x%04X\n", VolumeHeader.Revision); =20 do { - fread (&BlockMap, sizeof (EFI_FV_BLOCK_MAP_ENTRY), 1, InputFile); + ReadSize =3D fread (&BlockMap, sizeof (EFI_FV_BLOCK_MAP_ENTRY), 1, Inp= utFile); + if (ReadSize !=3D 1) { + return EFI_ABORTED; + } BytesRead +=3D sizeof (EFI_FV_BLOCK_MAP_ENTRY); =20 if (BlockMap.NumBlocks !=3D 0) { -- 2.21.0.windows.1