summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2012-11-05 03:34:52 +0000
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2012-11-05 03:34:52 +0000
commit1abf695f86af42c2ed1852cb51498bc241162f85 (patch)
tree9a508b985e857e680f463a496251fd8d93feefe8
parent7f3b78220a046fb9e412e1bec3dd240bfaccb65d (diff)
downloadedk2-1abf695f86af42c2ed1852cb51498bc241162f85.tar.gz
Sync patches r13852, r13856, r13903 and r13907 from main trunk.
Fix code potential errors and add more check to make code more safely. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/branches/UDK2010.SR1@13928 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.c1
-rw-r--r--MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c8
-rw-r--r--MdeModulePkg/Core/Dxe/Gcd/Gcd.c4
-rw-r--r--MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Icmp.c1
-rw-r--r--MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c6
-rw-r--r--MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c14
-rw-r--r--MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c2
-rw-r--r--MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c1
-rw-r--r--MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c2
-rw-r--r--NetworkPkg/IpSecDxe/IpSecDebug.c14
-rw-r--r--NetworkPkg/IpSecDxe/IpSecDebug.h2
11 files changed, 38 insertions, 17 deletions
diff --git a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.c b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.c
index 46e8de7158..11e90f97a9 100644
--- a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.c
+++ b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.c
@@ -473,6 +473,7 @@ UnregisterAtaDevice (
if (BlockIo != NULL) {
AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (BlockIo);
} else {
+ ASSERT (BlockIo2 != NULL);
AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (BlockIo2);
}
diff --git a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
index 0dda992ff5..5e5cab6575 100644
--- a/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
+++ b/MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c
@@ -133,6 +133,10 @@ AtaDevicePassThru (
if (TaskPacket != NULL) {
Packet = TaskPacket;
Packet->Asb = AllocateAlignedBuffer (AtaDevice, sizeof (EFI_ATA_STATUS_BLOCK));
+ if (Packet->Asb == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
CopyMem (Packet->Asb, AtaDevice->Asb, sizeof (EFI_ATA_STATUS_BLOCK));
Packet->Acb = AllocateCopyPool (sizeof (EFI_ATA_COMMAND_BLOCK), &AtaDevice->Acb);
} else {
@@ -948,6 +952,10 @@ TrustTransferAtaDevice (
AtaPassThru = AtaDevice->AtaBusDriverData->AtaPassThru;
if ((AtaPassThru->Mode->IoAlign > 1) && !IS_ALIGNED (Buffer, AtaPassThru->Mode->IoAlign)) {
NewBuffer = AllocateAlignedBuffer (AtaDevice, TransferLength);
+ if (NewBuffer == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
CopyMem (NewBuffer, Buffer, TransferLength);
FreePool (Buffer);
Buffer = NewBuffer;
diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c
index 49697ae89c..2b32bd68d2 100644
--- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c
+++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c
@@ -148,7 +148,7 @@ CoreDumpGcdMemorySpaceMap (
UINTN Index;
Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
- ASSERT_EFI_ERROR (Status);
+ ASSERT (Status == EFI_SUCCESS && MemorySpaceMap != NULL);
if (InitialMap) {
DEBUG ((DEBUG_GCD, "GCD:Initial GCD Memory Space Map\n"));
@@ -190,7 +190,7 @@ CoreDumpGcdIoSpaceMap (
UINTN Index;
Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap);
- ASSERT_EFI_ERROR (Status);
+ ASSERT (Status == EFI_SUCCESS && IoSpaceMap != NULL);
if (InitialMap) {
DEBUG ((DEBUG_GCD, "GCD:Initial GCD I/O Space Map\n"));
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 0990d18035..66b1d1c8e1 100644
--- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c
+++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c
@@ -1,7 +1,7 @@
/** @file
IP4 input process.
-Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
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
@@ -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..df79c85fa0 100644
--- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c
+++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c
@@ -443,7 +443,7 @@ Mtftp4SendPacket (
UDP_END_POINT UdpPoint;
EFI_STATUS Status;
UINT16 OpCode;
- UINT16 Value;
+ UINT8 *Buffer;
//
// Save the packet for retransmission
@@ -464,8 +464,9 @@ Mtftp4SendPacket (
// Send the requests to the listening port, other packets
// to the connected port
//
- Value = *((UINT16 *) NetbufGetByte (Packet, 0, NULL));
- OpCode = NTOHS (Value);
+ Buffer = NetbufGetByte (Packet, 0, NULL);
+ ASSERT (Buffer != NULL);
+ OpCode = NTOHS (*(UINT16 *)Buffer);
if ((OpCode == EFI_MTFTP4_OPCODE_RRQ) ||
(OpCode == EFI_MTFTP4_OPCODE_DIR) ||
@@ -511,7 +512,7 @@ Mtftp4Retransmit (
UDP_END_POINT UdpPoint;
EFI_STATUS Status;
UINT16 OpCode;
- UINT16 Value;
+ UINT8 *Buffer;
ASSERT (Instance->LastPacket != NULL);
@@ -521,8 +522,9 @@ Mtftp4Retransmit (
//
// Set the requests to the listening port, other packets to the connected port
//
- Value = *(UINT16 *) NetbufGetByte (Instance->LastPacket, 0, NULL);
- OpCode = NTOHS (Value);
+ Buffer = NetbufGetByte (Instance->LastPacket, 0, NULL);
+ ASSERT (Buffer != NULL);
+ OpCode = NTOHS (*(UINT16 *) Buffer);
if ((OpCode == EFI_MTFTP4_OPCODE_RRQ) || (OpCode == EFI_MTFTP4_OPCODE_DIR) ||
(OpCode == EFI_MTFTP4_OPCODE_WRQ)) {
diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c
index f8dcc365e3..c7a376f2f2 100644
--- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c
+++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Input.c
@@ -711,6 +711,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) ||
@@ -1423,6 +1424,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));
diff --git a/NetworkPkg/IpSecDxe/IpSecDebug.c b/NetworkPkg/IpSecDxe/IpSecDebug.c
index 56b35a1a14..636e775969 100644
--- a/NetworkPkg/IpSecDxe/IpSecDebug.c
+++ b/NetworkPkg/IpSecDxe/IpSecDebug.c
@@ -19,7 +19,7 @@
//
// The print title for IKEv1 variety phase.
//
-CHAR8 *mIkev1StateStr[] = {
+CHAR8 *mIkev1StateStr[IKE_STATE_NUM] = {
"IKEv1_MAIN_1",
"IKEv1_MAIN_2",
"IKEv1_MAIN_3",
@@ -32,7 +32,7 @@ CHAR8 *mIkev1StateStr[] = {
//
// The print title for IKEv2 variety phase.
//
-CHAR8 *mIkev2StateStr[] = {
+CHAR8 *mIkev2StateStr[IKE_STATE_NUM] = {
"IKEv2_STATE_INIT",
"IKEv2_STATE_AUTH",
"IKEv2_STATE_SA_ESTABLISH",
@@ -166,23 +166,23 @@ IkeDumpState (
IN UINT8 IkeVersion
)
{
+ if (Previous >= IKE_STATE_NUM || Current >= IKE_STATE_NUM) {
+ return;
+ }
if (Previous == Current) {
if (IkeVersion == 1) {
DEBUG ((DEBUG_INFO, "\n****Current state is %a\n", mIkev1StateStr[Previous]));
} else if (IkeVersion == 2) {
DEBUG ((DEBUG_INFO, "\n****Current state is %a\n", mIkev2StateStr[Previous]));
- }
-
+ }
} else {
if (IkeVersion == 1) {
DEBUG ((DEBUG_INFO, "\n****Change state from %a to %a\n", mIkev1StateStr[Previous], mIkev1StateStr[Current]));
} else {
DEBUG ((DEBUG_INFO, "\n****Change state from %a to %a\n", mIkev2StateStr[Previous], mIkev2StateStr[Current]));
- }
-
+ }
}
-
}
/**
diff --git a/NetworkPkg/IpSecDxe/IpSecDebug.h b/NetworkPkg/IpSecDxe/IpSecDebug.h
index d44677f300..16bbcd53c6 100644
--- a/NetworkPkg/IpSecDxe/IpSecDebug.h
+++ b/NetworkPkg/IpSecDxe/IpSecDebug.h
@@ -27,6 +27,8 @@
#define IPSEC_DUMP_BUF(Title, Data, DataSize) IpSecDumpBuf (Title, Data, DataSize)
#define IPSEC_DEBUG_BYTE_PER_LINE 8
+#define IKE_STATE_NUM 7
+
/**