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 0D337740035 for ; Wed, 24 Jan 2024 05:20:32 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=tQid0ij0U8pvw1XsxSzeGdgHRDE20MCBPZAOFBlM5RU=; 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=1706073631; v=1; b=Ct9UsBePM9cbf2kSTkAQMi4aoUX6hOnpsILxi5Ey5otdkC/z3QNRIAimqztZN3hcbxHbErVM vT52PBVkP8HYkpZEUq/MS11urkHkiRy4VJ2AmP/stECnRD3vuDES4KTsCTbutKbI24LOz+76dCC W9Lc7KBTse7c0ENrygrIkHCE= X-Received: by 127.0.0.2 with SMTP id 9ilKYY7687511xUFwRid8DXd; Tue, 23 Jan 2024 21:20:31 -0800 X-Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by mx.groups.io with SMTP id smtpd.web11.16103.1706073630477624504 for ; Tue, 23 Jan 2024 21:20:30 -0800 X-Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-5cddfe0cb64so2569410a12.0 for ; Tue, 23 Jan 2024 21:20:30 -0800 (PST) X-Gm-Message-State: rGpOekvWe7cb0kZVorL8Fuh0x7686176AA= X-Google-Smtp-Source: AGHT+IHagWLT3iDQl+Og4ecyn7jfS13hYYJPJxdi/ZSwfyEMG+RPH/15znPGtJ4gz0uvBE0TV4u8YQ== X-Received: by 2002:a17:903:2649:b0:1d7:4ea2:3dc3 with SMTP id je9-20020a170903264900b001d74ea23dc3mr173555plb.82.1706073629503; Tue, 23 Jan 2024 21:20:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 21:20:29 -0800 (PST) From: "Doug Flick via groups.io" To: devel@edk2.groups.io Cc: "Douglas Flick [MSFT]" , Saloni Kasbekar , Zachary Clark-williams Subject: [edk2-devel] [PATCH 04/14] NetworkPkg: Dhcp6Dxe: SECURITY PATCH CVE-2023-45229 Unit Tests Date: Tue, 23 Jan 2024 19:33:27 -0800 Message-ID: <9cedd6b0094a541bf6a32c728feda217c0964ea4.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=Ct9UsBeP; 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 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4534 SECURITY PATCH - Unit Tests TCBZ4534 CVE-2023-45229 CVSS 6.5 : CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N CWE-125 Out-of-bounds Read Cc: Saloni Kasbekar Cc: Zachary Clark-williams Signed-off-by: Doug Flick [MSFT] --- NetworkPkg/Test/NetworkPkgHostTest.dsc | 1 + .../GoogleTest/Dhcp6DxeGoogleTest.inf | 1 + .../Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.h | 58 +++ NetworkPkg/Dhcp6Dxe/Dhcp6Io.c | 2 +- .../Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp | 365 +++++++++++++++++- 5 files changed, 424 insertions(+), 3 deletions(-) create mode 100644 NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.h diff --git a/NetworkPkg/Test/NetworkPkgHostTest.dsc b/NetworkPkg/Test/Netwo= rkPkgHostTest.dsc index 20bc90b1728d..24dee654df2e 100644 --- a/NetworkPkg/Test/NetworkPkgHostTest.dsc +++ b/NetworkPkg/Test/NetworkPkgHostTest.dsc @@ -16,6 +16,7 @@ [Defines] SKUID_IDENTIFIER =3D DEFAULT=0D =0D !include UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc=0D +=0D [Packages]=0D MdePkg/MdePkg.dec=0D UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec=0D diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf b/Networ= kPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf index 8e9119a37158..12532ed30cb3 100644 --- a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf @@ -18,6 +18,7 @@ [Defines] [Sources]=0D Dhcp6DxeGoogleTest.cpp=0D Dhcp6IoGoogleTest.cpp=0D + Dhcp6IoGoogleTest.h=0D ../Dhcp6Io.c=0D ../Dhcp6Utility.c=0D =0D diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.h b/NetworkPk= g/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.h new file mode 100644 index 000000000000..aed3b890827b --- /dev/null +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.h @@ -0,0 +1,58 @@ +/** @file=0D + Acts as header for private functions under test in Dhcp6Io.c=0D +=0D + Copyright (c) Microsoft Corporation=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#ifndef DHCP6_IO_GOOGLE_TEST_H_=0D +#define DHCP6_IO_GOOGLE_TEST_H_=0D +=0D +//////////////////////////////////////////////////////////////////////////= //////=0D +// These are the functions that are being unit tested=0D +//////////////////////////////////////////////////////////////////////////= //////=0D +=0D +#include =0D +=0D +/**=0D + Seeks the Inner Options from a DHCP6 Option=0D +=0D + @param[in] IaType The type of the IA option.=0D + @param[in] Option The pointer to the DHCP6 Option.=0D + @param[in] OptionLen The length of the DHCP6 Option.=0D + @param[out] IaInnerOpt The pointer to the IA inner option.=0D + @param[out] IaInnerLen The length of the IA inner option.=0D +=0D + @retval EFI_SUCCESS Seek the inner option successfully.=0D + @retval EFI_DEVICE_ERROR The OptionLen is invalid.=0D +*/=0D +EFI_STATUS=0D +Dhcp6SeekInnerOptionSafe (=0D + UINT16 IaType,=0D + UINT8 *Option,=0D + UINT32 OptionLen,=0D + UINT8 **IaInnerOpt,=0D + UINT16 *IaInnerLen=0D + );=0D +=0D +/**=0D + Seek StatusCode Option in package. A Status Code option may appear in th= e=0D + options field of a DHCP message and/or in the options field of another o= ption.=0D + See details in section 22.13, RFC3315.=0D +=0D + @param[in] Instance The pointer to the Dhcp6 instance.=0D + @param[in] Packet The pointer to reply messages.=0D + @param[out] Option The pointer to status code option.=0D +=0D + @retval EFI_SUCCESS Seek status code option successfully.=0D + @retval EFI_DEVICE_ERROR An unexpected error.=0D +=0D +**/=0D +EFI_STATUS=0D +Dhcp6SeekStsOption (=0D + IN DHCP6_INSTANCE *Instance,=0D + IN EFI_DHCP6_PACKET *Packet,=0D + OUT UINT8 **Option=0D + );=0D +=0D +#endif // DHCP6_IO_GOOGLE_TEST_H=0D diff --git a/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c b/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c index 89d16484a568..3b8feb4a2032 100644 --- a/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c +++ b/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c @@ -816,7 +816,7 @@ Dhcp6SeekStsOption ( // IA option to the end of the DHCP6 option area, thus subtract the spac= e=0D // up until this option=0D //=0D - OptionLen =3D OptionLen - (*Option - Packet->Dhcp6.Option);=0D + OptionLen =3D OptionLen - (UINT32)(*Option - Packet->Dhcp6.Option);=0D =0D //=0D // Seek the inner option=0D diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp b/Network= Pkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp index 7ee40e4af480..7db253a7b87f 100644 --- a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp @@ -13,6 +13,7 @@ extern "C" { #include =0D #include "../Dhcp6Impl.h"=0D #include "../Dhcp6Utility.h"=0D + #include "Dhcp6IoGoogleTest.h"=0D }=0D =0D ////////////////////////////////////////////////////////////////////////=0D @@ -21,7 +22,35 @@ extern "C" { =0D #define DHCP6_PACKET_MAX_LEN 1500=0D =0D +// This definition is used by this test but is also required to compile=0D +// by Dhcp6Io.c=0D +#define DHCPV6_OPTION_IA_NA 3=0D +#define DHCPV6_OPTION_IA_TA 4=0D +=0D +#define SEARCH_PATTERN 0xDEADC0DE=0D +#define SEARCH_PATTERN_LEN sizeof(SEARCH_PATTERN)=0D +=0D ////////////////////////////////////////////////////////////////////////=0D +// Test structures for IA_NA and IA_TA options=0D +////////////////////////////////////////////////////////////////////////=0D +typedef struct {=0D + UINT16 Code;=0D + UINT16 Len;=0D + UINT32 IAID;=0D +} DHCPv6_OPTION;=0D +=0D +typedef struct {=0D + DHCPv6_OPTION Header;=0D + UINT32 T1;=0D + UINT32 T2;=0D + UINT8 InnerOptions[0];=0D +} DHCPv6_OPTION_IA_NA;=0D +=0D +typedef struct {=0D + DHCPv6_OPTION Header;=0D + UINT8 InnerOptions[0];=0D +} DHCPv6_OPTION_IA_TA;=0D +=0D ////////////////////////////////////////////////////////////////////////=0D // Symbol Definitions=0D // These functions are not directly under test - but required to compile=0D @@ -210,7 +239,7 @@ TEST_F (Dhcp6AppendETOptionTest, InvalidDataExpectBuffe= rTooSmall) { Status =3D Dhcp6AppendETOption (=0D Dhcp6AppendETOptionTest::Packet,=0D &Cursor,=0D - &Instance, // Instance is not used in this function=0D + &Instance, // Instance is not used in this= function=0D &ElapsedTime=0D );=0D =0D @@ -240,7 +269,7 @@ TEST_F (Dhcp6AppendETOptionTest, ValidDataExpectSuccess= ) { Status =3D Dhcp6AppendETOption (=0D Dhcp6AppendETOptionTest::Packet,=0D &Cursor,=0D - &Instance, // Instance is not used in this function=0D + &Instance, // Instance is not used in this= function=0D &ElapsedTime=0D );=0D =0D @@ -476,3 +505,335 @@ TEST_F (Dhcp6AppendIaOptionTest, IaTaValidDataExpectS= uccess) { // verify that the status is EFI_SUCCESS=0D ASSERT_EQ (Status, EFI_SUCCESS);=0D }=0D +=0D +////////////////////////////////////////////////////////////////////////=0D +// Dhcp6SeekInnerOptionSafe Tests=0D +////////////////////////////////////////////////////////////////////////=0D +=0D +// Define a fixture for your tests if needed=0D +class Dhcp6SeekInnerOptionSafeTest : public ::testing::Test {=0D +protected:=0D + // Add any setup code if needed=0D + virtual void=0D + SetUp (=0D + )=0D + {=0D + // Initialize any resources or variables=0D + }=0D +=0D + // Add any cleanup code if needed=0D + virtual void=0D + TearDown (=0D + )=0D + {=0D + // Clean up any resources or variables=0D + }=0D +};=0D +=0D +// Test Description:=0D +// This test verifies that Dhcp6SeekInnerOptionSafe returns EFI_SUCCESS wh= en the IANA option is found.=0D +TEST_F (Dhcp6SeekInnerOptionSafeTest, IANAValidOptionExpectSuccess) {=0D + EFI_STATUS Result;=0D + UINT8 Option[sizeof (DHCPv6_OPTION_IA_NA) + SEARCH_PATTER= N_LEN] =3D { 0 };=0D + UINT32 OptionLength = =3D sizeof (Option);=0D + DHCPv6_OPTION_IA_NA *OptionPtr = =3D (DHCPv6_OPTION_IA_NA *)Option;=0D + UINT32 SearchPattern = =3D SEARCH_PATTERN;=0D +=0D + UINTN SearchPatternLength =3D SEARCH_PATTERN_LEN;=0D + UINT8 *InnerOptionPtr =3D NULL;=0D + UINT16 InnerOptionLength =3D 0;=0D +=0D + OptionPtr->Header.Code =3D Dhcp6OptIana;=0D + OptionPtr->Header.Len =3D HTONS (4 + 12); // Valid length has to be mor= e than 12=0D + OptionPtr->Header.IAID =3D 0x12345678;=0D + OptionPtr->T1 =3D 0x11111111;=0D + OptionPtr->T2 =3D 0x22222222;=0D + CopyMem (OptionPtr->InnerOptions, &SearchPattern, SearchPatternLength);= =0D +=0D + Result =3D Dhcp6SeekInnerOptionSafe (=0D + Dhcp6OptIana,=0D + Option,=0D + OptionLength,=0D + &InnerOptionPtr,=0D + &InnerOptionLength=0D + );=0D + ASSERT_EQ (Result, EFI_SUCCESS);=0D + ASSERT_EQ (InnerOptionLength, 4);=0D + ASSERT_EQ (CompareMem (InnerOptionPtr, &SearchPattern, SearchPatternLeng= th), 0);=0D +}=0D +=0D +// Test Description:=0D +// This test verifies that Dhcp6SeekInnerOptionSafe returns EFI_DEIVCE_ERR= OR when the IANA option size is invalid.=0D +TEST_F (Dhcp6SeekInnerOptionSafeTest, IANAInvalidSizeExpectFail) {=0D + // Lets add an inner option of bytes we expect to find=0D + EFI_STATUS Status;=0D + UINT8 Option[sizeof (DHCPv6_OPTION_IA_NA) + SEARCH_PATTER= N_LEN] =3D { 0 };=0D + UINT32 OptionLength = =3D sizeof (Option);=0D + DHCPv6_OPTION_IA_NA *OptionPtr = =3D (DHCPv6_OPTION_IA_NA *)Option;=0D + UINT32 SearchPattern = =3D SEARCH_PATTERN;=0D +=0D + UINTN SearchPatternLength =3D SEARCH_PATTERN_LEN;=0D + UINT8 *InnerOptionPtr =3D NULL;=0D + UINT16 InnerOptionLength =3D 0;=0D +=0D + OptionPtr->Header.Code =3D Dhcp6OptIana;=0D + OptionPtr->Header.Len =3D HTONS (4); // Set the length to lower than ex= pected (12)=0D + OptionPtr->Header.IAID =3D 0x12345678;=0D + OptionPtr->T1 =3D 0x11111111;=0D + OptionPtr->T2 =3D 0x22222222;=0D + CopyMem (OptionPtr->InnerOptions, &SearchPattern, SearchPatternLength);= =0D +=0D + // Set the InnerOptionLength to be less than the size of the option=0D + Status =3D Dhcp6SeekInnerOptionSafe (=0D + Dhcp6OptIana,=0D + Option,=0D + OptionLength,=0D + &InnerOptionPtr,=0D + &InnerOptionLength=0D + );=0D + ASSERT_EQ (Status, EFI_DEVICE_ERROR);=0D +=0D + // Now set the OptionLength to be less than the size of the option=0D + OptionLength =3D sizeof (DHCPv6_OPTION_IA_NA) - 1;=0D + Status =3D Dhcp6SeekInnerOptionSafe (=0D + Dhcp6OptIana,=0D + Option,=0D + OptionLength,=0D + &InnerOptionPtr,=0D + &InnerOptionLength=0D + );=0D + ASSERT_EQ (Status, EFI_DEVICE_ERROR);=0D +}=0D +=0D +// Test Description:=0D +// This test verifies that Dhcp6SeekInnerOptionSafe returns EFI_SUCCESS wh= en the IATA option is found=0D +TEST_F (Dhcp6SeekInnerOptionSafeTest, IATAValidOptionExpectSuccess) {=0D + // Lets add an inner option of bytes we expect to find=0D + EFI_STATUS Status;=0D + UINT8 Option[sizeof (DHCPv6_OPTION_IA_TA) + SEARCH_PATTER= N_LEN] =3D { 0 };=0D + UINT32 OptionLength = =3D sizeof (Option);=0D + DHCPv6_OPTION_IA_TA *OptionPtr = =3D (DHCPv6_OPTION_IA_TA *)Option;=0D + UINT32 SearchPattern = =3D SEARCH_PATTERN;=0D +=0D + UINTN SearchPatternLength =3D SEARCH_PATTERN_LEN;=0D + UINT8 *InnerOptionPtr =3D NULL;=0D + UINT16 InnerOptionLength =3D 0;=0D +=0D + OptionPtr->Header.Code =3D Dhcp6OptIata;=0D + OptionPtr->Header.Len =3D HTONS (4 + 4); // Valid length has to be more= than 4=0D + OptionPtr->Header.IAID =3D 0x12345678;=0D + CopyMem (OptionPtr->InnerOptions, &SearchPattern, SearchPatternLength);= =0D +=0D + Status =3D Dhcp6SeekInnerOptionSafe (=0D + Dhcp6OptIata,=0D + Option,=0D + OptionLength,=0D + &InnerOptionPtr,=0D + &InnerOptionLength=0D + );=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D + ASSERT_EQ (InnerOptionLength, 4);=0D + ASSERT_EQ (CompareMem (InnerOptionPtr, &SearchPattern, SearchPatternLeng= th), 0);=0D +}=0D +=0D +// Test Description:=0D +// This test verifies that Dhcp6SeekInnerOptionSafe returns EFI_SUCCESS wh= en the IATA option size is invalid.=0D +TEST_F (Dhcp6SeekInnerOptionSafeTest, IATAInvalidSizeExpectFail) {=0D + // Lets add an inner option of bytes we expect to find=0D + EFI_STATUS Status;=0D + UINT8 Option[sizeof (DHCPv6_OPTION_IA_TA) + SEARCH_PATTER= N_LEN] =3D { 0 };=0D + UINT32 OptionLength = =3D sizeof (Option);=0D + DHCPv6_OPTION_IA_TA *OptionPtr = =3D (DHCPv6_OPTION_IA_TA *)Option;=0D + UINT32 SearchPattern = =3D SEARCH_PATTERN;=0D +=0D + UINTN SearchPatternLength =3D SEARCH_PATTERN_LEN;=0D + UINT8 *InnerOptionPtr =3D NULL;=0D + UINT16 InnerOptionLength =3D 0;=0D +=0D + OptionPtr->Header.Code =3D Dhcp6OptIata;=0D + OptionPtr->Header.Len =3D HTONS (2); // Set the length to lower than ex= pected (4)=0D + OptionPtr->Header.IAID =3D 0x12345678;=0D + CopyMem (OptionPtr->InnerOptions, &SearchPattern, SearchPatternLength);= =0D +=0D + Status =3D Dhcp6SeekInnerOptionSafe (=0D + Dhcp6OptIata,=0D + Option,=0D + OptionLength,=0D + &InnerOptionPtr,=0D + &InnerOptionLength=0D + );=0D + ASSERT_EQ (Status, EFI_DEVICE_ERROR);=0D +=0D + // Now lets try modifying the OptionLength to be less than the size of t= he option=0D + OptionLength =3D sizeof (DHCPv6_OPTION_IA_TA) - 1;=0D + Status =3D Dhcp6SeekInnerOptionSafe (=0D + Dhcp6OptIata,=0D + Option,=0D + OptionLength,=0D + &InnerOptionPtr,=0D + &InnerOptionLength=0D + );=0D + ASSERT_EQ (Status, EFI_DEVICE_ERROR);=0D +}=0D +=0D +// Test Description:=0D +// This test verifies that any other Option Type fails=0D +TEST_F (Dhcp6SeekInnerOptionSafeTest, InvalidOption) {=0D + // Lets add an inner option of bytes we expect to find=0D + EFI_STATUS Result;=0D + UINT8 Option[sizeof (DHCPv6_OPTION_IA_TA) + SEARCH_PATTER= N_LEN] =3D { 0 };=0D + UINT32 OptionLength = =3D sizeof (Option);=0D + DHCPv6_OPTION_IA_TA *OptionPtr = =3D (DHCPv6_OPTION_IA_TA *)Option;=0D + UINT32 SearchPattern = =3D SEARCH_PATTERN;=0D +=0D + UINTN SearchPatternLength =3D SEARCH_PATTERN_LEN;=0D + UINT8 *InnerOptionPtr =3D NULL;=0D + UINT16 InnerOptionLength =3D 0;=0D +=0D + OptionPtr->Header.Code =3D 0xC0DE;=0D + OptionPtr->Header.Len =3D HTONS (2); // Set the length to lower than ex= pected (4)=0D + OptionPtr->Header.IAID =3D 0x12345678;=0D + CopyMem (OptionPtr->InnerOptions, &SearchPattern, SearchPatternLength);= =0D +=0D + Result =3D Dhcp6SeekInnerOptionSafe (0xC0DE, Option, OptionLength, &Inne= rOptionPtr, &InnerOptionLength);=0D + ASSERT_EQ (Result, EFI_DEVICE_ERROR);=0D +}=0D +=0D +////////////////////////////////////////////////////////////////////////=0D +// Dhcp6SeekStsOption Tests=0D +////////////////////////////////////////////////////////////////////////=0D +=0D +#define PACKET_SIZE (1500)=0D +=0D +class Dhcp6SeekStsOptionTest : public ::testing::Test {=0D +public:=0D + DHCP6_INSTANCE Instance =3D { 0 };=0D + EFI_DHCP6_PACKET *Packet =3D NULL;=0D + EFI_DHCP6_CONFIG_DATA Config =3D { 0 };=0D +=0D +protected:=0D + // Add any setup code if needed=0D + virtual void=0D + SetUp (=0D + )=0D + {=0D + // Allocate a packet=0D + Packet =3D (EFI_DHCP6_PACKET *)AllocateZeroPool (PACKET_SIZE);=0D + ASSERT_NE (Packet, nullptr);=0D +=0D + // Initialize the packet=0D + Packet->Size =3D PACKET_SIZE;=0D +=0D + Instance.Config =3D &Config;=0D + }=0D +=0D + // Add any cleanup code if needed=0D + virtual void=0D + TearDown (=0D + )=0D + {=0D + // Clean up any resources or variables=0D + FreePool (Packet);=0D + }=0D +};=0D +=0D +// Test Description:=0D +// This test verifies that Dhcp6SeekStsOption returns EFI_DEVICE_ERROR whe= n the option is invalid=0D +// This verifies that the calling function is working as expected=0D +TEST_F (Dhcp6SeekStsOptionTest, SeekIATAOptionExpectFail) {=0D + EFI_STATUS Status;=0D + UINT8 *Option =3D NULL;=0D + UINT32 SearchPattern =3D SEARCH_PATTERN;=0D + UINT16 SearchPatternLength =3D SEARCH_PATTERN_LEN;=0D + UINT16 *Len =3D NULL;=0D + EFI_DHCP6_IA Ia =3D { 0 };=0D +=0D + Ia.Descriptor.Type =3D DHCPV6_OPTION_IA_TA;=0D + Ia.IaAddressCount =3D 1;=0D + Ia.IaAddress[0].PreferredLifetime =3D 0xDEADBEEF;=0D + Ia.IaAddress[0].ValidLifetime =3D 0xDEADAAAA;=0D + Ia.IaAddress[0].IpAddress =3D mAllDhcpRelayAndServersAddress;=0D +=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D +=0D + Option =3D Dhcp6SeekStsOptionTest::Packet->Dhcp6.Option;=0D +=0D + // Let's append the option to the packet=0D + Status =3D Dhcp6AppendOption (=0D + Dhcp6SeekStsOptionTest::Packet,=0D + &Option,=0D + Dhcp6OptStatusCode,=0D + SearchPatternLength,=0D + (UINT8 *)&SearchPattern=0D + );=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D +=0D + // Inner option length - this will be overwritten later=0D + Len =3D (UINT16 *)(Option + 2);=0D +=0D + // Fill in the inner IA option=0D + Status =3D Dhcp6AppendIaOption (=0D + Dhcp6SeekStsOptionTest::Packet,=0D + &Option,=0D + &Ia,=0D + 0x12345678,=0D + 0x11111111,=0D + 0x22222222=0D + );=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D +=0D + // overwrite the len of inner Ia option=0D + *Len =3D HTONS (3);=0D +=0D + Dhcp6SeekStsOptionTest::Instance.Config->IaDescriptor.Type =3D DHCPV6_OP= TION_IA_TA;=0D +=0D + Option =3D NULL;=0D + Status =3D Dhcp6SeekStsOption (&(Dhcp6SeekStsOptionTest::Instance), Dhcp= 6SeekStsOptionTest::Packet, &Option);=0D +=0D + ASSERT_EQ (Status, EFI_DEVICE_ERROR);=0D +}=0D +=0D +// Test Description:=0D +// This test verifies that Dhcp6SeekInnerOptionSafe returns EFI_SUCCESS wh= en the IATA option size is invalid.=0D +TEST_F (Dhcp6SeekStsOptionTest, SeekIANAOptionExpectSuccess) {=0D + EFI_STATUS Status =3D EFI_NOT_FOUND;=0D + UINT8 *Option =3D NULL;=0D + UINT32 SearchPattern =3D SEARCH_PATTERN;=0D + UINT16 SearchPatternLength =3D SEARCH_PATTERN_LEN;=0D + EFI_DHCP6_IA Ia =3D { 0 };=0D +=0D + Ia.Descriptor.Type =3D DHCPV6_OPTION_IA_NA;=0D + Ia.IaAddressCount =3D 1;=0D + Ia.IaAddress[0].PreferredLifetime =3D 0x11111111;=0D + Ia.IaAddress[0].ValidLifetime =3D 0x22222222;=0D + Ia.IaAddress[0].IpAddress =3D mAllDhcpRelayAndServersAddress;=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D +=0D + Option =3D Dhcp6SeekStsOptionTest::Packet->Dhcp6.Option;=0D +=0D + Status =3D Dhcp6AppendOption (=0D + Dhcp6SeekStsOptionTest::Packet,=0D + &Option,=0D + Dhcp6OptStatusCode,=0D + SearchPatternLength,=0D + (UINT8 *)&SearchPattern=0D + );=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D +=0D + Status =3D Dhcp6AppendIaOption (=0D + Dhcp6SeekStsOptionTest::Packet,=0D + &Option,=0D + &Ia,=0D + 0x12345678,=0D + 0x11111111,=0D + 0x22222222=0D + );=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D +=0D + Dhcp6SeekStsOptionTest::Instance.Config->IaDescriptor.Type =3D DHCPV6_OP= TION_IA_NA;=0D +=0D + Option =3D NULL;=0D + Status =3D Dhcp6SeekStsOption (&(Dhcp6SeekStsOptionTest::Instance), Dhcp= 6SeekStsOptionTest::Packet, &Option);=0D +=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D +}=0D --=20 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114256): https://edk2.groups.io/g/devel/message/114256 Mute This Topic: https://groups.io/mt/103926734/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-