From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.92.64.86; helo=eur01-db5-obe.outbound.protection.outlook.com; envelope-from=marvin.haeuser@outlook.com; receiver=edk2-devel@lists.01.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-oln040092064086.outbound.protection.outlook.com [40.92.64.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D802B2033D1B1 for ; Sat, 5 May 2018 13:22:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=8EhEK4mH5ZcSPEqviF7yGmQaMT/mY5dAeXM3i1bgym4=; b=n4Zef/HgfIbt4kVQwtKgR4YnF4kHpv4hEk1jQYXSHBR4P4PFoVJoDLCr4wgQrjIoKqbAHH1xEQTqRSFi2kakNtUud97rJV1mhS1N/PfCplnNhH2S9AKgflr07j1/Y7s1o5XnO8XzB11is3iloKARJ8DpDQYeKUThanzk9PK7HrKqieUWxodiids8KEPjrBwBN1kPkO52HUSuOkJkmgGlzMyMFvPmeznDBSsuC298p86GQyyNQocpyt0oJ27EgL87g+QK3ZPIQ2yX+j6lcZgYduDH/K9FrbWUX0Et+B+LqjUwNvCCIeCksoMN9H2gWLXsRDtl2VGpZpdvCH0Yv2ZGHQ== Received: from DB5EUR01FT060.eop-EUR01.prod.protection.outlook.com (10.152.4.55) by DB5EUR01HT066.eop-EUR01.prod.protection.outlook.com (10.152.5.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.735.16; Sat, 5 May 2018 20:21:56 +0000 Received: from VI1PR0801MB1790.eurprd08.prod.outlook.com (10.152.4.51) by DB5EUR01FT060.mail.protection.outlook.com (10.152.5.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.735.16 via Frontend Transport; Sat, 5 May 2018 20:21:56 +0000 Received: from VI1PR0801MB1790.eurprd08.prod.outlook.com ([fe80::7c79:584b:2e12:783e]) by VI1PR0801MB1790.eurprd08.prod.outlook.com ([fe80::7c79:584b:2e12:783e%17]) with mapi id 15.20.0715.024; Sat, 5 May 2018 20:21:55 +0000 From: =?iso-8859-1?Q?Marvin_H=E4user?= To: "edk2-devel@lists.01.org" CC: "michael.d.kinney@intel.com" , "liming.gao@intel.com" Thread-Topic: [PATCH] MdePkg/UefiFileHandleLib: Fix potential NULL dereference. Thread-Index: AQHT5K62NvsEKeSdZUOXJy6ivfNYYw== Date: Sat, 5 May 2018 20:21:55 +0000 Message-ID: Accept-Language: de-DE, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM5PR0701CA0064.eurprd07.prod.outlook.com (2603:10a6:203:2::26) To VI1PR0801MB1790.eurprd08.prod.outlook.com (2603:10a6:800:5b::15) x-incomingtopheadermarker: OriginalChecksum:F8FF27A89207430583C011B5F141CD34DEF2CEAC307C6FBB97AB8B2EC6F0925D; UpperCasedChecksum:6938409988CF2AD92584C4DA2BEB03FCDA7C3056C2C52625279B4D9CFAAF84C1; SizeAsReceived:7490; Count:48 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [amQzpn1rqFE7OQOBwWzDib/SKFQTTJ2L] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB5EUR01HT066; 7:Qu7chksVbiZLKExnhhn8d7mXB01ta0QSWj8loygbeHRTV9z6HhkvU9INtauBB7quHaqz8gyOEdfe9FHffxwmQYH03CsU6ADPWXkrwMnL7yU01+SvYnRBRL1h/qS8u2xM4gkXNyaiJ9JpcttTJrkWAgfXoyPpCILkWoOmpaUE7g1ljy0u8pYW5b8cjTL4EPeufoUHPAwoDkZlxWpHv0NACxusYJpk9i5nXCenL3qQNsbKu04zTbPcQOZ7zEudy2+D x-incomingheadercount: 48 x-eopattributedmessage: 0 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322404)(1603101448)(1601125374)(1701031045); SRVR:DB5EUR01HT066; x-ms-traffictypediagnostic: DB5EUR01HT066: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(444000031); SRVR:DB5EUR01HT066; BCL:0; PCL:0; RULEID:; SRVR:DB5EUR01HT066; x-forefront-prvs: 0663390E1B x-forefront-antispam-report: SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:DB5EUR01HT066; H:VI1PR0801MB1790.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:; x-microsoft-antispam-message-info: d/c0Xm5P21sQ/xwuLngDS79M+cdnwAwXajMYliPTywSJIdLgnc59Vdgp24qiG7wTtpJO4rVfiabipcKDyVqVfnbPwncpSIYH8ygShtlsfON3juXdvmj/sa8+ec/X/dCI34IKGYcWMpkfY5Lq3CAikSIlDaGOtAF+guM4DLYY6R7Wwrz5mnv7XZWybns4f0Za MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 61c77192-3239-457c-1cd0-08d5b2c5d855 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 7181d4b0-87d6-4f4e-ba33-0d3746212cec X-MS-Exchange-CrossTenant-Network-Message-Id: 61c77192-3239-457c-1cd0-08d5b2c5d855 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 7181d4b0-87d6-4f4e-ba33-0d3746212cec X-MS-Exchange-CrossTenant-originalarrivaltime: 05 May 2018 20:21:55.7113 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5EUR01HT066 Subject: [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: Sat, 05 May 2018 20:22:03 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Move the NULL-check in FileHandleGetInfo() to directly after the allocation to prevent potential NULL dereferences. 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(-) 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 BS= D License which accompanies this distribution. The full text of the license may b= e 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); --=20 2.17.0.windows.1