From nobody Thu May 2 08:53:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=outlook.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1526560906176813.4659953147631; Thu, 17 May 2018 05:41:46 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AA4F6207E36C1; Thu, 17 May 2018 05:41:44 -0700 (PDT) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-oln040092066037.outbound.protection.outlook.com [40.92.66.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E085C2063D742 for ; Thu, 17 May 2018 05:41:42 -0700 (PDT) Received: from HE1EUR01FT049.eop-EUR01.prod.protection.outlook.com (10.152.0.56) by HE1EUR01HT163.eop-EUR01.prod.protection.outlook.com (10.152.1.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.735.16; Thu, 17 May 2018 12:41:39 +0000 Received: from VI1PR0801MB1790.eurprd08.prod.outlook.com (10.152.0.56) by HE1EUR01FT049.mail.protection.outlook.com (10.152.0.221) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.776.10 via Frontend Transport; Thu, 17 May 2018 12:41:40 +0000 Received: from VI1PR0801MB1790.eurprd08.prod.outlook.com ([fe80::7010:5d5e:8dcf:d92e]) by VI1PR0801MB1790.eurprd08.prod.outlook.com ([fe80::7010:5d5e:8dcf:d92e%17]) with mapi id 15.20.0776.010; Thu, 17 May 2018 12:41:39 +0000 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.92.66.37; helo=eur01-ve1-obe.outbound.protection.outlook.com; envelope-from=marvin.haeuser@outlook.com; receiver=edk2-devel@lists.01.org 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:X-MS-Exchange-SenderADCheck; bh=eKX4TtJWmpZY13sDqZQ9Sb+H2V7XZ8xhH9qHqCebIfs=; b=HPJ2vIUUTL3rkyjjkZ1ft7ynEq7De+QnXdpXPfwmujLxh6svcmDwRshvJKU6eoeVNV5iAB/VeAcZMvllhvQ4DPtNcjg+wjeOPHGLQbPJhy/dVKF4+dXnrPyHkn/WI1t62SdA+ReFTKKXYeTWaTMOBaXjztUI/JaMqlN7/Ena6KvbfIDuNhdofj95jQBN7aFYz0Viz1Gh4++31bGuq4if4PxO16Gadnd6EvJ9BwwTaLM3jtGoFhouUfJelEZi2sm+9nXkcRTBjqVVgpZ7BaIUFigGdqXCd4fNjGDLoWqus2yLlvCI9fA2Pt8NEDNnW5bnmxRJisSSaUzCyxAQT6L5HQ== From: =?iso-8859-1?Q?Marvin_H=E4user?= To: "edk2-devel@lists.01.org" Thread-Topic: [PATCH v2] MdePkg/UefiFileHandleLib: Fix potential NULL dereference. Thread-Index: AQHT7dxmzOfOdLjaVEqFQMQHvQoxSQ== Date: Thu, 17 May 2018 12:41:39 +0000 Message-ID: References: <396ef0a31f51da8581a8100ed1c6a6358974038e.1526560735.git.Marvin.Haeuser@outlook.com> In-Reply-To: <396ef0a31f51da8581a8100ed1c6a6358974038e.1526560735.git.Marvin.Haeuser@outlook.com> Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM0PR0102CA0046.eurprd01.prod.exchangelabs.com (2603:10a6:208::23) To VI1PR0801MB1790.eurprd08.prod.outlook.com (2603:10a6:800:5b::15) x-incomingtopheadermarker: OriginalChecksum:908D071E305EF972CE5DE2FF747958BF2E7C6CAA02E89F52C7D01A7F839D5FD6; UpperCasedChecksum:8DE4CB7D021DDF7A0761C1940E9C447ED6B7CF85E497539073E63FFE64FB5070; SizeAsReceived:7698; Count:50 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [1il2Y27gjBvRb0Z+h3PMuC6MLdKAz9Jj] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1EUR01HT163; 7:gr1r3APRrcvSWAX0Kl4bfeHeOE0TH0J7J9h+d8X+eTExFTzYbz5dEjVHuEPEwy+etCQ1B4e5uVw0LDBeJ/KTnIViYwaBI32NQNKjnXzVrjiX5i5hfHkETaJ0mE+D9IB41LTBpD5gaiVxsXFvVGV9+kOykTp97i9WoC6LC8GTWl2LGgdGlKMiRHEHCJufgmIAs30A3UJmI2opqa5/0H+0om6etynkCf/sdosYIFXKOHbhI0FswZM2deYv4nxb6m2e x-incomingheadercount: 50 x-eopattributedmessage: 0 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322404)(1601125466)(1603101448)(1701031045); SRVR:HE1EUR01HT163; x-ms-traffictypediagnostic: HE1EUR01HT163: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(444000031); SRVR:HE1EUR01HT163; BCL:0; PCL:0; RULEID:; SRVR:HE1EUR01HT163; x-forefront-prvs: 067553F396 x-forefront-antispam-report: SFV:NSPM; SFS:(7070007)(189003)(199004)(2351001)(87572001)(33656002)(5660300001)(6436002)(3280700002)(86362001)(97736004)(72206003)(3660700001)(106356001)(105586002)(25786009)(14454004)(2900100001)(104016004)(305945005)(386003)(5640700003)(8936002)(7696005)(74316002)(4326008)(55016002)(2501003)(6346003)(20460500001)(5250100002)(99286004)(68736007)(102836004)(486006)(446003)(476003)(76176011)(8676002)(54906003)(82202002)(81156014)(426003)(11346002)(6916009)(26005); DIR:OUT; SFP:1901; SCL:1; SRVR:HE1EUR01HT163; H:VI1PR0801MB1790.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:; received-spf: None (protection.outlook.com: outlook.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Marvin.Haeuser@outlook.com; x-microsoft-antispam-message-info: dg7tlNcd/mdm9KSDPtsseotTxZ4n1N+KHJtSSYEQ16BRoQA+Cp49CS6LnxqC6Vi9403Y0SNlZTJ/XPV5yRkt6g450WUsOwDtDCuug1cZV2XhEBaAW5bMf6iS4pMzFIy/9Pro4zVbkegsQaf5L66YDKDqPFIBwgARhmg5gUUuDV+eQFVlTo1ioPCxdOmqmTgh MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: b631f5bc-4319-4da8-7199-08d5bbf388fc X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 7181d4b0-87d6-4f4e-ba33-0d3746212cec X-MS-Exchange-CrossTenant-Network-Message-Id: b631f5bc-4319-4da8-7199-08d5bbf388fc X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 7181d4b0-87d6-4f4e-ba33-0d3746212cec X-MS-Exchange-CrossTenant-originalarrivaltime: 17 May 2018 12:41:39.8579 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1EUR01HT163 Subject: [edk2] [PATCH v2] 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: , Cc: "michael.d.kinney@intel.com" , "liming.gao@intel.com" Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move the NULL-check in FileHandleGetInfo() to directly after the allocation to prevent potential NULL dereferences. V2: - Do not change the copyright date as requested. - Added R-bs from V1 as no functional changes have been made. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marvin Haeuser Reviewed-by: Ruiyu Ni --- MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c | 28 +++++++++++-----= ---- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c b/MdePkg/= Library/UefiFileHandleLib/UefiFileHandleLib.c index 57aad77bc135..5b3d39ef6103 100644 --- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c +++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c @@ -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 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel