]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
Fix the potential address overflow issue when checking PE signature.
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / DebugAgentCommon / DebugAgent.c
index 91b29af82a001554f64279d90b7d9ef604803d6f..f3da983946d6b66c6b6b849af387149b5ecf15d0 100644 (file)
@@ -4,7 +4,7 @@
   read/write debug packet to communication with HOST based on transfer\r
   protocol.\r
 \r
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -19,7 +19,7 @@
 #include "Ia32/DebugException.h"\r
 \r
 CHAR8 mErrorMsgVersionAlert[]       = "\rThe SourceLevelDebugPkg you are using requires a newer version of the Intel(R) UDK Debugger Tool.\r\n";\r
-CHAR8 mErrorMsgSendInitPacket[]     = "\rSend INIT break packet and try to connect the HOST (Intel(R) UDK Debugger Tool v1.3.1) ...\r\n";\r
+CHAR8 mErrorMsgSendInitPacket[]     = "\rSend INIT break packet and try to connect the HOST (Intel(R) UDK Debugger Tool v1.4) ...\r\n";\r
 CHAR8 mErrorMsgConnectOK[]          = "HOST connection is successful!\r\n";\r
 CHAR8 mErrorMsgConnectFail[]        = "HOST connection is failed!\r\n";\r
 CHAR8 mWarningMsgIngoreBreakpoint[] = "Ignore break point in SMM for SMI issued during DXE debugging!\r\n";\r
@@ -214,10 +214,12 @@ FindAndReportModuleImageInfo (
     if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
       //\r
       // DOS image header is present, so read the PE header after the DOS image header.\r
-      // Check if address overflow firstly.\r
       //\r
-      if ((MAX_ADDRESS - (UINTN)DosHdr->e_lfanew) > Pe32Data) {\r
-        Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data + (UINTN)(DosHdr->e_lfanew));\r
+      Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
+      //\r
+      // Make sure PE header address does not overflow and is less than the initial address.\r
+      //\r
+      if (((UINTN)Hdr.Pe32 > Pe32Data) && ((UINTN)Hdr.Pe32 < (UINTN)mErrorMsgVersionAlert)) {\r
         if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
           //\r
           // It's PE image.\r
@@ -374,7 +376,6 @@ UpdateMailboxContent (
     Mailbox->SequenceNo = (UINT8) Value;\r
     break;\r
   case DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX:\r
-    DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Update HostSequenceNo to %x\n", Value);\r
     Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->HostSequenceNo, sizeof(UINT8))\r
                                               - CalculateSum8 ((UINT8 *)&Value, sizeof(UINT8));\r
     Mailbox->HostSequenceNo = (UINT8) Value;\r
@@ -588,7 +589,7 @@ ReadRemainingBreakPacket (
   //\r
   // Has received start symbol, try to read the rest part\r
   //\r
-  if (DebugPortReadBuffer (Handle, &DebugHeader->Command, sizeof (DEBUG_PACKET_HEADER) - 1, READ_PACKET_TIMEOUT) == 0) {\r
+  if (DebugPortReadBuffer (Handle, (UINT8 *)DebugHeader + OFFSET_OF (DEBUG_PACKET_HEADER, Command), sizeof (DEBUG_PACKET_HEADER) - OFFSET_OF (DEBUG_PACKET_HEADER, Command), READ_PACKET_TIMEOUT) == 0) {\r
     //\r
     // Timeout occur, exit\r
     //\r
@@ -604,7 +605,7 @@ ReadRemainingBreakPacket (
     return EFI_CRC_ERROR;\r
   }\r
   Mailbox = GetMailboxPointer();\r
-  if (((DebugHeader->Command & DEBUG_COMMAND_RESPONSE) != 0) &&\r
+  if (((DebugHeader->Command & DEBUG_COMMAND_RESPONSE) == 0) &&\r
        (DebugHeader->SequenceNo == (UINT8) (Mailbox->HostSequenceNo + 1))) {\r
     //\r
     // Only updagte HostSequenceNo for new command packet \r
@@ -1015,7 +1016,7 @@ ReceivePacket (
     //\r
     Received = DebugPortReadBuffer (\r
                  Handle,\r
-                 &DebugHeader->Command,\r
+                 (UINT8 *)DebugHeader + OFFSET_OF (DEBUG_PACKET_HEADER, Command),\r
                  OFFSET_OF (DEBUG_PACKET_HEADER, Length) + sizeof (DebugHeader->Length) - sizeof (DebugHeader->StartSymbol),\r
                  Timeout\r
                  );\r
@@ -2105,6 +2106,7 @@ InterruptProcess (
   UINT32                           IssuedViewPoint;\r
   DEBUG_AGENT_EXCEPTION_BUFFER     *ExceptionBuffer;\r
 \r
+  InputCharacter  = 0;\r
   ProcessorIndex  = 0;\r
   IssuedViewPoint = 0;\r
   BreakReceived   = FALSE;\r