From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=fan.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CFFC422280C5B for ; Wed, 3 Jan 2018 19:15:51 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jan 2018 19:20:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,505,1508828400"; d="scan'208";a="21245822" Received: from fanwang2-hp.ccr.corp.intel.com ([10.239.9.33]) by orsmga001.jf.intel.com with ESMTP; 03 Jan 2018 19:20:22 -0800 From: fanwang2 To: edk2-devel@lists.01.org Cc: Wang Fan , Ye Ting , Jiaxin Wu , Fu Siyuan Date: Thu, 4 Jan 2018 11:20:05 +0800 Message-Id: <1515036008-10700-2-git-send-email-fan.wang@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1515036008-10700-1-git-send-email-fan.wang@intel.com> References: <1515036008-10700-1-git-send-email-fan.wang@intel.com> Subject: [Patch 1/4] NetworkPkg: Add ASSERT error handling for UDP6 driver X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Jan 2018 03:15:52 -0000 From: Wang Fan 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 Cc: Jiaxin Wu Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wang Fan --- 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.
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
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.
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
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