This patch replaces StrCpy with StrnCpy or refactors out the usage of StrCpy through some other means.
This patch replaces StrCat with StrnCat or refactors out the usage of StrCat through some other means.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15771
6f19259b-4bc3-4df7-8a09-
765794883524
SHELL_STATUS ShellStatus;\r
CHAR16 *DestPath;\r
VOID *Response;\r
SHELL_STATUS ShellStatus;\r
CHAR16 *DestPath;\r
VOID *Response;\r
CONST CHAR16 *Cwd;\r
UINTN NewSize;\r
\r
CONST CHAR16 *Cwd;\r
UINTN NewSize;\r
\r
\r
DestPath = NULL;\r
ShellStatus = SHELL_SUCCESS;\r
\r
DestPath = NULL;\r
ShellStatus = SHELL_SUCCESS;\r
Cwd = ShellGetCurrentDir(NULL);\r
\r
ASSERT(FileList != NULL);\r
Cwd = ShellGetCurrentDir(NULL);\r
\r
ASSERT(FileList != NULL);\r
NewSize = StrSize(DestDir);\r
NewSize += StrSize(Node->FullName);\r
NewSize += (Cwd == NULL)? 0 : StrSize(Cwd);\r
NewSize = StrSize(DestDir);\r
NewSize += StrSize(Node->FullName);\r
NewSize += (Cwd == NULL)? 0 : StrSize(Cwd);\r
- if (NewSize > PathLen) {\r
- PathLen = NewSize;\r
+ if (NewSize > PathSize) {\r
+ PathSize = NewSize;\r
\r
HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_CP_OUTPUT), NULL);\r
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);\r
\r
HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_CP_OUTPUT), NULL);\r
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);\r
- DestPath = AllocateZeroPool(PathLen);\r
+ DestPath = AllocateZeroPool(PathSize);\r
\r
if (DestPath == NULL || HiiOutput == NULL || HiiResultOk == NULL) {\r
SHELL_FREE_NON_NULL(DestPath);\r
\r
if (DestPath == NULL || HiiOutput == NULL || HiiResultOk == NULL) {\r
SHELL_FREE_NON_NULL(DestPath);\r
// simple copy of a single file\r
//\r
if (Cwd != NULL) {\r
// simple copy of a single file\r
//\r
if (Cwd != NULL) {\r
- StrCpy(DestPath, Cwd);\r
+ StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16)-1);\r
} else {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
return (SHELL_INVALID_PARAMETER);\r
}\r
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
} else {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
return (SHELL_INVALID_PARAMETER);\r
}\r
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
- StrCat(DestPath, L"\\");\r
+ StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
}\r
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
}\r
- StrCat(DestPath, DestDir);\r
+ StrnCat(DestPath, DestDir, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
- StrCpy(DestPath, DestDir);\r
+ StrnCpy(DestPath, DestDir, PathSize/sizeof(CHAR16) -1);\r
// Copy to the root of CWD\r
//\r
if (Cwd != NULL) {\r
// Copy to the root of CWD\r
//\r
if (Cwd != NULL) {\r
- StrCpy(DestPath, Cwd);\r
+ StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);\r
} else {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
return (SHELL_INVALID_PARAMETER);\r
}\r
while (PathRemoveLastItem(DestPath));\r
} else {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
return (SHELL_INVALID_PARAMETER);\r
}\r
while (PathRemoveLastItem(DestPath));\r
- StrCat(DestPath, DestDir+1);\r
- StrCat(DestPath, Node->FileName);\r
+ StrnCat(DestPath, DestDir+1, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+ StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
} else if (StrStr(DestDir, L":") == NULL) {\r
if (Cwd != NULL) {\r
} else if (StrStr(DestDir, L":") == NULL) {\r
if (Cwd != NULL) {\r
- StrCpy(DestPath, Cwd);\r
+ StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);\r
} else {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
return (SHELL_INVALID_PARAMETER);\r
}\r
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
} else {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
return (SHELL_INVALID_PARAMETER);\r
}\r
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
- StrCat(DestPath, L"\\");\r
+ StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
}\r
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
}\r
- StrCat(DestPath, DestDir);\r
+ StrnCat(DestPath, DestDir, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
- StrCat(DestPath, L"\\");\r
+ StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
} else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
}\r
} else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
}\r
- StrCat(DestPath, Node->FileName);\r
+ StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
- StrCpy(DestPath, DestDir);\r
+ StrnCpy(DestPath, DestDir, PathSize/sizeof(CHAR16) -1);\r
if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
- StrCat(DestPath, L"\\");\r
+ StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
} else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
((CHAR16*)DestDir)[StrLen(DestDir)-1] = CHAR_NULL;\r
}\r
} else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
((CHAR16*)DestDir)[StrLen(DestDir)-1] = CHAR_NULL;\r
}\r
- StrCat(DestPath, Node->FileName);\r
+ StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r