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 E405C7803D0 for ; Thu, 25 Jan 2024 23:06:33 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=nBoWyIY5BiII91WcY5Iq+mBYKQWdLC7NvrwsW03PUD0=; 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=1706223992; v=1; b=g8KJ/ieceJNO0gAosN1VIpD00appMSvX+fvD9ThF2oHSXT7aDeCE/b5945FKhvgvSimb5Q3I +ao9INYmcrmR41yHkphslwZND79zZ26xGX/hh5nPL7rpnik8kMTEQ8gg/oJ6Rjd8QzWUtL2qeha i7dyht1MrL4RveQnvt7vLrRo= X-Received: by 127.0.0.2 with SMTP id OPZpYY7687511xcpVMxIzUFO; Thu, 25 Jan 2024 15:06:32 -0800 X-Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by mx.groups.io with SMTP id smtpd.web11.777.1706223990862575729 for ; Thu, 25 Jan 2024 15:06:30 -0800 X-Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1d71e184695so32016955ad.3 for ; Thu, 25 Jan 2024 15:06:30 -0800 (PST) X-Gm-Message-State: ha2DKFHbgVqtnW43zTi9XCWMx7686176AA= X-Google-Smtp-Source: AGHT+IFhRM/LZFZw900yjaKK4HkAHklc2eIiXtMveBC3FjgBxmqZOe3qRed6j9Pu34zFb37IBkdv8w== X-Received: by 2002:a17:902:efc2:b0:1d7:2b80:ad84 with SMTP id ja2-20020a170902efc200b001d72b80ad84mr535910plb.50.1706223989858; Thu, 25 Jan 2024 15:06:29 -0800 (PST) X-Received: from localhost.localdomain ([24.17.138.83]) by smtp.gmail.com with ESMTPSA id jh1-20020a170903328100b001d752c4f180sm16779plb.94.2024.01.25.15.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 15:06: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 v2 03/15] NetworkPkg: Dhcp6Dxe: SECURITY PATCH CVE-2023-45230 Unit Tests Date: Thu, 25 Jan 2024 13:54:45 -0800 Message-ID: <4c33819343179a2cbdde07be55ac125c59f41f26.1706219324.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="g8KJ/iec"; 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=3D4535 Confirms that reported issue... "Buffer overflow in the DHCPv6 client via a long Server ID option" ..has been corrected by the provided patch. Tests the following functions to ensure they appropriately handle untrusted data (either too long or too small) to prevent a buffer overflow: Dhcp6AppendOption Dhcp6AppendETOption Dhcp6AppendIaOption Cc: Saloni Kasbekar Cc: Zachary Clark-williams Signed-off-by: Doug Flick [MSFT] --- NetworkPkg/Test/NetworkPkgHostTest.dsc | 1 + .../GoogleTest/Dhcp6DxeGoogleTest.inf | 43 ++ .../GoogleTest/Dhcp6DxeGoogleTest.cpp | 20 + .../Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp | 478 ++++++++++++++++++ 4 files changed, 542 insertions(+) create mode 100644 NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf create mode 100644 NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.cpp create mode 100644 NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp diff --git a/NetworkPkg/Test/NetworkPkgHostTest.dsc b/NetworkPkg/Test/Netwo= rkPkgHostTest.dsc index 1aeca5c5b353..20bc90b1728d 100644 --- a/NetworkPkg/Test/NetworkPkgHostTest.dsc +++ b/NetworkPkg/Test/NetworkPkgHostTest.dsc @@ -24,6 +24,7 @@ [Components] #=0D # Build HOST_APPLICATION that tests NetworkPkg=0D #=0D + NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.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/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf b/Networ= kPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf new file mode 100644 index 000000000000..8e9119a37158 --- /dev/null +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf @@ -0,0 +1,43 @@ +## @file=0D +# Unit test suite for the Dhcp6Dxe using Google Test=0D +#=0D +# Copyright (c) Microsoft Corporation.
=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +##=0D +[Defines]=0D + INF_VERSION =3D 0x00010017=0D + BASE_NAME =3D Dhcp6DxeGoogleTest=0D + FILE_GUID =3D 1D2A4C65-38C8-4C2F-BB60-B5FA49625AA9=0D + VERSION_STRING =3D 1.0=0D + MODULE_TYPE =3D HOST_APPLICATION=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64=0D +#=0D +[Sources]=0D + Dhcp6DxeGoogleTest.cpp=0D + Dhcp6IoGoogleTest.cpp=0D + ../Dhcp6Io.c=0D + ../Dhcp6Utility.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 +=0D +[Pcd]=0D + gEfiNetworkPkgTokenSpaceGuid.PcdDhcp6UidType=0D +=0D +[Guids]=0D + gZeroGuid=0D diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.cpp b/Networ= kPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.cpp new file mode 100644 index 000000000000..9aeced2f9156 --- /dev/null +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.cpp @@ -0,0 +1,20 @@ +/** @file=0D + Acts as the main entry point for the tests for the Dhcp6Dxe module.=0D +=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 diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp b/Network= Pkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp new file mode 100644 index 000000000000..7ee40e4af480 --- /dev/null +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp @@ -0,0 +1,478 @@ +/** @file=0D + Tests for Dhcp6Io.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 =0D + #include "../Dhcp6Impl.h"=0D + #include "../Dhcp6Utility.h"=0D +}=0D +=0D +////////////////////////////////////////////////////////////////////////=0D +// Defines=0D +////////////////////////////////////////////////////////////////////////=0D +=0D +#define DHCP6_PACKET_MAX_LEN 1500=0D +=0D +////////////////////////////////////////////////////////////////////////=0D +////////////////////////////////////////////////////////////////////////=0D +// Symbol Definitions=0D +// These functions are not directly under test - but required to compile=0D +////////////////////////////////////////////////////////////////////////=0D +=0D +// This definition is used by this test but is also required to compile=0D +// by Dhcp6Io.c=0D +EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress =3D {=0D + { 0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2 }=0D +};=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +UdpIoSendDatagram (=0D + IN UDP_IO *UdpIo,=0D + IN NET_BUF *Packet,=0D + IN UDP_END_POINT *EndPoint OPTIONAL,=0D + IN EFI_IP_ADDRESS *Gateway OPTIONAL,=0D + IN UDP_IO_CALLBACK CallBack,=0D + IN VOID *Context=0D + )=0D +{=0D + return EFI_SUCCESS;=0D +}=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +UdpIoRecvDatagram (=0D + IN UDP_IO *UdpIo,=0D + IN UDP_IO_CALLBACK CallBack,=0D + IN VOID *Context,=0D + IN UINT32 HeadLen=0D + )=0D +{=0D + return EFI_SUCCESS;=0D +}=0D +=0D +////////////////////////////////////////////////////////////////////////=0D +// Dhcp6AppendOptionTest Tests=0D +////////////////////////////////////////////////////////////////////////=0D +=0D +class Dhcp6AppendOptionTest : public ::testing::Test {=0D +public:=0D + UINT8 *Buffer =3D NULL;=0D + EFI_DHCP6_PACKET *Packet;=0D +=0D +protected:=0D + // Add any setup code if needed=0D + virtual void=0D + SetUp (=0D + )=0D + {=0D + // Initialize any resources or variables=0D + Buffer =3D (UINT8 *)AllocateZeroPool (DHCP6_PACKET_MAX_LEN);=0D + ASSERT_NE (Buffer, (UINT8 *)NULL);=0D +=0D + Packet =3D (EFI_DHCP6_PACKET *)Buffer;=0D + Packet->Size =3D DHCP6_PACKET_MAX_LEN;=0D + }=0D +=0D + // Add any cleanup code if needed=0D + virtual void=0D + TearDown (=0D + )=0D + {=0D + // Clean up any resources or variables=0D + if (Buffer !=3D NULL) {=0D + FreePool (Buffer);=0D + }=0D + }=0D +};=0D +=0D +// Test Description:=0D +// Attempt to append an option to a packet that is too small by a duid tha= t is too large=0D +TEST_F (Dhcp6AppendOptionTest, InvalidDataExpectBufferTooSmall) {=0D + UINT8 *Cursor;=0D + EFI_DHCP6_DUID *UntrustedDuid;=0D + EFI_STATUS Status;=0D +=0D + UntrustedDuid =3D (EFI_DHCP6_DUID *)AllocateZeroPool (sizeof (EFI_DHCP6_= DUID));=0D + ASSERT_NE (UntrustedDuid, (EFI_DHCP6_DUID *)NULL);=0D +=0D + UntrustedDuid->Length =3D NTOHS (0xFFFF);=0D +=0D + Cursor =3D Dhcp6AppendOptionTest::Packet->Dhcp6.Option;=0D +=0D + Status =3D Dhcp6AppendOption (=0D + Dhcp6AppendOptionTest::Packet,=0D + &Cursor,=0D + HTONS (Dhcp6OptServerId),=0D + UntrustedDuid->Length,=0D + UntrustedDuid->Duid=0D + );=0D +=0D + ASSERT_EQ (Status, EFI_BUFFER_TOO_SMALL);=0D +}=0D +=0D +// Test Description:=0D +// Attempt to append an option to a packet that is large enough=0D +TEST_F (Dhcp6AppendOptionTest, ValidDataExpectSuccess) {=0D + UINT8 *Cursor;=0D + EFI_DHCP6_DUID *UntrustedDuid;=0D + EFI_STATUS Status;=0D + UINTN OriginalLength;=0D +=0D + UINT8 Duid[6] =3D { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };=0D +=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D + OriginalLength =3D Packet->Length;=0D +=0D + UntrustedDuid =3D (EFI_DHCP6_DUID *)AllocateZeroPool (sizeof (EFI_DHCP6_= DUID));=0D + ASSERT_NE (UntrustedDuid, (EFI_DHCP6_DUID *)NULL);=0D +=0D + UntrustedDuid->Length =3D NTOHS (sizeof (Duid));=0D + CopyMem (UntrustedDuid->Duid, Duid, sizeof (Duid));=0D +=0D + Cursor =3D Dhcp6AppendOptionTest::Packet->Dhcp6.Option;=0D +=0D + Status =3D Dhcp6AppendOption (=0D + Dhcp6AppendOptionTest::Packet,=0D + &Cursor,=0D + HTONS (Dhcp6OptServerId),=0D + UntrustedDuid->Length,=0D + UntrustedDuid->Duid=0D + );=0D +=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D +=0D + // verify that the pointer to cursor moved by the expected amount=0D + ASSERT_EQ (Cursor, (UINT8 *)Dhcp6AppendOptionTest::Packet->Dhcp6.Option = + sizeof (Duid) + 4);=0D +=0D + // verify that the length of the packet is now the expected amount=0D + ASSERT_EQ (Dhcp6AppendOptionTest::Packet->Length, OriginalLength + sizeo= f (Duid) + 4);=0D +}=0D +=0D +////////////////////////////////////////////////////////////////////////=0D +// Dhcp6AppendETOption Tests=0D +////////////////////////////////////////////////////////////////////////=0D +=0D +class Dhcp6AppendETOptionTest : public ::testing::Test {=0D +public:=0D + UINT8 *Buffer =3D NULL;=0D + EFI_DHCP6_PACKET *Packet;=0D +=0D +protected:=0D + // Add any setup code if needed=0D + virtual void=0D + SetUp (=0D + )=0D + {=0D + // Initialize any resources or variables=0D + Buffer =3D (UINT8 *)AllocateZeroPool (DHCP6_PACKET_MAX_LEN);=0D + ASSERT_NE (Buffer, (UINT8 *)NULL);=0D +=0D + Packet =3D (EFI_DHCP6_PACKET *)Buffer;=0D + Packet->Size =3D DHCP6_PACKET_MAX_LEN;=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D + }=0D +=0D + // Add any cleanup code if needed=0D + virtual void=0D + TearDown (=0D + )=0D + {=0D + // Clean up any resources or variables=0D + if (Buffer !=3D NULL) {=0D + FreePool (Buffer);=0D + }=0D + }=0D +};=0D +=0D +// Test Description:=0D +// Attempt to append an option to a packet that is too small by a duid tha= t is too large=0D +TEST_F (Dhcp6AppendETOptionTest, InvalidDataExpectBufferTooSmall) {=0D + UINT8 *Cursor;=0D + EFI_STATUS Status;=0D + DHCP6_INSTANCE Instance;=0D + UINT16 ElapsedTimeVal;=0D + UINT16 *ElapsedTime;=0D +=0D + Cursor =3D Dhcp6AppendETOptionTest::Packet->Dhcp6.Option;=0D + ElapsedTime =3D &ElapsedTimeVal;=0D +=0D + Packet->Length =3D Packet->Size - 2;=0D +=0D + Status =3D Dhcp6AppendETOption (=0D + Dhcp6AppendETOptionTest::Packet,=0D + &Cursor,=0D + &Instance, // Instance is not used in this function=0D + &ElapsedTime=0D + );=0D +=0D + // verify that we error out because the packet is too small for the opti= on header=0D + ASSERT_EQ (Status, EFI_BUFFER_TOO_SMALL);=0D +=0D + // reset the length=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D +}=0D +=0D +// Test Description:=0D +// Attempt to append an option to a packet that is large enough=0D +TEST_F (Dhcp6AppendETOptionTest, ValidDataExpectSuccess) {=0D + UINT8 *Cursor;=0D + EFI_STATUS Status;=0D + DHCP6_INSTANCE Instance;=0D + UINT16 ElapsedTimeVal;=0D + UINT16 *ElapsedTime;=0D + UINTN ExpectedSize;=0D + UINTN OriginalLength;=0D +=0D + Cursor =3D Dhcp6AppendETOptionTest::Packet->Dhcp6.Option;=0D + ElapsedTime =3D &ElapsedTimeVal;=0D + ExpectedSize =3D 6;=0D + OriginalLength =3D Packet->Length;=0D +=0D + Status =3D Dhcp6AppendETOption (=0D + Dhcp6AppendETOptionTest::Packet,=0D + &Cursor,=0D + &Instance, // Instance is not used in this function=0D + &ElapsedTime=0D + );=0D +=0D + // verify that the status is EFI_SUCCESS=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D +=0D + // verify that the pointer to cursor moved by the expected amount=0D + ASSERT_EQ (Cursor, (UINT8 *)Dhcp6AppendETOptionTest::Packet->Dhcp6.Optio= n + ExpectedSize);=0D +=0D + // verify that the length of the packet is now the expected amount=0D + ASSERT_EQ (Dhcp6AppendETOptionTest::Packet->Length, OriginalLength + Exp= ectedSize);=0D +}=0D +=0D +////////////////////////////////////////////////////////////////////////=0D +// Dhcp6AppendIaOption Tests=0D +////////////////////////////////////////////////////////////////////////=0D +=0D +class Dhcp6AppendIaOptionTest : public ::testing::Test {=0D +public:=0D + UINT8 *Buffer =3D NULL;=0D + EFI_DHCP6_PACKET *Packet;=0D + EFI_DHCP6_IA *Ia;=0D +=0D +protected:=0D + // Add any setup code if needed=0D + virtual void=0D + SetUp (=0D + )=0D + {=0D + // Initialize any resources or variables=0D + Buffer =3D (UINT8 *)AllocateZeroPool (DHCP6_PACKET_MAX_LEN);=0D + ASSERT_NE (Buffer, (UINT8 *)NULL);=0D +=0D + Packet =3D (EFI_DHCP6_PACKET *)Buffer;=0D + Packet->Size =3D DHCP6_PACKET_MAX_LEN;=0D +=0D + Ia =3D (EFI_DHCP6_IA *)AllocateZeroPool (sizeof (EFI_DHCP6_IA) + sizeo= f (EFI_DHCP6_IA_ADDRESS) * 2);=0D + ASSERT_NE (Ia, (EFI_DHCP6_IA *)NULL);=0D +=0D + CopyMem (Ia->IaAddress, mAllDhcpRelayAndServersAddress.Addr, sizeof (E= FI_IPv6_ADDRESS));=0D + CopyMem (Ia->IaAddress + 1, mAllDhcpRelayAndServersAddress.Addr, sizeo= f (EFI_IPv6_ADDRESS));=0D +=0D + Ia->IaAddressCount =3D 2;=0D + }=0D +=0D + // Add any cleanup code if needed=0D + virtual void=0D + TearDown (=0D + )=0D + {=0D + // Clean up any resources or variables=0D + if (Buffer !=3D NULL) {=0D + FreePool (Buffer);=0D + }=0D +=0D + if (Ia !=3D NULL) {=0D + FreePool (Ia);=0D + }=0D + }=0D +};=0D +=0D +// Test Description:=0D +// Attempt to append an option to a packet that doesn't have enough space= =0D +// for the option header=0D +TEST_F (Dhcp6AppendIaOptionTest, IaNaInvalidDataExpectBufferTooSmall) {=0D + UINT8 *Cursor;=0D + EFI_STATUS Status;=0D +=0D + Packet->Length =3D Packet->Size - 2;=0D +=0D + Ia->Descriptor.Type =3D Dhcp6OptIana;=0D + Ia->Descriptor.IaId =3D 0x12345678;=0D +=0D + Cursor =3D Dhcp6AppendIaOptionTest::Packet->Dhcp6.Option;=0D +=0D + Status =3D Dhcp6AppendIaOption (=0D + Dhcp6AppendIaOptionTest::Packet,=0D + &Cursor,=0D + Ia,=0D + 0x12345678,=0D + 0x11111111,=0D + Dhcp6OptIana=0D + );=0D +=0D + // verify that we error out because the packet is too small for the opti= on header=0D + ASSERT_EQ (Status, EFI_BUFFER_TOO_SMALL);=0D +=0D + // reset the length=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D +}=0D +=0D +// Test Description:=0D +// Attempt to append an option to a packet that doesn't have enough space= =0D +// for the option header=0D +TEST_F (Dhcp6AppendIaOptionTest, IaTaInvalidDataExpectBufferTooSmall) {=0D + UINT8 *Cursor;=0D + EFI_STATUS Status;=0D +=0D + // Use up nearly all the space in the packet=0D + Packet->Length =3D Packet->Size - 2;=0D +=0D + Ia->Descriptor.Type =3D Dhcp6OptIata;=0D + Ia->Descriptor.IaId =3D 0x12345678;=0D +=0D + Cursor =3D Dhcp6AppendIaOptionTest::Packet->Dhcp6.Option;=0D +=0D + Status =3D Dhcp6AppendIaOption (=0D + Dhcp6AppendIaOptionTest::Packet,=0D + &Cursor,=0D + Ia,=0D + 0,=0D + 0,=0D + Dhcp6OptIata=0D + );=0D +=0D + // verify that we error out because the packet is too small for the opti= on header=0D + ASSERT_EQ (Status, EFI_BUFFER_TOO_SMALL);=0D +=0D + // reset the length=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D +}=0D +=0D +TEST_F (Dhcp6AppendIaOptionTest, IaNaValidDataExpectSuccess) {=0D + UINT8 *Cursor;=0D + EFI_STATUS Status;=0D + UINTN ExpectedSize;=0D + UINTN OriginalLength;=0D +=0D + //=0D + // 2 bytes for the option header type=0D + //=0D + ExpectedSize =3D 2;=0D + //=0D + // 2 bytes for the option header length=0D + //=0D + ExpectedSize +=3D 2;=0D + //=0D + // 4 bytes for the IAID=0D + //=0D + ExpectedSize +=3D 4;=0D + //=0D + // + 4 bytes for the T1=0D + //=0D + ExpectedSize +=3D 4;=0D + //=0D + // + 4 bytes for the T2=0D + //=0D + ExpectedSize +=3D 4;=0D + //=0D + // + (4 + sizeof (EFI_DHCP6_IA_ADDRESS)) * 2;=0D + // + 2 bytes for the option header type=0D + // + 2 bytes for the option header length=0D + // + sizeof (EFI_DHCP6_IA_ADDRESS) for the IA Address=0D + //=0D + ExpectedSize +=3D (4 + sizeof (EFI_DHCP6_IA_ADDRESS)) * 2;=0D +=0D + Cursor =3D Dhcp6AppendIaOptionTest::Packet->Dhcp6.Option;=0D +=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D + OriginalLength =3D Packet->Length;=0D +=0D + Ia->Descriptor.Type =3D Dhcp6OptIana;=0D + Ia->Descriptor.IaId =3D 0x12345678;=0D +=0D + Status =3D Dhcp6AppendIaOption (=0D + Dhcp6AppendIaOptionTest::Packet,=0D + &Cursor,=0D + Ia,=0D + 0x12345678,=0D + 0x12345678,=0D + Dhcp6OptIana=0D + );=0D +=0D + // verify that the pointer to cursor moved by the expected amount=0D + ASSERT_EQ (Cursor, (UINT8 *)Dhcp6AppendIaOptionTest::Packet->Dhcp6.Optio= n + ExpectedSize);=0D +=0D + // verify that the length of the packet is now the expected amount=0D + ASSERT_EQ (Dhcp6AppendIaOptionTest::Packet->Length, OriginalLength + Exp= ectedSize);=0D +=0D + // verify that the status is EFI_SUCCESS=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D +}=0D +=0D +TEST_F (Dhcp6AppendIaOptionTest, IaTaValidDataExpectSuccess) {=0D + UINT8 *Cursor;=0D + EFI_STATUS Status;=0D + UINTN ExpectedSize;=0D + UINTN OriginalLength;=0D +=0D + //=0D + // 2 bytes for the option header type=0D + //=0D + ExpectedSize =3D 2;=0D + //=0D + // 2 bytes for the option header length=0D + //=0D + ExpectedSize +=3D 2;=0D + //=0D + // 4 bytes for the IAID=0D + //=0D + ExpectedSize +=3D 4;=0D + //=0D + // + (4 + sizeof (EFI_DHCP6_IA_ADDRESS)) * 2;=0D + // + 2 bytes for the option header type=0D + // + 2 bytes for the option header length=0D + // + sizeof (EFI_DHCP6_IA_ADDRESS) for the IA Address=0D + //=0D + ExpectedSize +=3D (4 + sizeof (EFI_DHCP6_IA_ADDRESS)) * 2;=0D +=0D + Cursor =3D Dhcp6AppendIaOptionTest::Packet->Dhcp6.Option;=0D +=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D + OriginalLength =3D Packet->Length;=0D +=0D + Ia->Descriptor.Type =3D Dhcp6OptIata;=0D + Ia->Descriptor.IaId =3D 0x12345678;=0D +=0D + Status =3D Dhcp6AppendIaOption (=0D + Dhcp6AppendIaOptionTest::Packet,=0D + &Cursor,=0D + Ia,=0D + 0,=0D + 0,=0D + Dhcp6OptIata=0D + );=0D +=0D + // verify that the pointer to cursor moved by the expected amount=0D + ASSERT_EQ (Cursor, (UINT8 *)Dhcp6AppendIaOptionTest::Packet->Dhcp6.Optio= n + ExpectedSize);=0D +=0D + // verify that the length of the packet is now the expected amount=0D + ASSERT_EQ (Dhcp6AppendIaOptionTest::Packet->Length, OriginalLength + Exp= ectedSize);=0D +=0D + // verify that the status is EFI_SUCCESS=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 (#114465): https://edk2.groups.io/g/devel/message/114465 Mute This Topic: https://groups.io/mt/103964978/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-