Revision: 19758
          http://sourceforge.net/p/edk2/code/19758
Author:   luobozhang
Date:     2016-01-28 02:32:43 +0000 (Thu, 28 Jan 2016)
Log Message:
-----------
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 <[email protected]>
Reviewed-by: Fu Siyuan <[email protected]>
Reviewed-by: Wu Jiaxin <[email protected]>

Modified Paths:
--------------
    trunk/edk2/NetworkPkg/Dhcp6Dxe/ComponentName.c
    trunk/edk2/NetworkPkg/DnsDxe/ComponentName.c
    trunk/edk2/NetworkPkg/DnsDxe/DnsImpl.c
    trunk/edk2/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
    trunk/edk2/NetworkPkg/Ip6Dxe/ComponentName.c
    trunk/edk2/NetworkPkg/IpSecDxe/IkeService.c
    trunk/edk2/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
    trunk/edk2/NetworkPkg/TcpDxe/TcpMisc.c
    trunk/edk2/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
    trunk/edk2/NetworkPkg/UefiPxeBcDxe/PxeBcDriver.c

Modified: trunk/edk2/NetworkPkg/Dhcp6Dxe/ComponentName.c
===================================================================
--- trunk/edk2/NetworkPkg/Dhcp6Dxe/ComponentName.c      2016-01-28 01:12:59 UTC 
(rev 19757)
+++ trunk/edk2/NetworkPkg/Dhcp6Dxe/ComponentName.c      2016-01-28 02:32:43 UTC 
(rev 19758)
@@ -1,7 +1,7 @@
 /** @file
   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
   are licensed and made available under the terms and conditions of the BSD 
License
@@ -286,7 +286,14 @@
     }
     HandleName = mDhcp6ControllerName[Dhcp6ModeData.Ia->State];
   }
-  
+
+  if (Dhcp6ModeData.Ia != NULL) {
+    FreePool (Dhcp6ModeData.Ia);
+  }
+  if (Dhcp6ModeData.ClientId != NULL) {
+    FreePool (Dhcp6ModeData.ClientId);
+  }
+
   Status = AddUnicodeString2 (
              "eng",
              gDhcp6ComponentName.SupportedLanguages,

Modified: trunk/edk2/NetworkPkg/DnsDxe/ComponentName.c
===================================================================
--- trunk/edk2/NetworkPkg/DnsDxe/ComponentName.c        2016-01-28 01:12:59 UTC 
(rev 19757)
+++ trunk/edk2/NetworkPkg/DnsDxe/ComponentName.c        2016-01-28 02:32:43 UTC 
(rev 19758)
@@ -1,7 +1,7 @@
 /** @file
 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
 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
@@ -211,6 +211,13 @@
     ModeData.DnsConfigData.LocalPort
     );
 
+  if (ModeData.DnsCacheList != NULL) {
+    FreePool (ModeData.DnsCacheList);
+  }
+  if (ModeData.DnsServerList != NULL) {
+    FreePool (ModeData.DnsServerList);
+  }
+
   if (gDnsControllerNameTable != NULL) {
     FreeUnicodeStringTable (gDnsControllerNameTable);
     gDnsControllerNameTable = NULL;
@@ -281,6 +288,13 @@
     ModeData.DnsConfigData.LocalPort
     );
 
+  if (ModeData.DnsCacheList != NULL) {
+    FreePool (ModeData.DnsCacheList);
+  }
+  if (ModeData.DnsServerList != NULL) {
+    FreePool (ModeData.DnsServerList);
+  }
+
   if (gDnsControllerNameTable != NULL) {
     FreeUnicodeStringTable (gDnsControllerNameTable);
     gDnsControllerNameTable = NULL;

Modified: trunk/edk2/NetworkPkg/DnsDxe/DnsImpl.c
===================================================================
--- trunk/edk2/NetworkPkg/DnsDxe/DnsImpl.c      2016-01-28 01:12:59 UTC (rev 
19757)
+++ trunk/edk2/NetworkPkg/DnsDxe/DnsImpl.c      2016-01-28 02:32:43 UTC (rev 
19758)
@@ -1,7 +1,7 @@
 /** @file
 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
 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
@@ -618,11 +618,35 @@
   while (!EFI_ERROR (gBS->CheckEvent (Service->TimerToGetMap))) {
     Udp->Poll (Udp);
 
-    if (!EFI_ERROR (Udp->GetModeData (Udp, NULL, &Ip6Mode, NULL, NULL)) &&
-        Ip6Mode.IsConfigured) {
+    if (!EFI_ERROR (Udp->GetModeData (Udp, NULL, &Ip6Mode, NULL, NULL))) {
+      if (Ip6Mode.AddressList != NULL) {
+        FreePool (Ip6Mode.AddressList);
+      }
 
-      Udp->Configure (Udp, NULL);
-      return (BOOLEAN) (Udp->Configure (Udp, UdpCfgData) == EFI_SUCCESS);
+      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) {
+        Udp->Configure (Udp, NULL);
+        return (BOOLEAN) (Udp->Configure (Udp, UdpCfgData) == EFI_SUCCESS);
+      }
     }
   }
 

Modified: trunk/edk2/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c
===================================================================
--- trunk/edk2/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c   2016-01-28 01:12:59 UTC 
(rev 19757)
+++ trunk/edk2/NetworkPkg/HttpBootDxe/HttpBootDhcp6.c   2016-01-28 02:32:43 UTC 
(rev 19758)
@@ -1,7 +1,7 @@
 /** @file
   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 
 the terms and conditions of the BSD License that accompanies this 
distribution.  
 The full text of the license may be found at
@@ -974,8 +974,13 @@
     Dhcp6->Configure (Dhcp6, NULL);
   } else {
     ZeroMem (&Config, sizeof (EFI_DHCP6_CONFIG_DATA));
-    ZeroMem (&Mode, sizeof (EFI_DHCP6_MODE_DATA));
     Dhcp6->Configure (Dhcp6, &Config);
+    if (Mode.ClientId != NULL) {
+      FreePool (Mode.ClientId);
+    }
+    if (Mode.Ia != NULL) {
+      FreePool (Mode.Ia);
+    }
   }
 
   return Status; 

Modified: trunk/edk2/NetworkPkg/Ip6Dxe/ComponentName.c
===================================================================
--- trunk/edk2/NetworkPkg/Ip6Dxe/ComponentName.c        2016-01-28 01:12:59 UTC 
(rev 19757)
+++ trunk/edk2/NetworkPkg/Ip6Dxe/ComponentName.c        2016-01-28 02:32:43 UTC 
(rev 19758)
@@ -2,7 +2,7 @@
   Implementation of EFI_COMPONENT_NAME_PROTOCOL and
   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
   are licensed and made available under the terms and conditions of the BSD 
License
@@ -263,6 +263,32 @@
   //
   Offset = 0;
   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) {
     Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.StationAddress, Address, 
sizeof(Address));
     if (EFI_ERROR (Status)) {

Modified: trunk/edk2/NetworkPkg/IpSecDxe/IkeService.c
===================================================================
--- trunk/edk2/NetworkPkg/IpSecDxe/IkeService.c 2016-01-28 01:12:59 UTC (rev 
19757)
+++ trunk/edk2/NetworkPkg/IpSecDxe/IkeService.c 2016-01-28 02:32:43 UTC (rev 
19758)
@@ -1,7 +1,7 @@
 /** @file
   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
   are licensed and made available under the terms and conditions of the BSD 
License
@@ -328,6 +328,31 @@
       UdpIoFreeIo (UdpService->Output);
       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.
     //

Modified: trunk/edk2/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
===================================================================
--- trunk/edk2/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c     2016-01-28 01:12:59 UTC 
(rev 19757)
+++ trunk/edk2/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c     2016-01-28 02:32:43 UTC 
(rev 19758)
@@ -1,7 +1,7 @@
 /** @file
   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
   are licensed and made available under the terms and conditions of the BSD 
License
@@ -319,7 +319,30 @@
     Status = Udp6->GetModeData (Udp6, NULL, &Ip6Mode, NULL, NULL);
 
     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) {
         //
         // Continue to configure the Udp6 instance.

Modified: trunk/edk2/NetworkPkg/TcpDxe/TcpMisc.c
===================================================================
--- trunk/edk2/NetworkPkg/TcpDxe/TcpMisc.c      2016-01-28 01:12:59 UTC (rev 
19757)
+++ trunk/edk2/NetworkPkg/TcpDxe/TcpMisc.c      2016-01-28 02:32:43 UTC (rev 
19758)
@@ -2,7 +2,7 @@
   Misc support routines for TCP driver.
 
   (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
   are licensed and made available under the terms and conditions of the BSD 
License
@@ -566,8 +566,32 @@
   } else {
     Ip6 = TcpProto->TcpService->IpIo->Ip.Ip6;
     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));
   }
 }

Modified: trunk/edk2/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
===================================================================
--- trunk/edk2/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c     2016-01-28 01:12:59 UTC 
(rev 19757)
+++ trunk/edk2/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c     2016-01-28 02:32:43 UTC 
(rev 19758)
@@ -2,7 +2,7 @@
   Functions implementation related with DHCPv6 for UefiPxeBc Driver.
 
   (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
   are licensed and made available under the terms and conditions of the BSD 
License
@@ -2082,7 +2082,12 @@
   // to find a valid router 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.
   //

Modified: trunk/edk2/NetworkPkg/UefiPxeBcDxe/PxeBcDriver.c
===================================================================
--- trunk/edk2/NetworkPkg/UefiPxeBcDxe/PxeBcDriver.c    2016-01-28 01:12:59 UTC 
(rev 19757)
+++ trunk/edk2/NetworkPkg/UefiPxeBcDxe/PxeBcDriver.c    2016-01-28 02:32:43 UTC 
(rev 19758)
@@ -2,7 +2,7 @@
   Driver Binding functions implementationfor for UefiPxeBc Driver.
 
   (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
   are licensed and made available under the terms and conditions of the BSD 
License
@@ -1061,6 +1061,30 @@
 
   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.
   //


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to