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 BB569222D154D for ; Wed, 3 Jan 2018 19:15:57 -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:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,505,1508828400"; d="scan'208";a="21245843" Received: from fanwang2-hp.ccr.corp.intel.com ([10.239.9.33]) by orsmga001.jf.intel.com with ESMTP; 03 Jan 2018 19:20:29 -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:08 +0800 Message-Id: <1515036008-10700-5-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 4/4] NetworkPkg: Add more parameter or return status check in 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:58 -0000 From: Wang Fan In UDP6Dxe, there are several places that may be enhanced to check input parameters and returned status. This patch is to fix these issues. Cc: Ye Ting Cc: Jiaxin Wu Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wang Fan --- NetworkPkg/Udp6Dxe/Udp6Driver.c | 48 +++++++++++++++++++++++------------------ NetworkPkg/Udp6Dxe/Udp6Impl.c | 17 +++++++++++++++ NetworkPkg/Udp6Dxe/Udp6Main.c | 2 +- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/NetworkPkg/Udp6Dxe/Udp6Driver.c b/NetworkPkg/Udp6Dxe/Udp6Driver.c index 6dde1fc..f9d528e 100644 --- a/NetworkPkg/Udp6Dxe/Udp6Driver.c +++ b/NetworkPkg/Udp6Dxe/Udp6Driver.c @@ -288,22 +288,19 @@ Udp6DriverBindingStop ( Udp6DestroyChildEntryInHandleBuffer, &Context, NULL ); } else if (IsListEmpty (&Udp6Service->ChildrenList)) { - gBS->UninstallMultipleProtocolInterfaces ( - NicHandle, - &gEfiUdp6ServiceBindingProtocolGuid, - &Udp6Service->ServiceBinding, - NULL - ); + Status = gBS->UninstallMultipleProtocolInterfaces ( + NicHandle, + &gEfiUdp6ServiceBindingProtocolGuid, + &Udp6Service->ServiceBinding, + NULL + ); Udp6CleanService (Udp6Service); - FreePool (Udp6Service); - - Status = EFI_SUCCESS; } return Status; } @@ -508,25 +505,34 @@ Udp6ServiceBindingDestroyChild ( Instance->InDestroy = TRUE; // // Close the Ip6 protocol on the default IpIo. // - gBS->CloseProtocol ( - Udp6Service->IpIo->ChildHandle, - &gEfiIp6ProtocolGuid, - gUdp6DriverBinding.DriverBindingHandle, - Instance->ChildHandle - ); + Status = gBS->CloseProtocol ( + Udp6Service->IpIo->ChildHandle, + &gEfiIp6ProtocolGuid, + gUdp6DriverBinding.DriverBindingHandle, + Instance->ChildHandle + ); + if (EFI_ERROR (Status)) { + Instance->InDestroy = FALSE; + return Status; + } + // // Close the Ip6 protocol on this instance's IpInfo. // - gBS->CloseProtocol ( - Instance->IpInfo->ChildHandle, - &gEfiIp6ProtocolGuid, - gUdp6DriverBinding.DriverBindingHandle, - Instance->ChildHandle - ); + Status = gBS->CloseProtocol ( + Instance->IpInfo->ChildHandle, + &gEfiIp6ProtocolGuid, + gUdp6DriverBinding.DriverBindingHandle, + Instance->ChildHandle + ); + if (EFI_ERROR (Status)) { + Instance->InDestroy = FALSE; + return Status; + } // // Uninstall the Udp6Protocol previously installed on the ChildHandle. // Status = gBS->UninstallMultipleProtocolInterfaces ( diff --git a/NetworkPkg/Udp6Dxe/Udp6Impl.c b/NetworkPkg/Udp6Dxe/Udp6Impl.c index 458470c..d014e2d 100644 --- a/NetworkPkg/Udp6Dxe/Udp6Impl.c +++ b/NetworkPkg/Udp6Dxe/Udp6Impl.c @@ -55,10 +55,13 @@ Udp6FindInstanceByPort ( /** This function is the packet transmitting notify function registered to the IpIo interface. It's called to signal the udp TxToken when the IpIo layer completes transmitting of the udp datagram. + If Context is NULL, then ASSERT(). + If NotifyData is NULL, then ASSERT(). + @param[in] Status The completion status of the output udp datagram. @param[in] Context Pointer to the context data. @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending. @param[in] NotifyData Pointer to the notify data. @@ -73,10 +76,14 @@ Udp6DgramSent ( ); /** This function processes the received datagram passed up by the IpIo layer. + If NetSession is NULL, then ASSERT(). + If Packet is NULL, then ASSERT(). + If Context is NULL, then ASSERT(). + @param[in] Status The status of this udp datagram. @param[in] IcmpError The IcmpError code, only available when Status is EFI_ICMP_ERROR. @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA. @param[in] Packet Pointer to the NET_BUF containing the received udp @@ -975,10 +982,13 @@ Udp6RemoveToken ( /** This function is the packet transmitting notify function registered to the IpIo interface. It's called to signal the udp TxToken when IpIo layer completes the transmitting of the udp datagram. + If Context is NULL, then ASSERT(). + If NotifyData is NULL, then ASSERT(). + @param[in] Status The completion status of the output udp datagram. @param[in] Context Pointer to the context data. @param[in] Sender Specify a EFI_IP6_PROTOCOL for sending. @param[in] NotifyData Pointer to the notify data. @@ -993,10 +1003,12 @@ Udp6DgramSent ( ) { UDP6_INSTANCE_DATA *Instance; EFI_UDP6_COMPLETION_TOKEN *Token; + ASSERT (Context != NULL && NotifyData != NULL); + Instance = (UDP6_INSTANCE_DATA *) Context; Token = (EFI_UDP6_COMPLETION_TOKEN *) NotifyData; if (Udp6RemoveToken (&Instance->TxTokens, Token) == EFI_SUCCESS) { // @@ -1010,10 +1022,14 @@ Udp6DgramSent ( /** This function processes the received datagram passed up by the IpIo layer. + If NetSession is NULL, then ASSERT(). + If Packet is NULL, then ASSERT(). + If Context is NULL, then ASSERT(). + @param[in] Status The status of this udp datagram. @param[in] IcmpError The IcmpError code, only available when Status is EFI_ICMP_ERROR. @param[in] NetSession Pointer to the EFI_NET_SESSION_DATA. @param[in] Packet Pointer to the NET_BUF containing the received udp @@ -1029,10 +1045,11 @@ Udp6DgramRcvd ( IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Packet, IN VOID *Context ) { + ASSERT (NetSession != NULL && Packet != NULL && Context != NULL); NET_CHECK_SIGNATURE (Packet, NET_BUF_SIGNATURE); // // IpIo only passes received packets with Status EFI_SUCCESS or EFI_ICMP_ERROR. // diff --git a/NetworkPkg/Udp6Dxe/Udp6Main.c b/NetworkPkg/Udp6Dxe/Udp6Main.c index 53145c3..1d7f0ac 100644 --- a/NetworkPkg/Udp6Dxe/Udp6Main.c +++ b/NetworkPkg/Udp6Dxe/Udp6Main.c @@ -379,11 +379,11 @@ Udp6Groups ( if (JoinFlag) { Status = NetMapInsertTail (&Instance->McastIps, (VOID *) McastIp, NULL); } else { - NetMapIterate (&Instance->McastIps, Udp6LeaveGroup, MulticastAddress); + Status = NetMapIterate (&Instance->McastIps, Udp6LeaveGroup, MulticastAddress); } ON_EXIT: gBS->RestoreTPL (OldTpl); -- 1.9.5.msysgit.1