From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id DDC7C203B8CCD for ; Thu, 17 May 2018 01:04:34 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 May 2018 01:04:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,409,1520924400"; d="scan'208";a="41962915" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga008.jf.intel.com with ESMTP; 17 May 2018 01:04:34 -0700 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 17 May 2018 01:04:34 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by fmsmsx158.amr.corp.intel.com (10.18.116.75) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 17 May 2018 01:04:34 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.240]) by shsmsx102.ccr.corp.intel.com ([169.254.2.79]) with mapi id 14.03.0319.002; Thu, 17 May 2018 16:04:31 +0800 From: "Ni, Ruiyu" To: =?iso-8859-1?Q?Marvin_H=E4user?= , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" , "Gao, Liming" Thread-Topic: [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL dereference. Thread-Index: AQHT5K62NvsEKeSdZUOXJy6ivfNYY6QzoZow Date: Thu, 17 May 2018 08:04:30 +0000 Deferred-Delivery: Thu, 17 May 2018 08:04:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BC9E8E9@SHSMSX104.ccr.corp.intel.com> References: In-Reply-To: Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL dereference. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 May 2018 08:04:35 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ruiyu Ni Thanks/Ray > -----Original Message----- > From: edk2-devel On Behalf Of Marvin > H=E4user > Sent: Sunday, May 6, 2018 4:22 AM > To: edk2-devel@lists.01.org > Cc: Kinney, Michael D ; Gao, Liming > > Subject: [edk2] [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL > dereference. >=20 > Move the NULL-check in FileHandleGetInfo() to directly after the > allocation to prevent potential NULL dereferences. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Marvin Haeuser > --- > MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c | 30 +++++++++++--- > ------ > 1 file changed, 16 insertions(+), 14 deletions(-) >=20 > diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c > b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c > index 57aad77bc135..bcf3a328b82d 100644 > --- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c > +++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c > @@ -1,7 +1,7 @@ > /** @file > Provides interface to EFI_FILE_HANDLE functionality. >=20 > - Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved. > + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -74,19 +74,21 @@ FileHandleGetInfo ( > // error is expected. getting size to allocate > // > FileInfo =3D AllocateZeroPool(FileInfoSize); > - // > - // now get the information > - // > - Status =3D FileHandle->GetInfo(FileHandle, > - &gEfiFileInfoGuid, > - &FileInfoSize, > - FileInfo); > - // > - // if we got an error free the memory and return NULL > - // > - if (EFI_ERROR(Status) && (FileInfo !=3D NULL)) { > - FreePool(FileInfo); > - FileInfo =3D NULL; > + if (FileInfo !=3D NULL) { > + // > + // now get the information > + // > + Status =3D FileHandle->GetInfo(FileHandle, > + &gEfiFileInfoGuid, > + &FileInfoSize, > + FileInfo); > + // > + // if we got an error free the memory and return NULL > + // > + if (EFI_ERROR(Status)) { > + FreePool(FileInfo); > + FileInfo =3D NULL; > + } > } > } > return (FileInfo); > -- > 2.17.0.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel