From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id DC86A740032 for ; Wed, 24 Jan 2024 05:20:38 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=FbH5AuN0RlXygCr/dlmZidvEfZV5H2EFQ/njmrjzAhs=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706073637; v=1; b=XFWy6IL8+ZwFCnopAhBdNkOyVJ0T+Xghe3Pt9LSGOuA0f6H8tDJtSnjDPBNQ5PfATRn9jKLw hAk0QDjHIOLTB4YmUuixG0n9eFy+nW9/u8auu/Yu25uoopbFVtHjBHmthpqhMae/RGqrCMSMZkE LGuqBpHqMLegtu9WS8FyuwuQ= X-Received: by 127.0.0.2 with SMTP id VKr0YY7687511xrpid36Id20; Tue, 23 Jan 2024 21:20:37 -0800 X-Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mx.groups.io with SMTP id smtpd.web10.16103.1706073635240015184 for ; Tue, 23 Jan 2024 21:20:35 -0800 X-Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1d71e24845aso29217475ad.0 for ; Tue, 23 Jan 2024 21:20:35 -0800 (PST) X-Gm-Message-State: Dl5mxBrTVzq70E5BrXCWseFVx7686176AA= X-Google-Smtp-Source: AGHT+IHdQhR0Tk5UqF6MrUupO47L1GuiekqIywG6GrdsDqWUuJoBh7jPx8TfGfMdVupAqgZg4NXdAA== X-Received: by 2002:a17:902:9a86:b0:1d7:5c60:f508 with SMTP id w6-20020a1709029a8600b001d75c60f508mr181335plp.109.1706073634181; Tue, 23 Jan 2024 21:20:34 -0800 (PST) X-Received: from localhost.localdomain ([24.17.138.83]) by smtp.gmail.com with ESMTPSA id w2-20020a170902c78200b001d71f10aa42sm7831709pla.11.2024.01.23.21.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 21:20:33 -0800 (PST) From: "Doug Flick via groups.io" To: devel@edk2.groups.io Cc: Doug Flick , Saloni Kasbekar , Zachary Clark-williams , "Doug Flick [MSFT]" Subject: [edk2-devel] [PATCH 10/14] NetworkPkg: UefiPxeBcDxe: SECURITY PATCH CVE-2023-45234 Unit Tests Date: Tue, 23 Jan 2024 19:33:33 -0800 Message-ID: <7765fc863cb658830aec48b077f1104627fdc630.1706062164.git.doug.edk2@gmail.com> In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: 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,dougflick@microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=XFWy6IL8; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: Doug Flick REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D4539 SECURITY PATCH - Unit Tests TCBZ4539 CVE-2023-45234 CVSS 8.3 : CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:H CWE-119 Improper Restriction of Operations within the Bounds of a Memory Bu= ffer Cc: Saloni Kasbekar Cc: Zachary Clark-williams Signed-off-by: Doug Flick [MSFT] --- NetworkPkg/Test/NetworkPkgHostTest.dsc | 1 + .../GoogleTest/UefiPxeBcDxeGoogleTest.inf | 48 +++ .../GoogleTest/PxeBcDhcp6GoogleTest.h | 50 +++ .../GoogleTest/PxeBcDhcp6GoogleTest.cpp | 300 ++++++++++++++++++ .../GoogleTest/UefiPxeBcDxeGoogleTest.cpp | 19 ++ 5 files changed, 418 insertions(+) create mode 100644 NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTe= st.inf create mode 100644 NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest= .h create mode 100644 NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest= .cpp create mode 100644 NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTe= st.cpp diff --git a/NetworkPkg/Test/NetworkPkgHostTest.dsc b/NetworkPkg/Test/Netwo= rkPkgHostTest.dsc index 7fa7b0f9d5be..a0273c431025 100644 --- a/NetworkPkg/Test/NetworkPkgHostTest.dsc +++ b/NetworkPkg/Test/NetworkPkgHostTest.dsc @@ -27,6 +27,7 @@ [Components] #=0D NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf=0D NetworkPkg/Ip6Dxe/GoogleTest/Ip6DxeGoogleTest.inf=0D + NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf=0D =0D # Despite these library classes being listed in [LibraryClasses] below, th= ey are not needed for the host-based unit tests.=0D [LibraryClasses]=0D diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf = b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf new file mode 100644 index 000000000000..301dcdf61109 --- /dev/null +++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf @@ -0,0 +1,48 @@ +## @file=0D +# Unit test suite for the UefiPxeBcDxe using Google Test=0D +#=0D +# Copyright (c) Microsoft Corporation.
=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +##=0D +[Defines]=0D +INF_VERSION =3D 0x00010005=0D +BASE_NAME =3D UefiPxeBcDxeGoogleTest=0D +FILE_GUID =3D 77D45C64-EC1E-4174-887B-886E89FD1EDF=0D +MODULE_TYPE =3D HOST_APPLICATION=0D +VERSION_STRING =3D 1.0=0D +=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64=0D +#=0D +=0D +[Sources]=0D + UefiPxeBcDxeGoogleTest.cpp=0D + PxeBcDhcp6GoogleTest.cpp=0D + PxeBcDhcp6GoogleTest.h=0D + ../PxeBcDhcp6.c=0D + ../PxeBcSupport.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec=0D + NetworkPkg/NetworkPkg.dec=0D +=0D +[LibraryClasses]=0D + GoogleTestLib=0D + DebugLib=0D + NetLib=0D + PcdLib=0D +=0D +[Protocols]=0D + gEfiDhcp6ServiceBindingProtocolGuid=0D + gEfiDns6ServiceBindingProtocolGuid=0D + gEfiDns6ProtocolGuid=0D +=0D +[Pcd]=0D + gEfiNetworkPkgTokenSpaceGuid.PcdDhcp6UidType=0D +=0D +[Guids]=0D + gZeroGuid=0D diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.h b/Ne= tworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.h new file mode 100644 index 000000000000..b17c314791c8 --- /dev/null +++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.h @@ -0,0 +1,50 @@ +/** @file=0D + This file exposes the internal interfaces which may be unit tested=0D + for the PxeBcDhcp6Dxe driver.=0D +=0D + Copyright (c) Microsoft Corporation.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#ifndef PXE_BC_DHCP6_GOOGLE_TEST_H_=0D +#define PXE_BC_DHCP6_GOOGLE_TEST_H_=0D +=0D +//=0D +// Minimal includes needed to compile=0D +//=0D +#include =0D +#include "../PxeBcImpl.h"=0D +=0D +/**=0D + Handle the DHCPv6 offer packet.=0D +=0D + @param[in] Private The pointer to PXEBC_PRIVATE_DATA.=0D +=0D + @retval EFI_SUCCESS Handled the DHCPv6 offer packet succes= sfully.=0D + @retval EFI_NO_RESPONSE No response to the following request p= acket.=0D + @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.=0D + @retval EFI_BUFFER_TOO_SMALL Can't cache the offer pacet.=0D +=0D +**/=0D +EFI_STATUS=0D +PxeBcHandleDhcp6Offer (=0D + IN PXEBC_PRIVATE_DATA *Private=0D + );=0D +=0D +/**=0D + Cache the DHCPv6 Server address=0D +=0D + @param[in] Private The pointer to PXEBC_PRIVATE_DATA.=0D + @param[in] Cache6 The pointer to PXEBC_DHCP6_PACKET_CACHE= .=0D +=0D + @retval EFI_SUCCESS Cache the DHCPv6 Server address success= fully.=0D + @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.=0D + @retval EFI_DEVICE_ERROR Failed to cache the DHCPv6 Server addre= ss.=0D +**/=0D +EFI_STATUS=0D +PxeBcCacheDnsServerAddresses (=0D + IN PXEBC_PRIVATE_DATA *Private,=0D + IN PXEBC_DHCP6_PACKET_CACHE *Cache6=0D + );=0D +=0D +#endif // PXE_BC_DHCP6_GOOGLE_TEST_H_=0D diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp b/= NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp new file mode 100644 index 000000000000..8260eeee50dc --- /dev/null +++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp @@ -0,0 +1,300 @@ +/** @file=0D + Host based unit test for PxeBcDhcp6.c.=0D +=0D + Copyright (c) Microsoft Corporation=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +#include =0D +=0D +extern "C" {=0D + #include =0D + #include =0D + #include =0D + #include "../PxeBcImpl.h"=0D + #include "../PxeBcDhcp6.h"=0D + #include "PxeBcDhcp6GoogleTest.h"=0D +}=0D +=0D +//////////////////////////////////////////////////////////////////////////= /////=0D +// Definitions=0D +//////////////////////////////////////////////////////////////////////////= /////=0D +=0D +#define PACKET_SIZE (1500)=0D +=0D +typedef struct {=0D + UINT16 OptionCode; // The option code for DHCP6_OPT_SERVER_ID (e.g.= , 0x03)=0D + UINT16 OptionLen; // The length of the option (e.g., 16 bytes)=0D + UINT8 ServerId[16]; // The 16-byte DHCPv6 Server Identifier=0D +} DHCP6_OPTION_SERVER_ID;=0D +=0D +//////////////////////////////////////////////////////////////////////////= /////=0D +/// Symbol Definitions=0D +//////////////////////////////////////////////////////////////////////////= /////=0D +=0D +EFI_STATUS=0D +MockUdpWrite (=0D + IN EFI_PXE_BASE_CODE_PROTOCOL *This,=0D + IN UINT16 OpFlags,=0D + IN EFI_IP_ADDRESS *DestIp,=0D + IN EFI_PXE_BASE_CODE_UDP_PORT *DestPort,=0D + IN EFI_IP_ADDRESS *GatewayIp OPTIONAL,=0D + IN EFI_IP_ADDRESS *SrcIp OPTIONAL,=0D + IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,=0D + IN UINTN *HeaderSize OPTIONAL,=0D + IN VOID *HeaderPtr OPTIONAL,=0D + IN UINTN *BufferSize,=0D + IN VOID *BufferPtr=0D + )=0D +{=0D + return EFI_SUCCESS;=0D +}=0D +=0D +EFI_STATUS=0D +MockUdpRead (=0D + IN EFI_PXE_BASE_CODE_PROTOCOL *This,=0D + IN UINT16 OpFlags,=0D + IN OUT EFI_IP_ADDRESS *DestIp OPTIONAL,=0D + IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort OPTIONAL,=0D + IN OUT EFI_IP_ADDRESS *SrcIp OPTIONAL,=0D + IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,=0D + IN UINTN *HeaderSize OPTIONAL,=0D + IN VOID *HeaderPtr OPTIONAL,=0D + IN OUT UINTN *BufferSize,=0D + IN VOID *BufferPtr=0D + )=0D +{=0D + return EFI_SUCCESS;=0D +}=0D +=0D +EFI_STATUS=0D +MockConfigure (=0D + IN EFI_UDP6_PROTOCOL *This,=0D + IN EFI_UDP6_CONFIG_DATA *UdpConfigData OPTIONAL=0D + )=0D +{=0D + return EFI_SUCCESS;=0D +}=0D +=0D +// Needed by PxeBcSupport=0D +EFI_STATUS=0D +EFIAPI=0D +QueueDpc (=0D + IN EFI_TPL DpcTpl,=0D + IN EFI_DPC_PROCEDURE DpcProcedure,=0D + IN VOID *DpcContext OPTIONAL=0D + )=0D +{=0D + return EFI_SUCCESS;=0D +}=0D +=0D +//////////////////////////////////////////////////////////////////////////= /////=0D +// PxeBcHandleDhcp6OfferTest Tests=0D +//////////////////////////////////////////////////////////////////////////= /////=0D +=0D +class PxeBcHandleDhcp6OfferTest : public ::testing::Test {=0D +public:=0D + PXEBC_PRIVATE_DATA Private =3D { 0 };=0D + EFI_UDP6_PROTOCOL Udp6Read;=0D + EFI_PXE_BASE_CODE_MODE Mode =3D { 0 };=0D +=0D +protected:=0D + // Add any setup code if needed=0D + virtual void=0D + SetUp (=0D + )=0D + {=0D + Private.Dhcp6Request =3D (EFI_DHCP6_PACKET *)AllocateZeroPool (PACKET_= SIZE);=0D +=0D + // Need to setup the EFI_PXE_BASE_CODE_PROTOCOL=0D + // The function under test really only needs the following:=0D + // UdpWrite=0D + // UdpRead=0D +=0D + Private.PxeBc.UdpWrite =3D (EFI_PXE_BASE_CODE_UDP_WRITE)MockUdpWrite;= =0D + Private.PxeBc.UdpRead =3D (EFI_PXE_BASE_CODE_UDP_READ)MockUdpRead;=0D +=0D + // Need to setup EFI_UDP6_PROTOCOL=0D + // The function under test really only needs the following:=0D + // Configure=0D +=0D + Udp6Read.Configure =3D (EFI_UDP6_CONFIGURE)MockConfigure;=0D + Private.Udp6Read =3D &Udp6Read;=0D +=0D + // Need to setup the EFI_PXE_BASE_CODE_MODE=0D + Private.PxeBc.Mode =3D &Mode;=0D +=0D + // for this test it doesn't really matter what the Dhcpv6 ack is set t= o=0D + }=0D +=0D + // Add any cleanup code if needed=0D + virtual void=0D + TearDown (=0D + )=0D + {=0D + if (Private.Dhcp6Request !=3D NULL) {=0D + FreePool (Private.Dhcp6Request);=0D + }=0D +=0D + // Clean up any resources or variables=0D + }=0D +};=0D +=0D +// Note:=0D +// Testing PxeBcHandleDhcp6Offer() is difficult because it depends on a=0D +// properly setup Private structure. Attempting to properly test this func= tion=0D +// without a signficant refactor is a fools errand. Instead, we will test= =0D +// that we can prevent an overflow in the function.=0D +TEST_F (PxeBcHandleDhcp6OfferTest, BasicUsageTest) {=0D + PXEBC_DHCP6_PACKET_CACHE *Cache6 =3D NULL;=0D + EFI_DHCP6_PACKET_OPTION Option =3D { 0 };=0D +=0D + Private.SelectIndex =3D 1; // SelectIndex is 1-based=0D + Cache6 =3D &Private.OfferBuffer[Private.SelectIndex - 1].Dh= cp6;=0D +=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] =3D &Option;=0D + // Setup the DHCPv6 offer packet=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpCode =3D DHCP6_OPT_SERVER= _ID;=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpLen =3D NTOHS (1337);=0D +=0D + ASSERT_EQ (PxeBcHandleDhcp6Offer (&(PxeBcHandleDhcp6OfferTest::Private))= , EFI_DEVICE_ERROR);=0D +}=0D +=0D +class PxeBcCacheDnsServerAddressesTest : public ::testing::Test {=0D +public:=0D + PXEBC_PRIVATE_DATA Private =3D { 0 };=0D +=0D +protected:=0D + // Add any setup code if needed=0D + virtual void=0D + SetUp (=0D + )=0D + {=0D + }=0D +=0D + // Add any cleanup code if needed=0D + virtual void=0D + TearDown (=0D + )=0D + {=0D + }=0D +};=0D +=0D +// Test Description=0D +// Test that we cache the DNS server address from the DHCPv6 offer packet= =0D +TEST_F (PxeBcCacheDnsServerAddressesTest, BasicUsageTest) {=0D + UINT8 SearchPattern[16] =3D { 0xDE, 0xAD, 0xBE, 0xEF= , 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF };= =0D + EFI_DHCP6_PACKET_OPTION *Option;=0D + PXEBC_DHCP6_PACKET_CACHE *Cache6 =3D NULL;=0D +=0D + Option =3D (EFI_DHCP6_PACKET_OPTION *)AllocateZeroPool (sizeof (EFI_DHCP= 6_PACKET_OPTION) + sizeof (SearchPattern));=0D + ASSERT_NE (Option, nullptr);=0D +=0D + Option->OpCode =3D DHCP6_OPT_SERVER_ID;=0D + Option->OpLen =3D NTOHS (sizeof (SearchPattern));=0D + CopyMem (Option->Data, SearchPattern, sizeof (SearchPattern));=0D +=0D + Private.SelectIndex =3D 1; // SelectIndex is 1-b= ased=0D + Cache6 =3D &Private.OfferBuffer[Pri= vate.SelectIndex - 1].Dhcp6;=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] =3D Option;=0D +=0D + Private.DnsServer =3D nullptr;=0D +=0D + ASSERT_EQ (PxeBcCacheDnsServerAddresses (&(PxeBcCacheDnsServerAddressesT= est::Private), Cache6), EFI_SUCCESS);=0D + ASSERT_NE (Private.DnsServer, nullptr);=0D + ASSERT_EQ (CompareMem (Private.DnsServer, SearchPattern, sizeof (SearchP= attern)), 0);=0D +=0D + if (Private.DnsServer) {=0D + FreePool (Private.DnsServer);=0D + }=0D +=0D + if (Option) {=0D + FreePool (Option);=0D + }=0D +}=0D +// Test Description=0D +// Test that we can prevent an overflow in the function=0D +TEST_F (PxeBcCacheDnsServerAddressesTest, AttemptOverflowTest) {=0D + EFI_DHCP6_PACKET_OPTION Option =3D { 0 };=0D + PXEBC_DHCP6_PACKET_CACHE *Cache6 =3D NULL;=0D +=0D + Private.SelectIndex =3D 1; // SelectIndex is 1-b= ased=0D + Cache6 =3D &Private.OfferBuffer[Pri= vate.SelectIndex - 1].Dhcp6;=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] =3D &Option;=0D + // Setup the DHCPv6 offer packet=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpCode =3D DHCP6_OPT_SERVER= _ID;=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpLen =3D NTOHS (1337);=0D +=0D + Private.DnsServer =3D NULL;=0D +=0D + ASSERT_EQ (PxeBcCacheDnsServerAddresses (&(PxeBcCacheDnsServerAddressesT= est::Private), Cache6), EFI_DEVICE_ERROR);=0D + ASSERT_EQ (Private.DnsServer, nullptr);=0D +=0D + if (Private.DnsServer) {=0D + FreePool (Private.DnsServer);=0D + }=0D +}=0D +=0D +// Test Description=0D +// Test that we can prevent an underflow in the function=0D +TEST_F (PxeBcCacheDnsServerAddressesTest, AttemptUnderflowTest) {=0D + EFI_DHCP6_PACKET_OPTION Option =3D { 0 };=0D + PXEBC_DHCP6_PACKET_CACHE *Cache6 =3D NULL;=0D +=0D + Private.SelectIndex =3D 1; // SelectIndex is 1-b= ased=0D + Cache6 =3D &Private.OfferBuffer[Pri= vate.SelectIndex - 1].Dhcp6;=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] =3D &Option;=0D + // Setup the DHCPv6 offer packet=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpCode =3D DHCP6_OPT_SERVER= _ID;=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpLen =3D NTOHS (2);=0D +=0D + Private.DnsServer =3D NULL;=0D +=0D + ASSERT_EQ (PxeBcCacheDnsServerAddresses (&(PxeBcCacheDnsServerAddressesT= est::Private), Cache6), EFI_DEVICE_ERROR);=0D + ASSERT_EQ (Private.DnsServer, nullptr);=0D +=0D + if (Private.DnsServer) {=0D + FreePool (Private.DnsServer);=0D + }=0D +}=0D +=0D +// Test Description=0D +// Test that we can handle recursive dns (multiple dns entries)=0D +TEST_F (PxeBcCacheDnsServerAddressesTest, MultipleDnsEntries) {=0D + EFI_DHCP6_PACKET_OPTION Option =3D { 0 };=0D + PXEBC_DHCP6_PACKET_CACHE *Cache6 =3D NULL;=0D +=0D + Private.SelectIndex =3D 1; // SelectIndex is 1-b= ased=0D + Cache6 =3D &Private.OfferBuffer[Pri= vate.SelectIndex - 1].Dhcp6;=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] =3D &Option;=0D + // Setup the DHCPv6 offer packet=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpCode =3D DHCP6_OPT_SERVER= _ID;=0D +=0D + EFI_IPv6_ADDRESS addresses[2] =3D {=0D + // 2001:db8:85a3::8a2e:370:7334=0D + { 0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x= 2e, 0x03, 0x70, 0x73, 0x34 },=0D + // fe80::d478:91c3:ecd7:4ff9=0D + { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x78, 0x91, 0x= c3, 0xec, 0xd7, 0x4f, 0xf9 }=0D + };=0D +=0D + CopyMem (Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->Data, &addresses, = sizeof (addresses));=0D +=0D + Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpLen =3D NTOHS (sizeof (ad= dresses));=0D +=0D + Private.DnsServer =3D NULL;=0D +=0D + ASSERT_EQ (PxeBcCacheDnsServerAddresses (&(PxeBcCacheDnsServerAddressesT= est::Private), Cache6), EFI_SUCCESS);=0D +=0D + ASSERT_NE (Private.DnsServer, nullptr);=0D +=0D + //=0D + // This is expected to fail until DnsServer supports multiple DNS server= s=0D + //=0D + // This is tracked in https://bugzilla.tianocore.org/show_bug.cgi?id=3D1= 886=0D + //=0D + // Disabling:=0D + // ASSERT_EQ (CompareMem(Private.DnsServer, &addresses, sizeof(addresses= )), 0);=0D +=0D + if (Private.DnsServer) {=0D + FreePool (Private.DnsServer);=0D + }=0D +}=0D diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.cpp = b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.cpp new file mode 100644 index 000000000000..cc4fdf525b62 --- /dev/null +++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.cpp @@ -0,0 +1,19 @@ +/** @file=0D + Acts as the main entry point for the tests for the UefiPxeBcDxe module.= =0D + Copyright (c) Microsoft Corporation=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +#include =0D +=0D +//////////////////////////////////////////////////////////////////////////= //////=0D +// Run the tests=0D +//////////////////////////////////////////////////////////////////////////= //////=0D +int=0D +main (=0D + int argc,=0D + char *argv[]=0D + )=0D +{=0D + testing::InitGoogleTest (&argc, argv);=0D + return RUN_ALL_TESTS ();=0D +}=0D --=20 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114262): https://edk2.groups.io/g/devel/message/114262 Mute This Topic: https://groups.io/mt/103926741/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-