public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Gao, Zhichao" <zhichao.gao@intel.com>
To: devel@edk2.groups.io
Cc: Liming Gao <liming.gao@intel.com>, Hao A Wu <hao.a.wu@intel.com>
Subject: [PATCH] IntelFrameworkModulePkg/DebugLib: Fix string copy issue
Date: Tue, 21 May 2019 15:49:52 +0800	[thread overview]
Message-ID: <20190521074952.38376-1-zhichao.gao@intel.com> (raw)

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>
---
 .../Library/PeiDxeDebugLibReportStatusCode/DebugLib.c         | 4 ++--
 1 file 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
-- 
2.21.0.windows.1


             reply	other threads:[~2019-05-21  7:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-21  7:49 Gao, Zhichao [this message]
2019-05-21  8:03 ` [edk2-devel] [PATCH] IntelFrameworkModulePkg/DebugLib: Fix string copy issue Wu, Hao A
2019-05-22  1:55   ` Liming Gao
2019-05-22  5:22 ` Ni, Ray
2019-05-22  5:32   ` Liming Gao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190521074952.38376-1-zhichao.gao@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox