]> xenbits.xensource.com Git - people/aperard/ovmf.git/commitdiff
NetworkPkg: PxeBcDhcp6GoogleTest: Fix Stack Smashing Unit Test
authorOliver Smith-Denny <osde@linux.microsoft.com>
Wed, 28 Aug 2024 16:39:45 +0000 (09:39 -0700)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 13 Sep 2024 03:58:46 +0000 (03:58 +0000)
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>
NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp

index 61736ff79e83fe5d62785e9d1bbae82dd9cc7505..e529bc6daf1d5c79713841ec2b6c243782222dc9 100644 (file)
@@ -290,15 +290,9 @@ TEST_F (PxeBcCacheDnsServerAddressesTest, AttemptUnderflowTest) {
 // Test Description\r
 // Test that we can handle recursive dns (multiple dns entries)\r
 TEST_F (PxeBcCacheDnsServerAddressesTest, MultipleDnsEntries) {\r
-  EFI_DHCP6_PACKET_OPTION   Option  = { 0 };\r
+  EFI_DHCP6_PACKET_OPTION   *Option = NULL;\r
   PXEBC_DHCP6_PACKET_CACHE  *Cache6 = NULL;\r
 \r
-  Private.SelectIndex                         = 1; // SelectIndex is 1-based\r
-  Cache6                                      = &Private.OfferBuffer[Private.SelectIndex - 1].Dhcp6;\r
-  Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] = &Option;\r
-  // Setup the DHCPv6 offer packet\r
-  Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpCode = DHCP6_OPT_SERVER_ID;\r
-\r
   EFI_IPv6_ADDRESS  addresses[2] = {\r
     // 2001:db8:85a3::8a2e:370:7334\r
     { 0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34 },\r
@@ -306,7 +300,18 @@ TEST_F (PxeBcCacheDnsServerAddressesTest, MultipleDnsEntries) {
     { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x78, 0x91, 0xc3, 0xec, 0xd7, 0x4f, 0xf9 }\r
   };\r
 \r
-  CopyMem (Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->Data, &addresses, sizeof (addresses));\r
+  Option = (EFI_DHCP6_PACKET_OPTION *)AllocatePool (sizeof (*Option) + sizeof (addresses));\r
+  if (Option == NULL) {\r
+    ASSERT_NE (Option, nullptr);\r
+  }\r
+\r
+  Private.SelectIndex                         = 1; // SelectIndex is 1-based\r
+  Cache6                                      = &Private.OfferBuffer[Private.SelectIndex - 1].Dhcp6;\r
+  Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] = Option;\r
+  // Setup the DHCPv6 offer packet\r
+  Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpCode = DHCP6_OPT_SERVER_ID;\r
+\r
+  CopyMem (Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->Data, addresses, sizeof (addresses));\r
 \r
   Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpLen = NTOHS (sizeof (addresses));\r
 \r
@@ -327,6 +332,10 @@ TEST_F (PxeBcCacheDnsServerAddressesTest, MultipleDnsEntries) {
   if (Private.DnsServer) {\r
     FreePool (Private.DnsServer);\r
   }\r
+\r
+  if (Option) {\r
+    FreePool (Option);\r
+  }\r
 }\r
 \r
 ///////////////////////////////////////////////////////////////////////////////\r