]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
Update PeiDxeDebugDebugLibReportStatusCode to use CopyMem() in place of AsciiStrnCpy...
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / PeiDxeDebugLibReportStatusCode / DebugLib.c
index e4ca5b5539f267acc58559cee031379c4e06be6f..7f7a98cbefa8154b4332b3cda96f329a587f84ac 100644 (file)
@@ -4,7 +4,7 @@
   Note that if the debug message length is larger than the maximum allowable\r
   record length, then the debug message will be ignored directly.\r
 \r
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2012, 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
@@ -207,6 +207,7 @@ DebugPrint (
     // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then return\r
     //\r
     if ((CHAR8 *)BaseListMarker > FormatString) {\r
+      VA_END (VaListMarker);\r
       return;\r
     }\r
   }\r
@@ -257,44 +258,71 @@ DebugAssert (
 {\r
   UINT64                 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof(UINT64)];\r
   EFI_DEBUG_ASSERT_DATA  *AssertData;\r
+  UINTN                  HeaderSize;\r
   UINTN                  TotalSize;\r
   CHAR8                  *Temp;\r
   UINTN                  FileNameSize;\r
   UINTN                  DescriptionSize;\r
 \r
   //\r
-  // Make sure it will all fit in the passed in buffer\r
+  // Get string size\r
   //\r
-  FileNameSize    = AsciiStrSize (FileName);\r
-  DescriptionSize = AsciiStrSize (Description);\r
-  TotalSize = sizeof (EFI_DEBUG_ASSERT_DATA) + FileNameSize + DescriptionSize;\r
-  if (TotalSize <= sizeof (Buffer)) {\r
-    //\r
-    // Fill in EFI_DEBUG_ASSERT_DATA\r
-    //\r
-    AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer;\r
-    AssertData->LineNumber = (UINT32)LineNumber;\r
-\r
-    //\r
-    // Copy Ascii FileName including NULL.\r
-    //\r
-    Temp = AsciiStrCpy ((CHAR8 *)(AssertData + 1), FileName);\r
+  HeaderSize       = sizeof (EFI_DEBUG_ASSERT_DATA);\r
+  FileNameSize     = AsciiStrSize (FileName);\r
+  DescriptionSize  = AsciiStrSize (Description);\r
 \r
+  //\r
+  // Make sure it will all fit in the passed in buffer.\r
+  //\r
+  if (HeaderSize + FileNameSize + DescriptionSize > sizeof (Buffer)) {\r
     //\r
-    // Copy Ascii Description\r
+    // FileName + Description is too long to be filled into buffer. \r
     //\r
-    AsciiStrCpy (Temp + FileNameSize, Description);\r
-\r
-    REPORT_STATUS_CODE_EX (\r
-      (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),\r
-      (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),\r
-      0,\r
-      NULL,\r
-      NULL,\r
-      AssertData,\r
-      TotalSize\r
-      );\r
+    if (HeaderSize + FileNameSize < sizeof (Buffer)) {\r
+      //\r
+      // Description has enough buffer to be truncated. \r
+      //\r
+      DescriptionSize = sizeof (Buffer) - HeaderSize - FileNameSize;\r
+    } else {\r
+      //\r
+      // FileName is too long to be filled into buffer.\r
+      // FileName will be truncated. Reserved one byte for Description NULL terminator.\r
+      //\r
+      DescriptionSize = 1;\r
+      FileNameSize    = sizeof (Buffer) - HeaderSize - DescriptionSize;\r
+    }\r
   }\r
\r
+  //\r
+  // Fill in EFI_DEBUG_ASSERT_DATA\r
+  //\r
+  AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer;\r
+  AssertData->LineNumber = (UINT32)LineNumber;\r
+  TotalSize  = sizeof (EFI_DEBUG_ASSERT_DATA);\r
+\r
+  //\r
+  // Copy Ascii FileName including NULL terminator.\r
+  //\r
+  Temp = CopyMem (AssertData + 1, FileName, FileNameSize);\r
+  Temp[FileNameSize - 1] = 0;\r
+  TotalSize += FileNameSize;\r
+\r
+  //\r
+  // Copy Ascii Description include NULL terminator.\r
+  //\r
+  Temp = CopyMem (Temp + FileNameSize, Description, DescriptionSize);\r
+  Temp[DescriptionSize - 1] = 0;\r
+  TotalSize += DescriptionSize;\r
+\r
+  REPORT_STATUS_CODE_EX (\r
+    (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),\r
+    (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),\r
+    0,\r
+    NULL,\r
+    NULL,\r
+    AssertData,\r
+    TotalSize\r
+    );\r
 \r
   //\r
   // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r