public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: fanwang2 <fan.wang@intel.com>
To: edk2-devel@lists.01.org
Cc: Wang Fan <fan.wang@intel.com>, Ye Ting <ting.ye@intel.com>,
	Jiaxin Wu <jiaxin.wu@intel.com>, Fu Siyuan <siyuan.fu@intel.com>
Subject: [Patch 1/4] NetworkPkg: Add ASSERT error handling for UDP6 driver
Date: Thu,  4 Jan 2018 11:20:05 +0800	[thread overview]
Message-ID: <1515036008-10700-2-git-send-email-fan.wang@intel.com> (raw)
In-Reply-To: <1515036008-10700-1-git-send-email-fan.wang@intel.com>

From: Wang Fan <fan.wang@intel.com>

In Udp6Dxe, there are several places use ASSERT to check returned
value. But these errors should be handled if they occur, this patch
is to fix this issue.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wang Fan <fan.wang@intel.com>
---
 NetworkPkg/Udp6Dxe/Udp6Impl.c | 16 +++++++++++++++-
 NetworkPkg/Udp6Dxe/Udp6Main.c |  7 ++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/NetworkPkg/Udp6Dxe/Udp6Impl.c b/NetworkPkg/Udp6Dxe/Udp6Impl.c
index edf2c23..25d4e6a 100644
--- a/NetworkPkg/Udp6Dxe/Udp6Impl.c
+++ b/NetworkPkg/Udp6Dxe/Udp6Impl.c
@@ -1,9 +1,9 @@
 /** @file
   Udp6 driver's whole implementation.
 
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2018, 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
   http://opensource.org/licenses/bsd-license.php.
@@ -1606,10 +1606,14 @@ Udp6Demultiplex (
   //
   // Get the datagram header from the packet buffer.
   //
   Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);
   ASSERT (Udp6Header != NULL);
+  if (Udp6Header == NULL) {
+    NetbufFree (Packet);
+    return;
+  }
 
   if (Udp6Header->Checksum != 0) {
     //
     // check the checksum.
     //
@@ -1716,10 +1720,13 @@ Udp6SendPortUnreach (
   //
   // Get the Ipv6 Mode Data.
   //
   Ip6ModeData = AllocateZeroPool (sizeof (EFI_IP6_MODE_DATA));
   ASSERT (Ip6ModeData != NULL);
+  if (Ip6ModeData == NULL) {
+    goto EXIT;
+  }
 
   //
   // If not finding the related IpSender use the default IpIo to send out
   // the port unreachable ICMP message.
   //
@@ -1764,10 +1771,13 @@ Udp6SendPortUnreach (
   //
   // Allocate space for the IP6_ICMP_ERROR_HEAD.
   //
   IcmpErrHdr = (IP6_ICMP_ERROR_HEAD *) NetbufAllocSpace (Packet, Len, FALSE);
   ASSERT (IcmpErrHdr != NULL);
+  if (IcmpErrHdr == NULL) {
+    goto EXIT;
+  }
 
   //
   // Set the required fields for the icmp port unreachable message.
   //
   IcmpErrHdr->Head.Type     = ICMP_V6_DEST_UNREACHABLE;
@@ -1845,10 +1855,14 @@ Udp6IcmpHandler (
     return;
   }
   
   Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);
   ASSERT (Udp6Header != NULL);
+  if (Udp6Header == NULL) {
+    NetbufFree (Packet);
+    return;
+  }
 
   IP6_COPY_ADDRESS (&Udp6Session.SourceAddress, &NetSession->Source);
   IP6_COPY_ADDRESS (&Udp6Session.DestinationAddress, &NetSession->Dest);
 
   Udp6Session.SourcePort      = NTOHS (Udp6Header->DstPort);
diff --git a/NetworkPkg/Udp6Dxe/Udp6Main.c b/NetworkPkg/Udp6Dxe/Udp6Main.c
index f3e9925..9105ef4 100644
--- a/NetworkPkg/Udp6Dxe/Udp6Main.c
+++ b/NetworkPkg/Udp6Dxe/Udp6Main.c
@@ -1,9 +1,9 @@
 /** @file
   Contains all EFI_UDP6_PROTOCOL interfaces.
 
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2018, 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
   http://opensource.org/licenses/bsd-license.php.
@@ -523,10 +523,15 @@ Udp6Transmit (
   Udp6Service                        = Instance->Udp6Service;
   *((UINTN *) &Packet->ProtoData[0]) = (UINTN) (Udp6Service->IpIo);
 
   Udp6Header = (EFI_UDP_HEADER *) NetbufAllocSpace (Packet, UDP6_HEADER_SIZE, TRUE);
   ASSERT (Udp6Header != NULL);
+  if (Udp6Header == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    goto ON_EXIT;
+  }
+  
   ConfigData = &Instance->ConfigData;
 
   //
   // Fill the udp header.
   //
-- 
1.9.5.msysgit.1



  reply	other threads:[~2018-01-04  3:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-04  3:20 [Patch 0/4] Fix some issues in Udp6Dxe fanwang2
2018-01-04  3:20 ` fanwang2 [this message]
2018-01-04  3:20 ` [Patch 2/4] NetworkPkg: Fix a memory leak issue in UDP6 driver fanwang2
2018-01-04  3:20 ` [Patch 3/4] NetworkPkg: Fix some coding style issues " fanwang2
2018-01-04  3:20 ` [Patch 4/4] NetworkPkg: Add more parameter or return status check " fanwang2
2018-01-11  5:37 ` [Patch 0/4] Fix some issues in Udp6Dxe Wu, Jiaxin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1515036008-10700-2-git-send-email-fan.wang@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox