From a56b6e03e22c4023fdf5b026b0fcb096d6a0f677 Mon Sep 17 00:00:00 2001 From: ydong10 Date: Thu, 1 Nov 2012 02:10:31 +0000 Subject: [PATCH] Add more check to make code more safely. Signed-off-by: Eric Dong Reviewed-by: Ouyang Qian git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13903 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c | 1 + MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c | 4 +++- MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c | 2 ++ MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c | 2 ++ MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c | 1 + MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c | 2 ++ 6 files changed, 11 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c index a4d09abd74..18cb9ff360 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c @@ -240,6 +240,7 @@ Ip4IcmpReplyEcho ( // update is omitted. // Icmp = (IP4_ICMP_QUERY_HEAD *) NetbufGetByte (Data, 0, NULL); + ASSERT (Icmp != NULL); Icmp->Head.Type = ICMP_ECHO_REPLY; Icmp->Head.Checksum = 0; Icmp->Head.Checksum = (UINT16) (~NetblockChecksum ((UINT8 *) Icmp, Data->TotalSize)); diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c index bd15fc2e17..d985b1aeb6 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c @@ -849,7 +849,8 @@ Ip4AccpetFrame ( goto DROP; } - Head = (IP4_HEAD *) NetbufGetByte (Packet, 0, NULL); + Head = (IP4_HEAD *) NetbufGetByte (Packet, 0, NULL); + ASSERT (Head != NULL); OptionLen = (Head->HeadLen << 2) - IP4_MIN_HEADLEN; if (OptionLen > 0) { Option = (UINT8 *) (Head + 1); @@ -899,6 +900,7 @@ Ip4AccpetFrame ( // is transfered to the packet process logic. // Head = (IP4_HEAD *) NetbufGetByte (Packet, 0, NULL); + ASSERT (Head != NULL); Status = Ip4PreProcessPacket ( IpSb, &Packet, diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c index 26860e52bb..90207a2a9d 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c @@ -465,6 +465,7 @@ Mtftp4SendPacket ( // to the connected port // Value = *((UINT16 *) NetbufGetByte (Packet, 0, NULL)); + ASSERT (Value != NULL); OpCode = NTOHS (Value); if ((OpCode == EFI_MTFTP4_OPCODE_RRQ) || @@ -522,6 +523,7 @@ Mtftp4Retransmit ( // Set the requests to the listening port, other packets to the connected port // Value = *(UINT16 *) NetbufGetByte (Instance->LastPacket, 0, NULL); + ASSERT (Value != NULL); OpCode = NTOHS (Value); if ((OpCode == EFI_MTFTP4_OPCODE_RRQ) || (OpCode == EFI_MTFTP4_OPCODE_DIR) || diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c index 806ae295e1..2e87b3fc7a 100644 --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c +++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c @@ -710,6 +710,7 @@ TcpInput ( Tcb = NULL; Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL); + ASSERT (Head != NULL); Len = Nbuf->TotalSize - (Head->HeadLen << 2); if ((Head->HeadLen < 5) || (Len < 0) || @@ -1422,6 +1423,7 @@ TcpIcmpInput ( BOOLEAN IcmpErrNotify; Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL); + ASSERT (Head != NULL); Tcb = TcpLocateTcb ( Head->DstPort, Dst, diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c index b3591aa7df..bf04b5a55b 100644 --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c +++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c @@ -592,6 +592,7 @@ TcpFormatNetbuf ( Seg = TCPSEG_NETBUF (Nbuf); Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL); + ASSERT (Head != NULL); Nbuf->Tcp = Head; Seg->Seq = NTOHL (Head->Seq); diff --git a/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c b/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c index ffcbfed2c5..9326f3d344 100644 --- a/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c +++ b/MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c @@ -1612,6 +1612,7 @@ Udp4Demultiplex ( // Get the datagram header from the packet buffer. // Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL); + ASSERT (Udp4Header != NULL); if (Udp4Header->Checksum != 0) { // @@ -1799,6 +1800,7 @@ Udp4IcmpHandler ( UDP4_INSTANCE_DATA *Instance; Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL); + ASSERT (Udp4Header != NULL); CopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&Udp4Session.DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS)); -- 2.39.5