summaryrefslogtreecommitdiffstats
path: root/ShellPkg/Library/UefiShellLib
diff options
context:
space:
mode:
authorQiu Shumin <shumin.qiu@intel.com>2015-06-30 03:18:31 +0000
committershenshushi <shenshushi@Edk2>2015-06-30 03:18:31 +0000
commite75390f02971bcd4d67a9696508050bee4936a01 (patch)
tree10fc0928560c01484d1952adf3a5990cc2243c26 /ShellPkg/Library/UefiShellLib
parentcb9a7ebabcd6b8a49dc0854b2f9592d732b5afbd (diff)
downloadedk2-e75390f02971bcd4d67a9696508050bee4936a01.tar.gz
edk2-e75390f02971bcd4d67a9696508050bee4936a01.tar.bz2
edk2-e75390f02971bcd4d67a9696508050bee4936a01.zip
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/Library/UefiShellLib')
-rw-r--r--ShellPkg/Library/UefiShellLib/UefiShellLib.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
index f82668b60f..5b4c6d3fb7 100644
--- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
+++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
@@ -1713,8 +1713,8 @@ ShellFindFilePath (
if (TestPath == NULL) {
return (NULL);
}
- StrnCpy(TestPath, Path, Size/sizeof(CHAR16) - 1);
- StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));
+ StrCpyS(TestPath, Size/sizeof(CHAR16), Path);
+ StrCatS(TestPath, Size/sizeof(CHAR16), FileName);
Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);
if (!EFI_ERROR(Status)){
if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {
@@ -1746,12 +1746,12 @@ ShellFindFilePath (
*TempChar = CHAR_NULL;
}
if (TestPath[StrLen(TestPath)-1] != L'\\') {
- StrnCat(TestPath, L"\\", Size/sizeof(CHAR16) - 1 - StrLen(TestPath));
+ StrCatS(TestPath, Size/sizeof(CHAR16), L"\\");
}
if (FileName[0] == L'\\') {
FileName++;
}
- StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));
+ StrCatS(TestPath, Size/sizeof(CHAR16), FileName);
if (StrStr(Walker, L";") != NULL) {
Walker = StrStr(Walker, L";") + 1;
} else {
@@ -1820,9 +1820,9 @@ ShellFindFilePathEx (
return (NULL);
}
for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension; TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1){
- StrnCpy(TestPath, FileName, Size/sizeof(CHAR16) - 1);
+ StrCpyS(TestPath, Size/sizeof(CHAR16), FileName);
if (ExtensionWalker != NULL) {
- StrnCat(TestPath, ExtensionWalker, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));
+ StrCatS(TestPath, Size/sizeof(CHAR16), ExtensionWalker);
}
TempChar = StrStr(TestPath, L";");
if (TempChar != NULL) {
@@ -2109,10 +2109,19 @@ InternalCommandLineParse (
CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value);
ASSERT(CurrentItemPackage->Value != NULL);
if (ValueSize == 0) {
- StrnCpy(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1);
+ StrCpyS( CurrentItemPackage->Value,
+ CurrentValueSize/sizeof(CHAR16),
+ Argv[LoopCounter]
+ );
} else {
- StrnCat(CurrentItemPackage->Value, L" ", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));
- StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));
+ StrCatS( CurrentItemPackage->Value,
+ CurrentValueSize/sizeof(CHAR16),
+ L" "
+ );
+ StrCatS( CurrentItemPackage->Value,
+ CurrentValueSize/sizeof(CHAR16),
+ Argv[LoopCounter]
+ );
}
ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);
@@ -2635,14 +2644,14 @@ ShellCopySearchAndReplace(
FreePool(Replace);
return (EFI_BUFFER_TOO_SMALL);
}
- StrnCat(NewString, Replace, NewSize/sizeof(CHAR16) - 1 - StrLen(NewString));
+ StrCatS(NewString, NewSize/sizeof(CHAR16), Replace);
} else {
Size = StrSize(NewString);
if (Size + sizeof(CHAR16) > NewSize) {
FreePool(Replace);
return (EFI_BUFFER_TOO_SMALL);
}
- StrnCat(NewString, SourceString, 1);
+ StrnCatS(NewString, NewSize/sizeof(CHAR16), SourceString, 1);
SourceString++;
}
}
@@ -3254,7 +3263,9 @@ StrnCatGrow (
if (*Destination == NULL) {
return (NULL);
}
- return StrnCat(*Destination, Source, Count);
+
+ StrCatS(*Destination, Count + 1, Source);
+ return *Destination;
}
/**