summaryrefslogtreecommitdiffstats
path: root/ShellPkg/Library/UefiShellLib
diff options
context:
space:
mode:
authorQiu Shumin <shumin.qiu@intel.com>2014-09-17 07:58:31 +0000
committershenshushi <shenshushi@6f19259b-4bc3-4df7-8a09-765794883524>2014-09-17 07:58:31 +0000
commit0960ba17e596812f211ba334cc6699d45bada328 (patch)
tree9daaedac1ac18feb91901a5ee844df2e450b61cb /ShellPkg/Library/UefiShellLib
parent3a3395f06b95ad5a0a78e23d293929e6809e09e5 (diff)
downloadedk2-0960ba17e596812f211ba334cc6699d45bada328.tar.gz
edk2-0960ba17e596812f211ba334cc6699d45bada328.tar.bz2
edk2-0960ba17e596812f211ba334cc6699d45bada328.zip
ShellPkg: Remove redundant quotes in file path string for Shell command parameters.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qiu Shumin <shumin.qiu@intel.com> Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16122 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Library/UefiShellLib')
-rw-r--r--ShellPkg/Library/UefiShellLib/UefiShellLib.c55
-rw-r--r--ShellPkg/Library/UefiShellLib/UefiShellLib.h18
2 files changed, 71 insertions, 2 deletions
diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
index 819c9f03ac..dc36db0349 100644
--- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
+++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
@@ -1494,6 +1494,7 @@ ShellOpenFileMetaArg (
{
EFI_STATUS Status;
LIST_ENTRY mOldStyleFileList;
+ CHAR16 *CleanFilePathStr;
//
// ASSERT that Arg and ListHead are not NULL
@@ -1501,6 +1502,11 @@ ShellOpenFileMetaArg (
ASSERT(Arg != NULL);
ASSERT(ListHead != NULL);
+ Status = InternalShellStripQuotes (Arg, &CleanFilePathStr);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
//
// Check for UEFI Shell 2.0 protocols
//
@@ -1508,11 +1514,12 @@ ShellOpenFileMetaArg (
if (*ListHead == NULL) {
*ListHead = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
if (*ListHead == NULL) {
+ FreePool(CleanFilePathStr);
return (EFI_OUT_OF_RESOURCES);
}
InitializeListHead(&((*ListHead)->Link));
}
- Status = gEfiShellProtocol->OpenFileList(Arg,
+ Status = gEfiShellProtocol->OpenFileList(CleanFilePathStr,
OpenMode,
ListHead);
if (EFI_ERROR(Status)) {
@@ -1522,9 +1529,11 @@ ShellOpenFileMetaArg (
}
if (*ListHead != NULL && IsListEmpty(&(*ListHead)->Link)) {
FreePool(*ListHead);
+ FreePool(CleanFilePathStr);
*ListHead = NULL;
return (EFI_NOT_FOUND);
}
+ FreePool(CleanFilePathStr);
return (Status);
}
@@ -1540,15 +1549,17 @@ ShellOpenFileMetaArg (
//
// Get the EFI Shell list of files
//
- Status = mEfiShellEnvironment2->FileMetaArg(Arg, &mOldStyleFileList);
+ Status = mEfiShellEnvironment2->FileMetaArg(CleanFilePathStr, &mOldStyleFileList);
if (EFI_ERROR(Status)) {
*ListHead = NULL;
+ FreePool(CleanFilePathStr);
return (Status);
}
if (*ListHead == NULL) {
*ListHead = (EFI_SHELL_FILE_INFO *)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
if (*ListHead == NULL) {
+ FreePool(CleanFilePathStr);
return (EFI_OUT_OF_RESOURCES);
}
InitializeListHead(&((*ListHead)->Link));
@@ -1569,9 +1580,11 @@ ShellOpenFileMetaArg (
*ListHead = NULL;
Status = EFI_NOT_FOUND;
}
+ FreePool(CleanFilePathStr);
return (Status);
}
+ FreePool(CleanFilePathStr);
return (EFI_UNSUPPORTED);
}
/**
@@ -4240,3 +4253,41 @@ ShellDeleteFileByName(
return(Status);
}
+
+/**
+ 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
+InternalShellStripQuotes (
+ 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/UefiShellLib/UefiShellLib.h b/ShellPkg/Library/UefiShellLib/UefiShellLib.h
index 32f1c6596d..c70e6cb91e 100644
--- a/ShellPkg/Library/UefiShellLib/UefiShellLib.h
+++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.h
@@ -72,5 +72,23 @@ InternalShellIsHexOrDecimalNumber (
IN CONST BOOLEAN StopAtSpace
);
+/**
+ 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
+InternalShellStripQuotes (
+ IN CONST CHAR16 *OriginalString,
+ OUT CHAR16 **CleanString
+ );
+
+
#endif