diff options
author | Oliver Smith-Denny <osde@linux.microsoft.com> | 2024-08-28 09:39:45 -0700 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-09-13 03:58:46 +0000 |
commit | 837bb626613eb6ae2d9c647b39dc2784a6586c2d (patch) | |
tree | ec09bdb10e16c68f94ed8a25fa551d860e557ef8 | |
parent | 6706fe6e239253e45b28147e06f71dd68a374007 (diff) | |
download | edk2-837bb626613eb6ae2d9c647b39dc2784a6586c2d.tar.gz edk2-837bb626613eb6ae2d9c647b39dc2784a6586c2d.tar.bz2 edk2-837bb626613eb6ae2d9c647b39dc2784a6586c2d.zip |
NetworkPkg: PxeBcDhcp6GoogleTest: Fix Stack Smashing Unit Test
PxeBcDhcp6GoogleTest's MultipleDnsEntries test started to fail
with stack cookies added for host applications. Debugging this
showed that the test was attempting to copy two UINT16s to a
UINT8 Data[1] array allocated on the stack. This was moved to
a heap based allocation for a UINT32 to accommodate the proper
size. After this fix, the unit test passed with stack cookies
enabled.
Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
-rw-r--r-- | NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp index 61736ff79e..e529bc6daf 100644 --- a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp +++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp @@ -290,15 +290,9 @@ TEST_F (PxeBcCacheDnsServerAddressesTest, AttemptUnderflowTest) { // Test Description
// Test that we can handle recursive dns (multiple dns entries)
TEST_F (PxeBcCacheDnsServerAddressesTest, MultipleDnsEntries) {
- EFI_DHCP6_PACKET_OPTION Option = { 0 };
+ EFI_DHCP6_PACKET_OPTION *Option = NULL;
PXEBC_DHCP6_PACKET_CACHE *Cache6 = NULL;
- Private.SelectIndex = 1; // SelectIndex is 1-based
- Cache6 = &Private.OfferBuffer[Private.SelectIndex - 1].Dhcp6;
- Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] = &Option;
- // Setup the DHCPv6 offer packet
- Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpCode = DHCP6_OPT_SERVER_ID;
-
EFI_IPv6_ADDRESS addresses[2] = {
// 2001:db8:85a3::8a2e:370:7334
{ 0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34 },
@@ -306,7 +300,18 @@ TEST_F (PxeBcCacheDnsServerAddressesTest, MultipleDnsEntries) { { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x78, 0x91, 0xc3, 0xec, 0xd7, 0x4f, 0xf9 }
};
- CopyMem (Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->Data, &addresses, sizeof (addresses));
+ Option = (EFI_DHCP6_PACKET_OPTION *)AllocatePool (sizeof (*Option) + sizeof (addresses));
+ if (Option == NULL) {
+ ASSERT_NE (Option, nullptr);
+ }
+
+ Private.SelectIndex = 1; // SelectIndex is 1-based
+ Cache6 = &Private.OfferBuffer[Private.SelectIndex - 1].Dhcp6;
+ Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] = Option;
+ // Setup the DHCPv6 offer packet
+ Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpCode = DHCP6_OPT_SERVER_ID;
+
+ CopyMem (Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->Data, addresses, sizeof (addresses));
Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpLen = NTOHS (sizeof (addresses));
@@ -327,6 +332,10 @@ TEST_F (PxeBcCacheDnsServerAddressesTest, MultipleDnsEntries) { if (Private.DnsServer) {
FreePool (Private.DnsServer);
}
+
+ if (Option) {
+ FreePool (Option);
+ }
}
///////////////////////////////////////////////////////////////////////////////
|