NetworkPkg:Fix Network memory leak when calling GetModeData interface

Multiple network protocols have a GetModeData() interface, which may
allocate memory resource in the return mode data structure. It's
callers responsibility to free these buffers.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19758 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Zhang Lubo 2016-01-28 02:32:43 +00:00 committed by luobozhang
parent b1b1d64699
commit ce22514e48
10 changed files with 195 additions and 18 deletions

View File

@ -1,7 +1,7 @@
/** @file /** @file
UEFI Component Name(2) protocol implementation for Dhcp6 driver. UEFI Component Name(2) protocol implementation for Dhcp6 driver.
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -286,7 +286,14 @@ UpdateName (
} }
HandleName = mDhcp6ControllerName[Dhcp6ModeData.Ia->State]; HandleName = mDhcp6ControllerName[Dhcp6ModeData.Ia->State];
} }
if (Dhcp6ModeData.Ia != NULL) {
FreePool (Dhcp6ModeData.Ia);
}
if (Dhcp6ModeData.ClientId != NULL) {
FreePool (Dhcp6ModeData.ClientId);
}
Status = AddUnicodeString2 ( Status = AddUnicodeString2 (
"eng", "eng",
gDhcp6ComponentName.SupportedLanguages, gDhcp6ComponentName.SupportedLanguages,

View File

@ -1,7 +1,7 @@
/** @file /** @file
Implementation of EFI_COMPONENT_NAME_PROTOCOL and EFI_COMPONENT_NAME2_PROTOCOL protocol. Implementation of EFI_COMPONENT_NAME_PROTOCOL and EFI_COMPONENT_NAME2_PROTOCOL protocol.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -211,6 +211,13 @@ UpdateDns4Name (
ModeData.DnsConfigData.LocalPort ModeData.DnsConfigData.LocalPort
); );
if (ModeData.DnsCacheList != NULL) {
FreePool (ModeData.DnsCacheList);
}
if (ModeData.DnsServerList != NULL) {
FreePool (ModeData.DnsServerList);
}
if (gDnsControllerNameTable != NULL) { if (gDnsControllerNameTable != NULL) {
FreeUnicodeStringTable (gDnsControllerNameTable); FreeUnicodeStringTable (gDnsControllerNameTable);
gDnsControllerNameTable = NULL; gDnsControllerNameTable = NULL;
@ -281,6 +288,13 @@ UpdateDns6Name (
ModeData.DnsConfigData.LocalPort ModeData.DnsConfigData.LocalPort
); );
if (ModeData.DnsCacheList != NULL) {
FreePool (ModeData.DnsCacheList);
}
if (ModeData.DnsServerList != NULL) {
FreePool (ModeData.DnsServerList);
}
if (gDnsControllerNameTable != NULL) { if (gDnsControllerNameTable != NULL) {
FreeUnicodeStringTable (gDnsControllerNameTable); FreeUnicodeStringTable (gDnsControllerNameTable);
gDnsControllerNameTable = NULL; gDnsControllerNameTable = NULL;

View File

@ -1,7 +1,7 @@
/** @file /** @file
DnsDxe support functions implementation. DnsDxe support functions implementation.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -618,11 +618,35 @@ Dns6GetMapping (
while (!EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) { while (!EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) {
Udp->Poll (Udp); Udp->Poll (Udp);
if (!EFI_ERROR (Udp->GetModeData (Udp, NULL, &Ip6Mode, NULL, NULL)) && if (!EFI_ERROR (Udp->GetModeData (Udp, NULL, &Ip6Mode, NULL, NULL))) {
Ip6Mode.IsConfigured) { if (Ip6Mode.AddressList != NULL) {
FreePool (Ip6Mode.AddressList);
}
Udp->Configure (Udp, NULL); if (Ip6Mode.GroupTable != NULL) {
return (BOOLEAN) (Udp->Configure (Udp, UdpCfgData) == EFI_SUCCESS); FreePool (Ip6Mode.GroupTable);
}
if (Ip6Mode.RouteTable != NULL) {
FreePool (Ip6Mode.RouteTable);
}
if (Ip6Mode.NeighborCache != NULL) {
FreePool (Ip6Mode.NeighborCache);
}
if (Ip6Mode.PrefixTable != NULL) {
FreePool (Ip6Mode.PrefixTable);
}
if (Ip6Mode.IcmpTypeList != NULL) {
FreePool (Ip6Mode.IcmpTypeList);
}
if (Ip6Mode.IsConfigured) {
Udp->Configure (Udp, NULL);
return (BOOLEAN) (Udp->Configure (Udp, UdpCfgData) == EFI_SUCCESS);
}
} }
} }

View File

@ -1,7 +1,7 @@
/** @file /** @file
Functions implementation related with DHCPv6 for HTTP boot driver. Functions implementation related with DHCPv6 for HTTP boot driver.
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution. the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at The full text of the license may be found at
@ -974,8 +974,13 @@ ON_EXIT:
Dhcp6->Configure (Dhcp6, NULL); Dhcp6->Configure (Dhcp6, NULL);
} else { } else {
ZeroMem (&Config, sizeof (EFI_DHCP6_CONFIG_DATA)); ZeroMem (&Config, sizeof (EFI_DHCP6_CONFIG_DATA));
ZeroMem (&Mode, sizeof (EFI_DHCP6_MODE_DATA));
Dhcp6->Configure (Dhcp6, &Config); Dhcp6->Configure (Dhcp6, &Config);
if (Mode.ClientId != NULL) {
FreePool (Mode.ClientId);
}
if (Mode.Ia != NULL) {
FreePool (Mode.Ia);
}
} }
return Status; return Status;

View File

@ -2,7 +2,7 @@
Implementation of EFI_COMPONENT_NAME_PROTOCOL and Implementation of EFI_COMPONENT_NAME_PROTOCOL and
EFI_COMPONENT_NAME2_PROTOCOL protocol. EFI_COMPONENT_NAME2_PROTOCOL protocol.
Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -263,6 +263,32 @@ UpdateName (
// //
Offset = 0; Offset = 0;
Status = Ip6->GetModeData (Ip6, &Ip6ModeData, NULL, NULL); Status = Ip6->GetModeData (Ip6, &Ip6ModeData, NULL, NULL);
if (!EFI_ERROR (Status)) {
if (Ip6ModeData.AddressList != NULL) {
FreePool (Ip6ModeData.AddressList);
}
if (Ip6ModeData.GroupTable != NULL) {
FreePool (Ip6ModeData.GroupTable);
}
if (Ip6ModeData.RouteTable != NULL) {
FreePool (Ip6ModeData.RouteTable);
}
if (Ip6ModeData.NeighborCache != NULL) {
FreePool (Ip6ModeData.NeighborCache);
}
if (Ip6ModeData.PrefixTable != NULL) {
FreePool (Ip6ModeData.PrefixTable);
}
if (Ip6ModeData.IcmpTypeList != NULL) {
FreePool (Ip6ModeData.IcmpTypeList);
}
}
if (!EFI_ERROR (Status) && Ip6ModeData.IsStarted) { if (!EFI_ERROR (Status) && Ip6ModeData.IsStarted) {
Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.StationAddress, Address, sizeof(Address)); Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.StationAddress, Address, sizeof(Address));
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {

View File

@ -1,7 +1,7 @@
/** @file /** @file
Provide IPsec Key Exchange (IKE) service general interfaces. Provide IPsec Key Exchange (IKE) service general interfaces.
Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -328,6 +328,31 @@ IkeOpenOutputUdp (
UdpIoFreeIo (UdpService->Output); UdpIoFreeIo (UdpService->Output);
goto ON_EXIT; goto ON_EXIT;
} }
if (Ip6ModeData.AddressList != NULL) {
FreePool (Ip6ModeData.AddressList);
}
if (Ip6ModeData.GroupTable != NULL) {
FreePool (Ip6ModeData.GroupTable);
}
if (Ip6ModeData.RouteTable != NULL) {
FreePool (Ip6ModeData.RouteTable);
}
if (Ip6ModeData.NeighborCache != NULL) {
FreePool (Ip6ModeData.NeighborCache);
}
if (Ip6ModeData.PrefixTable != NULL) {
FreePool (Ip6ModeData.PrefixTable);
}
if (Ip6ModeData.IcmpTypeList != NULL) {
FreePool (Ip6ModeData.IcmpTypeList);
}
// //
// Reconfigure udp6 io without remote address. // Reconfigure udp6 io without remote address.
// //

View File

@ -1,7 +1,7 @@
/** @file /** @file
Mtftp6 support functions implementation. Mtftp6 support functions implementation.
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -319,6 +319,29 @@ Mtftp6GetMapping (
Status = Udp6->GetModeData (Udp6, NULL, &Ip6Mode, NULL, NULL); Status = Udp6->GetModeData (Udp6, NULL, &Ip6Mode, NULL, NULL);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
if (Ip6Mode.AddressList != NULL) {
FreePool (Ip6Mode.AddressList);
}
if (Ip6Mode.GroupTable != NULL) {
FreePool (Ip6Mode.GroupTable);
}
if (Ip6Mode.RouteTable != NULL) {
FreePool (Ip6Mode.RouteTable);
}
if (Ip6Mode.NeighborCache != NULL) {
FreePool (Ip6Mode.NeighborCache);
}
if (Ip6Mode.PrefixTable != NULL) {
FreePool (Ip6Mode.PrefixTable);
}
if (Ip6Mode.IcmpTypeList != NULL) {
FreePool (Ip6Mode.IcmpTypeList);
}
if (Ip6Mode.IsConfigured) { if (Ip6Mode.IsConfigured) {
// //

View File

@ -2,7 +2,7 @@
Misc support routines for TCP driver. Misc support routines for TCP driver.
(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR> (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -566,7 +566,31 @@ TcpGetRcvMss (
} else { } else {
Ip6 = TcpProto->TcpService->IpIo->Ip.Ip6; Ip6 = TcpProto->TcpService->IpIo->Ip.Ip6;
ASSERT (Ip6 != NULL); ASSERT (Ip6 != NULL);
Ip6->GetModeData (Ip6, &Ip6Mode, NULL, NULL); if (!EFI_ERROR (Ip6->GetModeData (Ip6, &Ip6Mode, NULL, NULL))) {
if (Ip6Mode.AddressList != NULL) {
FreePool (Ip6Mode.AddressList);
}
if (Ip6Mode.GroupTable != NULL) {
FreePool (Ip6Mode.GroupTable);
}
if (Ip6Mode.RouteTable != NULL) {
FreePool (Ip6Mode.RouteTable);
}
if (Ip6Mode.NeighborCache != NULL) {
FreePool (Ip6Mode.NeighborCache);
}
if (Ip6Mode.PrefixTable != NULL) {
FreePool (Ip6Mode.PrefixTable);
}
if (Ip6Mode.IcmpTypeList != NULL) {
FreePool (Ip6Mode.IcmpTypeList);
}
}
return (UINT16) (Ip6Mode.MaxPacketSize - sizeof (TCP_HEAD)); return (UINT16) (Ip6Mode.MaxPacketSize - sizeof (TCP_HEAD));
} }

View File

@ -2,7 +2,7 @@
Functions implementation related with DHCPv6 for UefiPxeBc Driver. Functions implementation related with DHCPv6 for UefiPxeBc Driver.
(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR> (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -2082,7 +2082,12 @@ PxeBcDhcp6Sarr (
// to find a valid router address. // to find a valid router address.
// //
CopyMem (&Private->TmpStationIp.v6, &Mode.Ia->IaAddress[0].IpAddress, sizeof (EFI_IPv6_ADDRESS)); CopyMem (&Private->TmpStationIp.v6, &Mode.Ia->IaAddress[0].IpAddress, sizeof (EFI_IPv6_ADDRESS));
if (Mode.ClientId != NULL) {
FreePool (Mode.ClientId);
}
if (Mode.Ia != NULL) {
FreePool (Mode.Ia);
}
// //
// Check the selected offer whether BINL retry is needed. // Check the selected offer whether BINL retry is needed.
// //

View File

@ -2,7 +2,7 @@
Driver Binding functions implementationfor for UefiPxeBc Driver. Driver Binding functions implementationfor for UefiPxeBc Driver.
(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR> (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR> Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -1061,6 +1061,30 @@ PxeBcCreateIp6Children (
Private->Ip6MaxPacketSize = Ip6ModeData.MaxPacketSize; Private->Ip6MaxPacketSize = Ip6ModeData.MaxPacketSize;
if (Ip6ModeData.AddressList != NULL) {
FreePool (Ip6ModeData.AddressList);
}
if (Ip6ModeData.GroupTable != NULL) {
FreePool (Ip6ModeData.GroupTable);
}
if (Ip6ModeData.RouteTable != NULL) {
FreePool (Ip6ModeData.RouteTable);
}
if (Ip6ModeData.NeighborCache != NULL) {
FreePool (Ip6ModeData.NeighborCache);
}
if (Ip6ModeData.PrefixTable != NULL) {
FreePool (Ip6ModeData.PrefixTable);
}
if (Ip6ModeData.IcmpTypeList != NULL) {
FreePool (Ip6ModeData.IcmpTypeList);
}
// //
// Locate Ip6->Ip6Config and store it for set IPv6 address. // Locate Ip6->Ip6Config and store it for set IPv6 address.
// //