]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/DebugLib: Print partial when format string is too long
authorRuiyu Ni <ruiyu.ni@intel.com>
Thu, 11 Jan 2018 03:35:16 +0000 (11:35 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Mon, 15 Jan 2018 10:03:37 +0000 (18:03 +0800)
Today's implementation prints nothing when the format string cannot
fit in the report status extended data buffer.
It confuses user.
The patch changes to print partial message by truncating the format
string when it's too long.

The missing enhancement is the extended data buffer only reserves 96
bytes for the var-args. When the format string is not very long but
contains 13 %lx or %p, the var-args buffer is too small. Today's
implementation prints nothing for this case.
This patch doesn't change such behavior.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c

index 163d530ae5ae210a468c708b9b9d2c405f8cc478..16a1d206fb7f2d5936e02d572fc978d207e57f3b 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 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2018, 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
@@ -96,7 +96,7 @@ DebugPrint (
   // If the TotalSize is larger than the maximum record size, then return\r
   //\r
   if (TotalSize > sizeof (Buffer)) {\r
-    return;\r
+    TotalSize = sizeof (Buffer);\r
   }\r
 \r
   //\r
@@ -113,9 +113,12 @@ DebugPrint (
   FormatString          = (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12);\r
 \r
   //\r
-  // Copy the Format string into the record\r
+  // Copy the Format string into the record. It will be truncated if it's too long.\r
   //\r
-  AsciiStrCpyS (FormatString, sizeof(Buffer) - (4 + sizeof(EFI_DEBUG_INFO) + 12 * sizeof(UINT64)), Format);\r
+  AsciiStrnCpyS (\r
+    FormatString, sizeof(Buffer) - (4 + sizeof(EFI_DEBUG_INFO) + 12 * sizeof(UINT64)),\r
+    Format,       sizeof(Buffer) - (4 + sizeof(EFI_DEBUG_INFO) + 12 * sizeof(UINT64)) - 1\r
+    );\r
 \r
   //\r
   // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r