From: Wang Fan Date: Wed, 3 Jan 2018 09:30:54 +0000 (+0800) Subject: NetworkPkg: Add ASSERT error handling for UDP6 driver X-Git-Tag: edk2-stable201903~2631 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=2c4a45b3619303112d46df0d5a606842ad32d011 NetworkPkg: Add ASSERT error handling for UDP6 driver 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 Reviewed-by: Jiaxin Wu --- diff --git a/NetworkPkg/Udp6Dxe/Udp6Impl.c b/NetworkPkg/Udp6Dxe/Udp6Impl.c index edf2c23976..25d4e6a80f 100644 --- a/NetworkPkg/Udp6Dxe/Udp6Impl.c +++ b/NetworkPkg/Udp6Dxe/Udp6Impl.c @@ -1,7 +1,7 @@ /** @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 @@ -1608,6 +1608,10 @@ Udp6Demultiplex ( // Udp6Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL); ASSERT (Udp6Header != NULL); + if (Udp6Header == NULL) { + NetbufFree (Packet); + return; + } if (Udp6Header->Checksum != 0) { // @@ -1718,6 +1722,9 @@ Udp6SendPortUnreach ( // 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 @@ -1766,6 +1773,9 @@ Udp6SendPortUnreach ( // 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. @@ -1847,6 +1857,10 @@ Udp6IcmpHandler ( 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); diff --git a/NetworkPkg/Udp6Dxe/Udp6Main.c b/NetworkPkg/Udp6Dxe/Udp6Main.c index f3e99255f9..9105ef453f 100644 --- a/NetworkPkg/Udp6Dxe/Udp6Main.c +++ b/NetworkPkg/Udp6Dxe/Udp6Main.c @@ -1,7 +1,7 @@ /** @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 @@ -525,6 +525,11 @@ Udp6Transmit ( 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; //