summaryrefslogtreecommitdiff
path: root/ShellPkg/Library/UefiShellLevel2CommandsLib
diff options
context:
space:
mode:
Diffstat (limited to 'ShellPkg/Library/UefiShellLevel2CommandsLib')
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c7
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c73
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c13
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c39
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h17
5 files changed, 121 insertions, 28 deletions
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
index aa5a20857f..21976211e6 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
@@ -38,6 +38,7 @@ ShellCommandRunCd (
SHELL_FILE_HANDLE Handle;
CONST CHAR16 *Param1;
CHAR16 *Param1Copy;
+ CHAR16* Walker;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
@@ -96,6 +97,12 @@ ShellCommandRunCd (
}
} else {
Param1Copy = CatSPrint(NULL, L"%s", Param1, NULL);
+ for (Walker = Param1Copy; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {
+ if (*Walker == L'\"') {
+ CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));
+ }
+ }
+
if (Param1Copy != NULL) {
Param1Copy = PathCleanUpDirectories(Param1Copy);
}
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
index 3a00683939..52c1de8a96 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
@@ -295,11 +295,13 @@ ValidateAndCopyFiles(
CHAR16 *HiiResultOk;
CONST EFI_SHELL_FILE_INFO *Node;
SHELL_STATUS ShellStatus;
+ EFI_STATUS Status;
CHAR16 *DestPath;
VOID *Response;
UINTN PathSize;
CONST CHAR16 *Cwd;
UINTN NewSize;
+ CHAR16 *CleanFilePathStr;
if (Resp == NULL) {
Response = NULL;
@@ -315,14 +317,25 @@ ValidateAndCopyFiles(
ASSERT(FileList != NULL);
ASSERT(DestDir != NULL);
+
+ Status = ShellLevel2StripQuotes (DestDir, &CleanFilePathStr);
+ if (EFI_ERROR (Status)) {
+ if (Status == EFI_OUT_OF_RESOURCES) {
+ return SHELL_OUT_OF_RESOURCES;
+ } else {
+ return SHELL_INVALID_PARAMETER;
+ }
+ }
+
//
// If we are trying to copy multiple files... make sure we got a directory for the target...
//
- if (EFI_ERROR(ShellIsDirectory(DestDir)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {
+ if (EFI_ERROR(ShellIsDirectory(CleanFilePathStr)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {
//
// Error for destination not a directory
//
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, DestDir);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, CleanFilePathStr);
+ FreePool (CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
@@ -336,7 +349,7 @@ ValidateAndCopyFiles(
continue;
}
- NewSize = StrSize(DestDir);
+ NewSize = StrSize(CleanFilePathStr);
NewSize += StrSize(Node->FullName);
NewSize += (Cwd == NULL)? 0 : StrSize(Cwd);
if (NewSize > PathSize) {
@@ -348,17 +361,19 @@ ValidateAndCopyFiles(
//
if (!RecursiveMode && !EFI_ERROR(ShellIsDirectory(Node->FullName))) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_REQ), gShellLevel2HiiHandle);
+ FreePool (CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
//
// make sure got dest as dir if needed
//
- if (!EFI_ERROR(ShellIsDirectory(Node->FullName)) && EFI_ERROR(ShellIsDirectory(DestDir))) {
+ if (!EFI_ERROR(ShellIsDirectory(Node->FullName)) && EFI_ERROR(ShellIsDirectory(CleanFilePathStr))) {
//
// Error for destination not a directory
//
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, DestDir);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, CleanFilePathStr);
+ FreePool (CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
}
@@ -371,6 +386,7 @@ ValidateAndCopyFiles(
SHELL_FREE_NON_NULL(DestPath);
SHELL_FREE_NON_NULL(HiiOutput);
SHELL_FREE_NON_NULL(HiiResultOk);
+ FreePool (CleanFilePathStr);
return (SHELL_OUT_OF_RESOURCES);
}
@@ -395,26 +411,27 @@ ValidateAndCopyFiles(
}
if (FileList->Link.ForwardLink == FileList->Link.BackLink // 1 item
- && EFI_ERROR(ShellIsDirectory(DestDir)) // not an existing directory
+ && EFI_ERROR(ShellIsDirectory(CleanFilePathStr)) // not an existing directory
) {
- if (StrStr(DestDir, L":") == NULL) {
+ if (StrStr(CleanFilePathStr, L":") == NULL) {
//
// simple copy of a single file
//
if (Cwd != NULL) {
StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16)-1);
} else {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, CleanFilePathStr);
+ FreePool (CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
- if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
+ if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {
StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
- } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
+ } else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
- StrnCat(DestPath, DestDir, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
+ StrnCat(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
} else {
- StrnCpy(DestPath, DestDir, PathSize/sizeof(CHAR16) -1);
+ StrnCpy(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) -1);
}
} else {
//
@@ -424,50 +441,52 @@ ValidateAndCopyFiles(
//
// Check for leading slash
//
- if (DestDir[0] == L'\\') {
+ if (CleanFilePathStr[0] == L'\\') {
//
// Copy to the root of CWD
//
if (Cwd != NULL) {
StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);
} else {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, CleanFilePathStr);
+ FreePool(CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
while (PathRemoveLastItem(DestPath));
- StrnCat(DestPath, DestDir+1, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
+ StrnCat(DestPath, CleanFilePathStr+1, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
- } else if (StrStr(DestDir, L":") == NULL) {
+ } else if (StrStr(CleanFilePathStr, L":") == NULL) {
if (Cwd != NULL) {
StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);
} else {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, CleanFilePathStr);
+ FreePool(CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
- if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
+ if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {
StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
- } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
+ } else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
- StrnCat(DestPath, DestDir, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
- if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {
+ StrnCat(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
+ if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {
StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
- } else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {
+ } else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
} else {
- StrnCpy(DestPath, DestDir, PathSize/sizeof(CHAR16) -1);
- if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {
+ StrnCpy(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) -1);
+ if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {
StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
- } else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {
- ((CHAR16*)DestDir)[StrLen(DestDir)-1] = CHAR_NULL;
+ } else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {
+ ((CHAR16*)CleanFilePathStr)[StrLen(CleanFilePathStr)-1] = CHAR_NULL;
}
StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
}
}
-
+ FreePool (CleanFilePathStr);
//
// Make sure the path exists
//
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
index f9b83e6fa4..fcf5f657b8 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
@@ -270,6 +270,7 @@ ValidateAndMoveFiles(
UINTN Length;
VOID *Response;
SHELL_FILE_HANDLE DestHandle;
+ CHAR16 *CleanFilePathStr;
ASSERT(FileList != NULL);
ASSERT(DestDir != NULL);
@@ -278,10 +279,20 @@ ValidateAndMoveFiles(
Cwd = ShellGetCurrentDir(NULL);
Response = *Resp;
+ Status = ShellLevel2StripQuotes (DestDir, &CleanFilePathStr);
+ if (EFI_ERROR (Status)) {
+ if (Status == EFI_OUT_OF_RESOURCES) {
+ return SHELL_OUT_OF_RESOURCES;
+ } else {
+ return SHELL_INVALID_PARAMETER;
+ }
+ }
+
//
// Get and validate the destination location
//
- ShellStatus = GetDestinationLocation(DestDir, &DestPath, Cwd);
+ ShellStatus = GetDestinationLocation(CleanFilePathStr, &DestPath, Cwd);
+ FreePool (CleanFilePathStr);
if (ShellStatus != SHELL_SUCCESS) {
return (ShellStatus);
}
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
index 48b1cf84b8..4ac7e67007 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
@@ -309,3 +309,42 @@ StrniCmp(
return (NULL);
}
+
+/**
+ Cleans off all the quotes in the string.
+
+ @param[in] OriginalString pointer to the string to be cleaned.
+ @param[out] CleanString The new string with all quotes removed.
+ Memory allocated in the function and free
+ by caller.
+
+ @retval EFI_SUCCESS The operation was successful.
+**/
+EFI_STATUS
+EFIAPI
+ShellLevel2StripQuotes (
+ IN CONST CHAR16 *OriginalString,
+ OUT CHAR16 **CleanString
+ )
+{
+ CHAR16 *Walker;
+
+ if (OriginalString == NULL || CleanString == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *CleanString = AllocateCopyPool (StrSize (OriginalString), OriginalString);
+ if (*CleanString == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {
+ if (*Walker == L'\"') {
+ CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
+
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
index 8abf7e02a8..d6f23187be 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
@@ -301,6 +301,23 @@ StrniCmp(
);
/**
+ Cleans off all the quotes in the string.
+
+ @param[in] OriginalString pointer to the string to be cleaned.
+ @param[out] CleanString The new string with all quotes removed.
+ Memory allocated in the function and free
+ by caller.
+
+ @retval EFI_SUCCESS The operation was successful.
+**/
+EFI_STATUS
+EFIAPI
+ShellLevel2StripQuotes (
+ IN CONST CHAR16 *OriginalString,
+ OUT CHAR16 **CleanString
+ );
+
+/**
Function for 'Vol' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).