mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-23 13:44:33 +02:00
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>
This commit is contained in:
parent
6706fe6e23
commit
837bb62661
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
x
Reference in New Issue
Block a user