summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGao, Zhichao <zhichao.gao@intel.com>2019-05-21 15:49:52 +0800
committerLiming Gao <liming.gao@intel.com>2019-05-22 09:59:30 +0800
commit3604174718e2afc950c3cc64c64ba5165c8692bd (patch)
treee8f41cb83a099abe1768431bbee5349fcc03a8be
parent9ca1f1446a5ad6b108044739a50e9275758e772c (diff)
downloadedk2-3604174718e2afc950c3cc64c64ba5165c8692bd.tar.gz
edk2-3604174718e2afc950c3cc64c64ba5165c8692bd.tar.bz2
edk2-3604174718e2afc950c3cc64c64ba5165c8692bd.zip
IntelFrameworkModulePkg/DebugLib: Fix string copy issue
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>
-rw-r--r--IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c b/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
index e92601f89e..1840b6d683 100644
--- a/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
+++ b/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
@@ -150,7 +150,7 @@ DebugPrintMarker (
FormatString = (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12);
//
- // Copy the Format string into the record
+ // Copy the Format string into the record. It will be truncated if it's too long.
//
// According to the content structure of Buffer shown above, the size of
// the FormatString buffer is the size of Buffer minus the Padding
@@ -158,7 +158,7 @@ DebugPrintMarker (
// variable arguments (12 * sizeof (UINT64)).
//
DestBufferSize = sizeof (Buffer) - 4 - sizeof (EFI_DEBUG_INFO) - 12 * sizeof (UINT64);
- AsciiStrCpyS (FormatString, DestBufferSize / sizeof (CHAR8), Format);
+ AsciiStrnCpyS (FormatString, DestBufferSize / sizeof (CHAR8), Format, DestBufferSize / sizeof (CHAR8) - 1);
//
// The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments