From nobody Fri May 3 14:13:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+39454+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+39454+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1556082353; cv=none; d=zoho.com; s=zohoarc; b=D72DboUjl+fppQZH4vYjmDAp/eg5aBwgt/I68E4WbyJwo41GZ336+GXsOqxiQ3/4UnRQaw1RoMNCA1OkK8B2gev84Pz5rsvPMMuv9G3Q/+nBv1sz9abWccEMT9w0p85VaWzGsvoVjbvpt0S5eVU4RCcjczu0LUHFD4HS14oZlMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556082353; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=0UP2EPKEBJg12jQoylfesTYXTr54mweVj8+VC/M4V4g=; b=mRlg+SR+3tMn0yG+lBg063P4zKDWQrWzMrYtzANYCixR9OGKG3KTU1IQH7XceKNgqXJKj7gxFkIzTfIkuZKwr8sg9bnn0XIXjNaUP3rMK0gC1r0PukKdzI8MVfEWBHxfvtUGJQaoiV5/tpmUEl4nxqjP0PiuzKANawBWvFLc5yI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+39454+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1556082353766587.7164159630722; Tue, 23 Apr 2019 22:05:53 -0700 (PDT) Return-Path: X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by groups.io with SMTP; Tue, 23 Apr 2019 22:05:52 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Apr 2019 22:05:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,388,1549958400"; d="scan'208";a="340269821" X-Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.8]) by fmsmga006.fm.intel.com with ESMTP; 23 Apr 2019 22:05:51 -0700 From: "Wu, Hao A" To: devel@edk2.groups.io Cc: Hao Wu , Ard Biesheuvel , Michael D Kinney , Liming Gao , Jian J Wang Subject: [edk2-devel] [PATCH v2] MdeModulePkg/DxeCore: Please static checker for false report Date: Wed, 24 Apr 2019 13:05:49 +0800 Message-Id: <20190424050549.6760-1-hao.a.wu@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,hao.a.wu@intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1556082353; bh=OmdD9jDVQTJFjDNtyfQp1jZFygI+zuYMwHL2zFNsH94=; h=Cc:Date:From:Reply-To:Subject:To; b=YE8pAd8WDDgi391SyhKHbrYrUjTme0A18EKK6RxpnUgNmD7V+5B46ol9tAzdaiLZrCW mJIjxXNpMQgb5ALL4Dar+k8isZJ+EbAVdePDp5LVIGzduE1f9B3qBbHXCxTqGxdylNRnS GQ9fj68WQvLWqAH70yPZMtA6RWO719qLYg4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" After commit 57df17fe26, some static check reports suspicous NULL pointer deference at line: Entry->MachineType =3D Entry->Emulator->MachineType; ^^^^^^^^^^^^^^^ within function PeCoffEmuProtocolNotify(). However, 'Entry->Emulator' is guaranteed to have a non-NULL value when previous call to the CoreHandleProtocol() returns EFI_SUCCESS. This commit will re-write the return status check for CoreHandleProtocol() to add explicit NULL pointer check for protocol instance pointer. Cc: Ard Biesheuvel Cc: Michael D Kinney Cc: Liming Gao Cc: Jian J Wang Signed-off-by: Hao Wu Acked-by: Ard Biesheuvel Reviewed-by: Michael D Kinney --- MdeModulePkg/Core/Dxe/Image/Image.c | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index 08306a73fd..de5b8bed27 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -134,12 +134,14 @@ PeCoffEmuProtocolNotify ( IN VOID *Context ) { - EFI_STATUS Status; - UINTN BufferSize; - EFI_HANDLE EmuHandle; - EMULATOR_ENTRY *Entry; + EFI_STATUS Status; + UINTN BufferSize; + EFI_HANDLE EmuHandle; + EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emulator; + EMULATOR_ENTRY *Entry; =20 EmuHandle =3D NULL; + Emulator =3D NULL; =20 while (TRUE) { BufferSize =3D sizeof (EmuHandle); @@ -157,16 +159,19 @@ PeCoffEmuProtocolNotify ( return; } =20 - Entry =3D AllocateZeroPool (sizeof (*Entry)); - ASSERT (Entry !=3D NULL); - Status =3D CoreHandleProtocol ( EmuHandle, &gEdkiiPeCoffImageEmulatorProtocolGuid, - (VOID **)&Entry->Emulator + (VOID **)&Emulator ); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status) || Emulator =3D=3D NULL) { + continue; + } + + Entry =3D AllocateZeroPool (sizeof (*Entry)); + ASSERT (Entry !=3D NULL); =20 + Entry->Emulator =3D Emulator; Entry->MachineType =3D Entry->Emulator->MachineType; =20 InsertTailList (&mAvailableEmulators, &Entry->Link); --=20 2.12.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#39454): https://edk2.groups.io/g/devel/message/39454 Mute This Topic: https://groups.io/mt/31318926/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-