From 568eee7cf319fa95183c8d3b5e8dcf6e078ab8b3 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Thu, 21 May 2020 09:28:40 +0800 Subject: UnitTestFrameworkPkg/UnitTestResultReportLib: Use AsciiStrnCpyS() REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2721 The ReportOutput() function in UnitTestResultReportLib copies characters from a function input buffer to an intermediate local buffer in fixed size chunks of the maximum size of the intermediate buffer. The implementation currently calls AsciiStrCpyS() which will ASSERT on an error. This commit changes the call to AsciiStrnCpyS() to avoid the ASSERT which is not expected in the usage of the string copy in this implementation. Cc: Bret Barkelew Cc: Sean Brogan Cc: Liming Gao Cc: Michael D Kinney Signed-off-by: Michael Kubacki Reviewed-by: Bret Barkelew --- .../Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c | 2 +- .../Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'UnitTestFrameworkPkg') diff --git a/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c b/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c index 139360ee16..cfb0c5972b 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c +++ b/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c @@ -42,7 +42,7 @@ ReportOutput ( Length = AsciiStrLen (Output); for (Index = 0; Index < Length; Index += (sizeof (AsciiString) - 1)) { - AsciiStrCpyS (AsciiString, sizeof (AsciiString), &Output[Index]); + AsciiStrnCpyS (AsciiString, sizeof (AsciiString), &Output[Index], sizeof (AsciiString) - 1); ReportPrint ("%a", AsciiString); } } diff --git a/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.c b/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.c index 743aad2958..1402d0ef83 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.c +++ b/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.c @@ -41,7 +41,7 @@ ReportOutput ( Length = AsciiStrLen (Output); for (Index = 0; Index < Length; Index += (sizeof (AsciiString) - 1)) { - AsciiStrCpyS (AsciiString, sizeof (AsciiString), &Output[Index]); + AsciiStrnCpyS (AsciiString, sizeof (AsciiString), &Output[Index], sizeof (AsciiString) - 1); DEBUG ((DEBUG_INFO, AsciiString)); } } -- cgit v1.2.3