Add more check to make code more safely.

Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ouyang Qian  <ouyang.qian@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13903 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
ydong10
2012-11-01 02:10:31 +00:00
parent 0d5df2aba7
commit a56b6e03e2
6 changed files with 11 additions and 1 deletions

View File

@ -240,6 +240,7 @@ Ip4IcmpReplyEcho (
// update is omitted. // update is omitted.
// //
Icmp = (IP4_ICMP_QUERY_HEAD *) NetbufGetByte (Data, 0, NULL); Icmp = (IP4_ICMP_QUERY_HEAD *) NetbufGetByte (Data, 0, NULL);
ASSERT (Icmp != NULL);
Icmp->Head.Type = ICMP_ECHO_REPLY; Icmp->Head.Type = ICMP_ECHO_REPLY;
Icmp->Head.Checksum = 0; Icmp->Head.Checksum = 0;
Icmp->Head.Checksum = (UINT16) (~NetblockChecksum ((UINT8 *) Icmp, Data->TotalSize)); Icmp->Head.Checksum = (UINT16) (~NetblockChecksum ((UINT8 *) Icmp, Data->TotalSize));

View File

@ -850,6 +850,7 @@ Ip4AccpetFrame (
} }
Head = (IP4_HEAD *) NetbufGetByte (Packet, 0, NULL); Head = (IP4_HEAD *) NetbufGetByte (Packet, 0, NULL);
ASSERT (Head != NULL);
OptionLen = (Head->HeadLen << 2) - IP4_MIN_HEADLEN; OptionLen = (Head->HeadLen << 2) - IP4_MIN_HEADLEN;
if (OptionLen > 0) { if (OptionLen > 0) {
Option = (UINT8 *) (Head + 1); Option = (UINT8 *) (Head + 1);
@ -899,6 +900,7 @@ Ip4AccpetFrame (
// is transfered to the packet process logic. // is transfered to the packet process logic.
// //
Head = (IP4_HEAD *) NetbufGetByte (Packet, 0, NULL); Head = (IP4_HEAD *) NetbufGetByte (Packet, 0, NULL);
ASSERT (Head != NULL);
Status = Ip4PreProcessPacket ( Status = Ip4PreProcessPacket (
IpSb, IpSb,
&Packet, &Packet,

View File

@ -465,6 +465,7 @@ Mtftp4SendPacket (
// to the connected port // to the connected port
// //
Value = *((UINT16 *) NetbufGetByte (Packet, 0, NULL)); Value = *((UINT16 *) NetbufGetByte (Packet, 0, NULL));
ASSERT (Value != NULL);
OpCode = NTOHS (Value); OpCode = NTOHS (Value);
if ((OpCode == EFI_MTFTP4_OPCODE_RRQ) || if ((OpCode == EFI_MTFTP4_OPCODE_RRQ) ||
@ -522,6 +523,7 @@ Mtftp4Retransmit (
// Set the requests to the listening port, other packets to the connected port // Set the requests to the listening port, other packets to the connected port
// //
Value = *(UINT16 *) NetbufGetByte (Instance->LastPacket, 0, NULL); Value = *(UINT16 *) NetbufGetByte (Instance->LastPacket, 0, NULL);
ASSERT (Value != NULL);
OpCode = NTOHS (Value); OpCode = NTOHS (Value);
if ((OpCode == EFI_MTFTP4_OPCODE_RRQ) || (OpCode == EFI_MTFTP4_OPCODE_DIR) || if ((OpCode == EFI_MTFTP4_OPCODE_RRQ) || (OpCode == EFI_MTFTP4_OPCODE_DIR) ||

View File

@ -710,6 +710,7 @@ TcpInput (
Tcb = NULL; Tcb = NULL;
Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL); Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL);
ASSERT (Head != NULL);
Len = Nbuf->TotalSize - (Head->HeadLen << 2); Len = Nbuf->TotalSize - (Head->HeadLen << 2);
if ((Head->HeadLen < 5) || (Len < 0) || if ((Head->HeadLen < 5) || (Len < 0) ||
@ -1422,6 +1423,7 @@ TcpIcmpInput (
BOOLEAN IcmpErrNotify; BOOLEAN IcmpErrNotify;
Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL); Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL);
ASSERT (Head != NULL);
Tcb = TcpLocateTcb ( Tcb = TcpLocateTcb (
Head->DstPort, Head->DstPort,
Dst, Dst,

View File

@ -592,6 +592,7 @@ TcpFormatNetbuf (
Seg = TCPSEG_NETBUF (Nbuf); Seg = TCPSEG_NETBUF (Nbuf);
Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL); Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL);
ASSERT (Head != NULL);
Nbuf->Tcp = Head; Nbuf->Tcp = Head;
Seg->Seq = NTOHL (Head->Seq); Seg->Seq = NTOHL (Head->Seq);

View File

@ -1612,6 +1612,7 @@ Udp4Demultiplex (
// Get the datagram header from the packet buffer. // Get the datagram header from the packet buffer.
// //
Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL); Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);
ASSERT (Udp4Header != NULL);
if (Udp4Header->Checksum != 0) { if (Udp4Header->Checksum != 0) {
// //
@ -1799,6 +1800,7 @@ Udp4IcmpHandler (
UDP4_INSTANCE_DATA *Instance; UDP4_INSTANCE_DATA *Instance;
Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL); Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);
ASSERT (Udp4Header != NULL);
CopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS));
CopyMem (&Udp4Session.DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS)); CopyMem (&Udp4Session.DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));