]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Udp6Dxe/Udp6Impl.c
ShellPkg/DP: Add more check for input parameters
[mirror_edk2.git] / NetworkPkg / Udp6Dxe / Udp6Impl.c
index 5896a7a2e07b3a4ae649ad637add462f1c5b2100..25336362b0c19515cd95ade036dd4e561bee8307 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Udp6 driver's whole implementation.\r
 \r
 /** @file\r
   Udp6 driver's whole implementation.\r
 \r
-  Copyright (c) 2009 - 2016 Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -57,6 +57,9 @@ Udp6FindInstanceByPort (
   interface. It's called to signal the udp TxToken when the IpIo layer completes\r
   transmitting of the udp datagram.\r
 \r
   interface. It's called to signal the udp TxToken when the IpIo layer completes\r
   transmitting of the udp datagram.\r
 \r
+  If Context is NULL, then ASSERT().\r
+  If NotifyData is NULL, then ASSERT().\r
+\r
   @param[in]  Status            The completion status of the output udp datagram.\r
   @param[in]  Context           Pointer to the context data.\r
   @param[in]  Sender            Specify a EFI_IP6_PROTOCOL for sending.\r
   @param[in]  Status            The completion status of the output udp datagram.\r
   @param[in]  Context           Pointer to the context data.\r
   @param[in]  Sender            Specify a EFI_IP6_PROTOCOL for sending.\r
@@ -75,6 +78,10 @@ Udp6DgramSent (
 /**\r
   This function processes the received datagram passed up by the IpIo layer.\r
 \r
 /**\r
   This function processes the received datagram passed up by the IpIo layer.\r
 \r
+  If NetSession is NULL, then ASSERT().\r
+  If Packet is NULL, then ASSERT().\r
+  If Context is NULL, then ASSERT().\r
+\r
   @param[in]  Status            The status of this udp datagram.\r
   @param[in]  IcmpError         The IcmpError code, only available when Status is\r
                                 EFI_ICMP_ERROR.\r
   @param[in]  Status            The status of this udp datagram.\r
   @param[in]  IcmpError         The IcmpError code, only available when Status is\r
                                 EFI_ICMP_ERROR.\r
@@ -158,7 +165,8 @@ Udp6RecycleRxDataWrap (
   @param[in]  RxData             Pointer to the EFI_UDP6_RECEIVE_DATA of this\r
                                  datagram.\r
 \r
   @param[in]  RxData             Pointer to the EFI_UDP6_RECEIVE_DATA of this\r
                                  datagram.\r
 \r
-  @return Pointer to the structure wrapping the RxData and the Packet.\r
+  @return Pointer to the structure wrapping the RxData and the Packet. NULL will\r
+          be returned if any error occurs.\r
 \r
 **/\r
 UDP6_RXDATA_WRAP *\r
 \r
 **/\r
 UDP6_RXDATA_WRAP *\r
@@ -364,7 +372,7 @@ ON_ERROR:
 \r
   IpIoDestroy (Udp6Service->IpIo);\r
   Udp6Service->IpIo = NULL;\r
 \r
   IpIoDestroy (Udp6Service->IpIo);\r
   Udp6Service->IpIo = NULL;\r
-  \r
+\r
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
 \r
@@ -390,7 +398,7 @@ Udp6CleanService (
   //\r
   IpIoDestroy (Udp6Service->IpIo);\r
   Udp6Service->IpIo = NULL;\r
   //\r
   IpIoDestroy (Udp6Service->IpIo);\r
   Udp6Service->IpIo = NULL;\r
-  \r
+\r
   ZeroMem (Udp6Service, sizeof (UDP6_SERVICE_DATA));\r
 }\r
 \r
   ZeroMem (Udp6Service, sizeof (UDP6_SERVICE_DATA));\r
 }\r
 \r
