Reviewed-by: Bret Barkelew - Bret ________________________________ From: michael.kubacki@outlook.com Sent: Wednesday, May 20, 2020 6:28:40 PM To: devel@edk2.groups.io Cc: Bret Barkelew ; Sean Brogan ; liming.gao ; Kinney, Michael D Subject: [EXTERNAL] [PATCH v1 1/1] UnitTestFrameworkPkg/UnitTestResultReportLib: Use AsciiStrnCpyS() From: Michael Kubacki REF:https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2721&data=02%7C01%7CBret.Barkelew%40microsoft.com%7C3df7de73c045465745a708d7fd265f00%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637256213561542812&sdata=d28c2VOQ%2FCn53uFUGpddqFtL3lmX9Kir7mvKYm7%2BYEw%3D&reserved=0 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 --- UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c | 2 +- UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c b/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c index 139360ee1657..cfb0c5972bd1 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 743aad2958a7..1402d0ef83e2 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)); } } -- 2.16.3.windows.1