]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelFrameworkModulePkg/DebugLib: Fix string copy issue
authorGao, Zhichao <zhichao.gao@intel.com>
Tue, 21 May 2019 07:49:52 +0000 (15:49 +0800)
committerLiming Gao <liming.gao@intel.com>
Wed, 22 May 2019 01:59:30 +0000 (09:59 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1826

There is a bug to use AsciiStrCpyS to copy a truncated
string. If would cause an assert because the truncated
length is always less than the source string length. It
should use the AsciiStrnCpyS instead.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c

index e92601f89ee01b294b95d6743546f39f82061794..1840b6d68313399fd2da301cbefdae2059c25863 100644 (file)
@@ -150,7 +150,7 @@ DebugPrintMarker (
   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
   // According to the content structure of Buffer shown above, the size of\r
   // the FormatString buffer is the size of Buffer minus the Padding\r
@@ -158,7 +158,7 @@ DebugPrintMarker (
   // variable arguments (12 * sizeof (UINT64)).\r
   //\r
   DestBufferSize = sizeof (Buffer) - 4 - sizeof (EFI_DEBUG_INFO) - 12 * sizeof (UINT64);\r
-  AsciiStrCpyS (FormatString, DestBufferSize / sizeof (CHAR8), Format);\r
+  AsciiStrnCpyS (FormatString, DestBufferSize / sizeof (CHAR8), Format, DestBufferSize / sizeof (CHAR8) - 1);\r
 \r
   //\r
   // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r