@@ -976,6 +984,9 @@ Udp6RemoveToken (
   interface. It's called to signal the udp TxToken when IpIo layer completes the\r
   transmitting of the udp datagram.\r
 \r
   interface. It's called to signal the udp TxToken when IpIo layer completes the\r
   transmitting of the udp datagram.\r
 \r
+  If Context is NULL, then ASSERT().\r
+  If NotifyData is NULL, then ASSERT().\r
+\r
   @param[in]  Status            The completion status of the output udp datagram.\r
   @param[in]  Context           Pointer to the context data.\r
   @param[in]  Sender            Specify a EFI_IP6_PROTOCOL for sending.\r
   @param[in]  Status            The completion status of the output udp datagram.\r
   @param[in]  Context           Pointer to the context data.\r
   @param[in]  Sender            Specify a EFI_IP6_PROTOCOL for sending.\r
@@ -994,6 +1005,8 @@ Udp6DgramSent (
   UDP6_INSTANCE_DATA         *Instance;\r
   EFI_UDP6_COMPLETION_TOKEN  *Token;\r
 \r
   UDP6_INSTANCE_DATA         *Instance;\r
   EFI_UDP6_COMPLETION_TOKEN  *Token;\r
 \r
+  ASSERT (Context != NULL && NotifyData != NULL);\r
+\r
   Instance = (UDP6_INSTANCE_DATA *) Context;\r
   Token    = (EFI_UDP6_COMPLETION_TOKEN *) NotifyData;\r
 \r
   Instance = (UDP6_INSTANCE_DATA *) Context;\r
   Token    = (EFI_UDP6_COMPLETION_TOKEN *) NotifyData;\r
 \r
@@ -1011,6 +1024,10 @@ Udp6DgramSent (
 /**\r
   This function processes the received datagram passed up by the IpIo layer.\r
 \r
 /**\r
   This function processes the received datagram passed up by the IpIo layer.\r
 \r
+  If NetSession is NULL, then ASSERT().\r
+  If Packet is NULL, then ASSERT().\r
+  If Context is NULL, then ASSERT().\r
+\r
   @param[in]  Status            The status of this udp datagram.\r
   @param[in]  IcmpError         The IcmpError code, only available when Status is\r
                                 EFI_ICMP_ERROR.\r
   @param[in]  Status            The status of this udp datagram.\r
   @param[in]  IcmpError         The IcmpError code, only available when Status is\r
                                 EFI_ICMP_ERROR.\r
@@ -1030,6 +1047,7 @@ Udp6DgramRcvd (
   IN VOID                  *Context\r
   )\r
 {\r
   IN VOID                  *Context\r
   )\r
 {\r
+  ASSERT (NetSession != NULL && Packet != NULL && Context != NULL);\r
   NET_CHECK_SIGNATURE (Packet, NET_BUF_SIGNATURE);\r
 \r
   //\r
   NET_CHECK_SIGNATURE (Packet, NET_BUF_SIGNATURE);\r
 \r
   //\r
@@ -1374,7 +1392,8 @@ Udp6RecycleRxDataWrap (
   @param[in]  RxData             Pointer to the EFI_UDP6_RECEIVE_DATA of this\r
                                  datagram.\r
 \r
   @param[in]  RxData             Pointer to the EFI_UDP6_RECEIVE_DATA of this\r
                                  datagram.\r
 \r
-  @return Pointer to the structure wrapping the RxData and the Packet.\r
+  @return Pointer to the structure wrapping the RxData and the Packet. NULL will\r
+          be returned if any error occurs.\r
 \r
 **/\r
 UDP6_RXDATA_WRAP *\r
 \r
 **/\r
 UDP6_RXDATA_WRAP *\r
@@ -1598,16 +1617,20 @@ Udp6Demultiplex (
   EFI_UDP6_SESSION_DATA  *Udp6Session;\r
   UINTN                  Enqueued;\r
 \r
   EFI_UDP6_SESSION_DATA  *Udp6Session;\r
   UINTN                  Enqueued;\r
 \r
-  if (Packet->TotalSize < sizeof (EFI_UDP_HEADER)) {\r
+  if (Packet->TotalSize < UDP6_HEADER_SIZE) {\r
     NetbufFree (Packet);\r
     return;\r
   }\r
     NetbufFree (Packet);\r
     return;\r
   }\r
-  \r
+\r
   //\r
   // Get the datagram header from the packet buffer.\r
   //\r
   Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
   ASSERT (Udp6Header != NULL);\r
   //\r
   // Get the datagram header from the packet buffer.\r
   //\r
   Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
   ASSERT (Udp6Header != NULL);\r
+  if (Udp6Header == NULL) {\r
+    NetbufFree (Packet);\r
+    return;\r
+  }\r
 \r
   if (Udp6Header->Checksum != 0) {\r
     //\r
 \r
   if (Udp6Header->Checksum != 0) {\r
     //\r
@@ -1718,6 +1741,9 @@ Udp6SendPortUnreach (
   //\r
   Ip6ModeData = AllocateZeroPool (sizeof (EFI_IP6_MODE_DATA));\r
   ASSERT (Ip6ModeData != NULL);\r
   //\r
   Ip6ModeData = AllocateZeroPool (sizeof (EFI_IP6_MODE_DATA));\r
   ASSERT (Ip6ModeData != NULL);\r
+  if (Ip6ModeData == NULL) {\r
+    goto EXIT;\r
+  }\r
 \r
   //\r
   // If not finding the related IpSender use the default IpIo to send out\r
 \r
   //\r
   // If not finding the related IpSender use the default IpIo to send out\r
@@ -1766,6 +1792,9 @@ Udp6SendPortUnreach (
   //\r
   IcmpErrHdr = (IP6_ICMP_ERROR_HEAD *) NetbufAllocSpace (Packet, Len, FALSE);\r
   ASSERT (IcmpErrHdr != NULL);\r
   //\r
   IcmpErrHdr = (IP6_ICMP_ERROR_HEAD *) NetbufAllocSpace (Packet, Len, FALSE);\r
   ASSERT (IcmpErrHdr != NULL);\r
+  if (IcmpErrHdr == NULL) {\r
+    goto EXIT;\r
+  }\r
 \r
   //\r
   // Set the required fields for the icmp port unreachable message.\r
 \r
   //\r
   // Set the required fields for the icmp port unreachable message.\r
@@ -1840,13 +1869,17 @@ Udp6IcmpHandler (
   LIST_ENTRY             *Entry;\r
   UDP6_INSTANCE_DATA     *Instance;\r
 \r
   LIST_ENTRY             *Entry;\r
   UDP6_INSTANCE_DATA     *Instance;\r
 \r
-  if (Packet->TotalSize < sizeof (EFI_UDP_HEADER)) {\r
+  if (Packet->TotalSize < UDP6_HEADER_SIZE) {\r
     NetbufFree (Packet);\r
     return;\r
   }\r
     NetbufFree (Packet);\r
     return;\r
   }\r
-  \r
+\r
   Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
   ASSERT (Udp6Header != NULL);\r
   Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
   ASSERT (Udp6Header != NULL);\r
+  if (Udp6Header == NULL) {\r
+    NetbufFree (Packet);\r
+    return;\r
+  }\r
 \r
   IP6_COPY_ADDRESS (&Udp6Session.SourceAddress, &NetSession->Source);\r
   IP6_COPY_ADDRESS (&Udp6Session.DestinationAddress, &NetSession->Dest);\r
 \r
   IP6_COPY_ADDRESS (&Udp6Session.SourceAddress, &NetSession->Source);\r
   IP6_COPY_ADDRESS (&Udp6Session.DestinationAddress, &NetSession->Dest);\r
@@ -1942,7 +1975,7 @@ Udp6NetVectorExtFree (
   IN VOID  *Context\r
   )\r
 {\r
   IN VOID  *Context\r
   )\r
 {\r
-} \r
+}\r
 \r
 /**\r
   Find the key in the netmap.\r
 \r
 /**\r
   Find the key in the netmap.\r