UINT64 Buffer[(EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)) + 1];\r
EFI_DEBUG_INFO *DebugInfo;\r
UINTN TotalSize;\r
+ UINTN DestBufferSize;\r
VA_LIST VaListMarker;\r
BASE_LIST BaseListMarker;\r
CHAR8 *FormatString;\r
//\r
// Copy the Format string into the record\r
//\r
- AsciiStrCpy (FormatString, Format);\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
+ // (4 bytes), minus the size of EFI_DEBUG_INFO, minus the size of\r
+ // 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
\r
//\r
// The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r