]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Enhance the code to avoid the potential of return address of local variable to output...
authortye1 <tye1@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 17 Jan 2011 05:54:13 +0000 (05:54 +0000)
committertye1 <tye1@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 17 Jan 2011 05:54:13 +0000 (05:54 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11255 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Include/Library/TcpIoLib.h
MdeModulePkg/Library/DxeTcpIoLib/DxeTcpIoLib.c

index 050f14b28f918c7302744bc19237df726542c5a8..49008bdefc5bba7dbba6371f5796c6b49788c6fb 100644 (file)
@@ -2,7 +2,7 @@
   This library is used to share code between UEFI network stack modules.\r
   It provides the helper routines to access TCP service.\r
 \r
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at<BR>\r
@@ -114,10 +114,11 @@ typedef struct {
   @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
   @retval EFI_UNSUPPORTED        One or more of the control options are not
                                  supported in the implementation.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.\r
   @retval Others                 Failed to create the TCP socket or configure it.\r
 \r
 **/\r
-EFI_STATUS
+EFI_STATUS\r
 EFIAPI\r
 TcpIoCreateSocket (
   IN EFI_HANDLE             Image,
index 2a65422e1c5875b1d7946395766be818b7df73fe..730ccb2cafe8b36fda3d7a89898588dee12a90be 100644 (file)
@@ -2,7 +2,7 @@
   This library is used to share code between UEFI network stack modules.\r
   It provides the helper routines to access TCP service.\r
 \r
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at<BR>\r
@@ -123,6 +123,7 @@ ON_EXIT:
   @retval EFI_INVALID_PARAMETER  One or more parameters are invalid.\r
   @retval EFI_UNSUPPORTED        One or more of the control options are not
                                  supported in the implementation.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.\r
   @retval Others                 Failed to create the TCP socket or configure it.\r
 \r
 **/\r
@@ -148,6 +149,7 @@ TcpIoCreateSocket (
   EFI_TCP6_CONFIG_DATA      Tcp6ConfigData;\r
   EFI_TCP6_ACCESS_POINT     *AccessPoint6;\r
   EFI_TCP6_PROTOCOL         *Tcp6;\r
+  EFI_TCP4_RECEIVE_DATA     *RxData;\r
 \r
   if ((Image == NULL) || (Controller == NULL) || (ConfigData == NULL) || (TcpIo == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -363,6 +365,14 @@ TcpIoCreateSocket (
 \r
   TcpIo->RxToken.Tcp4Token.CompletionToken.Event = Event;\r
 \r
+  RxData = (EFI_TCP4_RECEIVE_DATA *) AllocateZeroPool (sizeof (EFI_TCP4_RECEIVE_DATA));\r
+  if (RxData == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ON_ERROR;\r
+  }\r
+\r
+  TcpIo->RxToken.Tcp4Token.Packet.RxData = RxData;\r
+\r
   Status = gBS->CreateEvent (
                   EVT_NOTIFY_SIGNAL,
                   TPL_NOTIFY,
@@ -446,6 +456,10 @@ TcpIoDestroySocket (
     gBS->CloseEvent (Event);\r
   }\r
 \r
+  if (TcpIo->RxToken.Tcp4Token.Packet.RxData != NULL) {\r
+    FreePool (TcpIo->RxToken.Tcp4Token.Packet.RxData);\r
+  }\r
+\r
   Tcp4 = NULL;\r
   Tcp6 = NULL;\r
 \r
@@ -868,7 +882,7 @@ TcpIoReceive (
 {\r
   EFI_TCP4_PROTOCOL         *Tcp4;\r
   EFI_TCP6_PROTOCOL         *Tcp6;\r
-  EFI_TCP4_RECEIVE_DATA     RxData;\r
+  EFI_TCP4_RECEIVE_DATA     *RxData;\r
   EFI_STATUS                Status;\r
   NET_FRAGMENT              *Fragment;\r
   UINT32                    FragmentCount;\r
@@ -878,6 +892,11 @@ TcpIoReceive (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  RxData = TcpIo->RxToken.Tcp4Token.Packet.RxData;\r
+  if (RxData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   Tcp4 = NULL;\r
   Tcp6 = NULL;\r
 \r
@@ -892,8 +911,6 @@ TcpIoReceive (
       return EFI_DEVICE_ERROR;\r
     }\r
 \r
-    TcpIo->RxToken.Tcp4Token.Packet.RxData = &RxData;\r
-\r
   } else if (TcpIo->TcpVersion == TCP_VERSION_6) {\r
     Tcp6 = TcpIo->Tcp.Tcp6;\r
 \r
@@ -905,8 +922,6 @@ TcpIoReceive (
       return EFI_DEVICE_ERROR; \r
     }\r
 \r
-    TcpIo->RxToken.Tcp6Token.Packet.RxData = (EFI_TCP6_RECEIVE_DATA *) &RxData;\r
-\r
   } else {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -922,14 +937,14 @@ TcpIoReceive (
   //
   NetbufBuildExt (Packet, Fragment, &FragmentCount);
 \r
-  RxData.FragmentCount          = 1;\r
+  RxData->FragmentCount         = 1;\r
   CurrentFragment               = 0;\r
   Status                        = EFI_SUCCESS;
 
   while (CurrentFragment < FragmentCount) {
-    RxData.DataLength                       = Fragment[CurrentFragment].Len;
-    RxData.FragmentTable[0].FragmentLength  = Fragment[CurrentFragment].Len;
-    RxData.FragmentTable[0].FragmentBuffer  = Fragment[CurrentFragment].Bulk;
+    RxData->DataLength                       = Fragment[CurrentFragment].Len;\r
+    RxData->FragmentTable[0].FragmentLength  = Fragment[CurrentFragment].Len;\r
+    RxData->FragmentTable[0].FragmentBuffer  = Fragment[CurrentFragment].Bulk;\r
 \r
     if (TcpIo->TcpVersion == TCP_VERSION_4) {\r
       Status = Tcp4->Receive (Tcp4, &TcpIo->RxToken.Tcp4Token);\r
@@ -974,22 +989,16 @@ TcpIoReceive (
       goto ON_EXIT;
     }
 
-    Fragment[CurrentFragment].Len -= RxData.FragmentTable[0].FragmentLength;
+    Fragment[CurrentFragment].Len -= RxData->FragmentTable[0].FragmentLength;\r
     if (Fragment[CurrentFragment].Len == 0) {
       CurrentFragment++;
     } else {
-      Fragment[CurrentFragment].Bulk += RxData.FragmentTable[0].FragmentLength;
+      Fragment[CurrentFragment].Bulk += RxData->FragmentTable[0].FragmentLength;\r
     }
   }
 
 ON_EXIT:
 \r
-  if (TcpIo->TcpVersion == TCP_VERSION_4) {\r
-    TcpIo->RxToken.Tcp4Token.Packet.RxData = NULL;\r
-  } else {\r
-    TcpIo->RxToken.Tcp6Token.Packet.RxData = NULL;\r
-  }\r
-  \r
   if (Fragment != NULL) {\r
     FreePool (Fragment);\r
   }\r