From 4dc0d578b8b923672657956d3b1831c3cbf126ef Mon Sep 17 00:00:00 2001 From: Qiu Shumin Date: Thu, 9 Jul 2015 03:19:06 +0000 Subject: ShellPkg: Refine code to use Strn**S safe functions instead of Str**S ones in some cases. Safe string functions may ASSERT when the source length is larger than the MaxDest. This patch use Strn**S to indicate the copy length. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qiu Shumin Reviewed-by: Tapan Shah <> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17894 6f19259b-4bc3-4df7-8a09-765794883524 --- ShellPkg/Library/UefiDpLib/DpUtilities.c | 8 ++++---- ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c | 2 +- .../Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'ShellPkg/Library') diff --git a/ShellPkg/Library/UefiDpLib/DpUtilities.c b/ShellPkg/Library/UefiDpLib/DpUtilities.c index 7290285e2..063eb658c 100644 --- a/ShellPkg/Library/UefiDpLib/DpUtilities.c +++ b/ShellPkg/Library/UefiDpLib/DpUtilities.c @@ -261,7 +261,7 @@ GetNameFromHandle ( ); if (!EFI_ERROR (Status)) { SHELL_FREE_NON_NULL (PlatformLanguage); - StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr); + StrnCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr, DP_GAUGE_STRING_LENGTH); mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; return; } @@ -305,7 +305,7 @@ GetNameFromHandle ( // // Method 3. Get the name string from FFS UI section // - StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, NameString); + StrnCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, NameString, DP_GAUGE_STRING_LENGTH); mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; FreePool (NameString); } else { @@ -321,7 +321,7 @@ GetNameFromHandle ( // NameString = ConvertDevicePathToText (LoadedImageDevicePath, TRUE, FALSE); if (NameString != NULL) { - StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, NameString); + StrnCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, NameString, DP_GAUGE_STRING_LENGTH); mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; FreePool (NameString); return; @@ -334,7 +334,7 @@ GetNameFromHandle ( // StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL); ASSERT (StringPtr != NULL); - StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr); + StrnCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr, DP_GAUGE_STRING_LENGTH); FreePool (StringPtr); } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c index d818b9b8d..ac6d0bdb5 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c @@ -406,7 +406,7 @@ CascadeProcessVariables ( FoundVarName = AllocateZeroPool (NameSize); if (FoundVarName != NULL) { if (PrevName != NULL) { - StrCpyS(FoundVarName, NameSize/sizeof(CHAR16), PrevName); + StrnCpyS(FoundVarName, NameSize/sizeof(CHAR16), PrevName, NameSize/sizeof(CHAR16) - 1); } Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c index dd878c4cb..759f486a3 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c @@ -3229,8 +3229,8 @@ QueryTable ( // if ((High > Low && Key >= Low && Key <= High) || (Table[Index].Key == Key)) { - StrCpyS (Info, InfoLen, Table[Index].Info); - StrCatS (Info, InfoLen, L"\n"); + StrnCpyS (Info, InfoLen, Table[Index].Info, InfoLen - 1); + StrnCatS (Info, InfoLen, L"\n", InfoLen - 1 - StrLen(Info)); return Key; } } -- cgit v1.2.3