diff options
author | Qiu Shumin <shumin.qiu@intel.com> | 2015-06-30 03:18:31 +0000 |
---|---|---|
committer | shenshushi <shenshushi@Edk2> | 2015-06-30 03:18:31 +0000 |
commit | e75390f02971bcd4d67a9696508050bee4936a01 (patch) | |
tree | 10fc0928560c01484d1952adf3a5990cc2243c26 /ShellPkg/Application/Shell/Shell.c | |
parent | cb9a7ebabcd6b8a49dc0854b2f9592d732b5afbd (diff) | |
download | edk2-platforms-e75390f02971bcd4d67a9696508050bee4936a01.tar.xz |
ShellPkg: Use safe string functions to refine code.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17730 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Application/Shell/Shell.c')
-rw-r--r-- | ShellPkg/Application/Shell/Shell.c | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index 377e1ca7b7..779bb53df6 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -1079,10 +1079,10 @@ DoStartupScript( if (FileStringPath == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
- StrnCpy(FileStringPath, ShellInfoObject.ShellInitSettings.FileName, NewSize/sizeof(CHAR16) -1);
+ StrCpyS(FileStringPath, NewSize/sizeof(CHAR16), ShellInfoObject.ShellInitSettings.FileName);
if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {
- StrnCat(FileStringPath, L" ", NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);
- StrnCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);
+ StrnCatS(FileStringPath, NewSize/sizeof(CHAR16), L" ", NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);
+ StrnCatS(FileStringPath, NewSize/sizeof(CHAR16), ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);
}
Status = RunCommand(FileStringPath);
FreePool(FileStringPath);
@@ -1488,11 +1488,20 @@ ShellConvertVariables ( ; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL
; MasterEnvList += StrLen(MasterEnvList) + 1
){
- StrnCpy(ItemTemp, L"%", ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1);
- StrnCat(ItemTemp, MasterEnvList, ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1 - StrLen(ItemTemp));
- StrnCat(ItemTemp, L"%", ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1 - StrLen(ItemTemp));
+ StrCpyS( ItemTemp,
+ ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16)),
+ L"%"
+ );
+ StrCatS( ItemTemp,
+ ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16)),
+ MasterEnvList
+ );
+ StrCatS( ItemTemp,
+ ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16)),
+ L"%"
+ );
ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, ItemTemp, EfiShellGetEnv(MasterEnvList), TRUE, FALSE);
- StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);
+ StrCpyS(NewCommandLine1, NewSize/sizeof(CHAR16), NewCommandLine2);
}
if (CurrentScriptFile != NULL) {
for (AliasListNode = (ALIAS_LIST*)GetFirstNode(&CurrentScriptFile->SubstList)
@@ -1500,7 +1509,7 @@ ShellConvertVariables ( ; AliasListNode = (ALIAS_LIST*)GetNextNode(&CurrentScriptFile->SubstList, &AliasListNode->Link)
){
ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);
- StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);
+ StrCpyS(NewCommandLine1, NewSize/sizeof(CHAR16), NewCommandLine2);
}
}
@@ -1513,7 +1522,7 @@ ShellConvertVariables ( // Now cleanup any straggler intentionally ignored "%" characters
//
ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, L"^%", L"%", TRUE, FALSE);
- StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);
+ StrCpyS(NewCommandLine1, NewSize/sizeof(CHAR16), NewCommandLine2);
FreePool(NewCommandLine2);
FreePool(ItemTemp);
@@ -1991,6 +2000,7 @@ DoHelpUpdate( CHAR16 *Walker;
CHAR16 *NewCommandLine;
EFI_STATUS Status;
+ UINTN NewCmdLineSize;
Status = EFI_SUCCESS;
@@ -2005,7 +2015,8 @@ DoHelpUpdate( if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {
CurrentParameter[0] = L' ';
CurrentParameter[1] = L' ';
- NewCommandLine = AllocateZeroPool(StrSize(L"help ") + StrSize(*CmdLine));
+ NewCmdLineSize = StrSize(L"help ") + StrSize(*CmdLine);
+ NewCommandLine = AllocateZeroPool(NewCmdLineSize);
if (NewCommandLine == NULL) {
Status = EFI_OUT_OF_RESOURCES;
break;
@@ -2014,8 +2025,8 @@ DoHelpUpdate( //
// We know the space is sufficient since we just calculated it.
//
- StrnCpy(NewCommandLine, L"help ", 5);
- StrnCat(NewCommandLine, *CmdLine, StrLen(*CmdLine));
+ StrnCpyS(NewCommandLine, NewCmdLineSize/sizeof(CHAR16), L"help ", 5);
+ StrnCatS(NewCommandLine, NewCmdLineSize/sizeof(CHAR16), *CmdLine, StrLen(*CmdLine));
SHELL_FREE_NON_NULL(*CmdLine);
*CmdLine = NewCommandLine;
break;
@@ -2658,7 +2669,10 @@ RunScriptFileHandle ( ; // conditional increment in the body of the loop
){
ASSERT(CommandLine2 != NULL);
- StrnCpy(CommandLine2, NewScriptFile->CurrentCommand->Cl, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);
+ StrCpyS( CommandLine2,
+ PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16),
+ NewScriptFile->CurrentCommand->Cl
+ );
//
// NULL out comments
@@ -2679,7 +2693,10 @@ RunScriptFileHandle ( //
// Due to variability in starting the find and replace action we need to have both buffers the same.
//
- StrnCpy(CommandLine, CommandLine2, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);
+ StrCpyS( CommandLine,
+ PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16),
+ CommandLine2
+ );
//
// Remove the %0 to %9 from the command line (if we have some arguments)
@@ -2731,7 +2748,10 @@ RunScriptFileHandle ( Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%8", L"\"\"", FALSE, FALSE);
Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%9", L"\"\"", FALSE, FALSE);
- StrnCpy(CommandLine2, CommandLine, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);
+ StrCpyS( CommandLine2,
+ PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16),
+ CommandLine
+ );
LastCommand = NewScriptFile->CurrentCommand;
|