]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/IpIoLib: add more error handling code to DxeIpIoLib.
authorFu Siyuan <siyuan.fu@intel.com>
Wed, 13 Dec 2017 07:06:16 +0000 (15:06 +0800)
committerFu Siyuan <siyuan.fu@intel.com>
Fri, 22 Dec 2017 05:30:20 +0000 (13:30 +0800)
In DxeIpIo, there are several places not check the returned value of called functions.
This patch is to add the error handling to these functions.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
MdeModulePkg/Include/Library/IpIoLib.h
MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c

index 0bebdb73b5b32ebd6df05a7a01c7bd23e5df53b8..059eb05f172a2361c9437a25fb39a37788220b72 100644 (file)
@@ -428,7 +428,7 @@ IpIoSend (
   IN     IP_IO_IP_INFO  *Sender        OPTIONAL,\r
   IN     VOID           *Context       OPTIONAL,\r
   IN     VOID           *NotifyData    OPTIONAL,\r
-  IN     EFI_IP_ADDRESS *Dest,\r
+  IN     EFI_IP_ADDRESS *Dest          OPTIONAL,\r
   IN     IP_IO_OVERRIDE *OverrideData  OPTIONAL\r
   );\r
 \r
index cd9bc3bd543749a5f85b5687efb5958e04a8d951..fe5699d9517885544df2165117ebd7c367fa2008 100644 (file)
@@ -234,24 +234,25 @@ IpIoCloseProtocolDestroyIpChild (
   //\r
   // Close the previously openned IP protocol.\r
   //\r
-  gBS->CloseProtocol (\r
-         ChildHandle,\r
-         IpProtocolGuid,\r
-         ImageHandle,\r
-         ControllerHandle\r
-         );\r
+  Status = gBS->CloseProtocol (\r
+                  ChildHandle,\r
+                  IpProtocolGuid,\r
+                  ImageHandle,\r
+                  ControllerHandle\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
   //\r
   // Destroy the IP child.\r
   //\r
-  Status = NetLibDestroyServiceChild (\r
-             ControllerHandle,\r
-             ImageHandle,\r
-             ServiceBindingGuid,\r
-             ChildHandle\r
-             );\r
-\r
-  return Status;\r
+  return NetLibDestroyServiceChild (\r
+           ControllerHandle,\r
+           ImageHandle,\r
+           ServiceBindingGuid,\r
+           ChildHandle\r
+           );\r
 }\r
 \r
 /**\r
@@ -377,8 +378,14 @@ IpIoIcmpv4Handler (
   TrimBytes  = (UINT32) (PayLoadHdr - (UINT8 *) IcmpHdr);\r
 \r
   NetbufTrim (Pkt, TrimBytes, TRUE);\r
-\r
-  IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext);\r
+  \r
+  //\r
+  // If the input packet has invalid format, and TrimBytes is larger than \r
+  // the packet size, the NetbufTrim might trim the packet to zero.\r
+  //\r
+  if (Pkt->TotalSize != 0) {\r
+    IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext);\r
+  }\r
 \r
   return EFI_SUCCESS;  \r
 }\r
@@ -539,7 +546,13 @@ IpIoIcmpv6Handler (
   \r
   NetbufTrim (Pkt, TrimBytes, TRUE);\r
 \r
-  IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext);\r
+  //\r
+  // If the input packet has invalid format, and TrimBytes is larger than \r
+  // the packet size, the NetbufTrim might trim the packet to zero.\r
+  //\r
+  if (Pkt->TotalSize != 0) {\r
+    IpIo->PktRcvdNotify (EFI_ICMP_ERROR, IcmpErr, Session, Pkt, IpIo->RcvdContext);\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -1542,7 +1555,7 @@ IpIoSend (
   IN     IP_IO_IP_INFO  *Sender        OPTIONAL,\r
   IN     VOID           *Context       OPTIONAL,\r
   IN     VOID           *NotifyData    OPTIONAL,\r
-  IN     EFI_IP_ADDRESS *Dest,\r
+  IN     EFI_IP_ADDRESS *Dest          OPTIONAL,\r
   IN     IP_IO_OVERRIDE *OverrideData  OPTIONAL\r
   )\r
 {\r
@@ -1799,19 +1812,23 @@ IpIoConfigIp (
   }\r
 \r
   if (IpConfigData != NULL) {\r
-    if (IpInfo->IpVersion == IP_VERSION_4){\r
+    if (IpInfo->IpVersion == IP_VERSION_4) {\r
 \r
       if (((EFI_IP4_CONFIG_DATA *) IpConfigData)->UseDefaultAddress) {\r
-        Ip.Ip4->GetModeData (\r
-                  Ip.Ip4, \r
-                  &Ip4ModeData, \r
-                  NULL, \r
-                  NULL\r
-                  );\r
+        Status = Ip.Ip4->GetModeData (\r
+                           Ip.Ip4, \r
+                           &Ip4ModeData, \r
+                           NULL, \r
+                           NULL\r
+                           );\r
+        if (EFI_ERROR (Status)) {\r
+          Ip.Ip4->Configure (Ip.Ip4, NULL);\r
+          goto OnExit;\r
+        }\r
 \r
         IP4_COPY_ADDRESS (&((EFI_IP4_CONFIG_DATA*) IpConfigData)->StationAddress, &Ip4ModeData.ConfigData.StationAddress);\r
         IP4_COPY_ADDRESS (&((EFI_IP4_CONFIG_DATA*) IpConfigData)->SubnetMask, &Ip4ModeData.ConfigData.SubnetMask);\r
-    }\r
+      }\r
 \r
       CopyMem (\r
         &IpInfo->Addr.Addr, \r
@@ -1828,16 +1845,20 @@ IpIoConfigIp (
                          Ip.Ip4,\r
                          &IpInfo->DummyRcvToken.Ip4Token\r
                          );\r
-    if (EFI_ERROR (Status)) {\r
-      Ip.Ip4->Configure (Ip.Ip4, NULL);\r
-    }\r
-  } else {\r
-    Ip.Ip6->GetModeData (\r
-              Ip.Ip6,\r
-              &Ip6ModeData,\r
-              NULL,\r
-              NULL\r
-              );\r
+      if (EFI_ERROR (Status)) {\r
+        Ip.Ip4->Configure (Ip.Ip4, NULL);\r
+      }\r
+    } else {\r
+      Status = Ip.Ip6->GetModeData (\r
+                         Ip.Ip6,\r
+                         &Ip6ModeData,\r
+                         NULL,\r
+                         NULL\r
+                         );\r
+      if (EFI_ERROR (Status)) {\r
+        Ip.Ip6->Configure (Ip.Ip6, NULL);\r
+        goto OnExit;\r
+      }\r
 \r
       if (Ip6ModeData.IsConfigured) {\r
         CopyMem (\r