]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
ShellPkg: Add checking for memory allocation and pointer returns from functions.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / UefiShellLevel2CommandsLib.c
index 7fe5a1102cab3fd3099d7226d847ca32709b264c..b153d2fe452842df0e2412328eb4719cfeee8403 100644 (file)
   rm,\r
   reset,\r
   set,\r
-  timezone*\r
+  timezone*,\r
+  vol\r
 \r
   * functions are non-interactive only\r
 \r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 \r
 CONST CHAR16 mFileName[] = L"ShellCommands";\r
 EFI_HANDLE gShellLevel2HiiHandle = NULL;\r
-CONST EFI_GUID gShellLevel2HiiGuid = \\r
-  { \\r
-    0xf95a7ccc, 0x4c55, 0x4426, { 0xa7, 0xb4, 0xdc, 0x89, 0x61, 0x95, 0xb, 0xae } \\r
-  };\r
 \r
+/**\r
+  Get the filename to get help text from if not using HII.\r
+\r
+  @retval The filename.\r
+**/\r
 CONST CHAR16*\r
 EFIAPI\r
 ShellCommandGetManFileNameLevel2 (\r
@@ -71,7 +73,7 @@ ShellLevel2CommandsLibConstructor (
   // if shell level is less than 2 do nothing\r
   //\r
   if (PcdGet8(PcdShellSupportLevel) < 2) {\r
-    return (EFI_UNSUPPORTED);\r
+    return (EFI_SUCCESS);\r
   }\r
 \r
   gShellLevel2HiiHandle = HiiAddPackages (&gShellLevel2HiiGuid, gImageHandle, UefiShellLevel2CommandsLibStrings, NULL);\r
@@ -94,6 +96,7 @@ ShellLevel2CommandsLibConstructor (
   ShellCommandRegisterCommandName(L"set",      ShellCommandRunSet     , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_SET)    );\r
   ShellCommandRegisterCommandName(L"ls",       ShellCommandRunLs      , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_LS)     );\r
   ShellCommandRegisterCommandName(L"rm",       ShellCommandRunRm      , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_RM)     );\r
+  ShellCommandRegisterCommandName(L"vol",      ShellCommandRunVol     , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_VOL)    );\r
 \r
   //\r
   // support for permenant (built in) aliases\r
@@ -104,6 +107,7 @@ ShellLevel2CommandsLibConstructor (
   ShellCommandRegisterAlias(L"mkdir", L"md");\r
   ShellCommandRegisterAlias(L"cd ..", L"cd..");\r
   ShellCommandRegisterAlias(L"cd \\", L"cd\\");\r
+  ShellCommandRegisterAlias(L"ren", L"mv");\r
   //\r
   // These are installed in level 2 or 3...\r
   //\r
@@ -146,54 +150,6 @@ ShellLevel2CommandsLibDestructor (
   return (EFI_SUCCESS);\r
 }\r
 \r
-/**\r
-  Function to clean up paths.  Removes the following items:\r
-    single periods in the path (no need for the current directory tag)\r
-    double periods in the path and removes a single parent directory.\r
-\r
-  This will be done inline and the resultant string may be be 'too big'.\r
-\r
-  @param[in] PathToReturn  The pointer to the string containing the path.\r
-\r
-  @return PathToReturn is always returned.\r
-**/\r
-CHAR16*\r
-EFIAPI\r
-CleanPath(\r
-  IN CHAR16 *PathToReturn\r
-  )\r
-{\r
-  CHAR16  *TempString;\r
-  UINTN   TempSize;\r
-  if (PathToReturn==NULL) {\r
-    return(NULL);\r
-  }\r
-  //\r
-  // Fix up the directory name\r
-  //\r
-  while ((TempString = StrStr(PathToReturn, L"\\..\\")) != NULL) {\r
-    *TempString = CHAR_NULL;\r
-    TempString  += 4;\r
-    ChopLastSlash(PathToReturn);\r
-    TempSize = StrSize(TempString);\r
-    CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize);\r
-  }\r
-  if ((TempString = StrStr(PathToReturn, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) {\r
-    *TempString = CHAR_NULL;\r
-    ChopLastSlash(PathToReturn);\r
-  }\r
-  while ((TempString = StrStr(PathToReturn, L"\\.\\")) != NULL) {\r
-    *TempString = CHAR_NULL;\r
-    TempString  += 2;\r
-    TempSize = StrSize(TempString);\r
-    CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize);\r
-  }\r
-  if ((TempString = StrStr(PathToReturn, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {\r
-    *TempString = CHAR_NULL;\r
-  }\r
-  return (PathToReturn);\r
-}\r
-\r
 /**\r
   returns a fully qualified directory (contains a map drive at the begining)\r
   path from a unknown directory path.\r
@@ -236,7 +192,7 @@ GetFullyQualifiedPath(
   }\r
   StrnCatGrow(&PathToReturn, &Size, Path, 0);\r
 \r
-  CleanPath(PathToReturn);\r
+  PathCleanUpDirectories(PathToReturn);\r
 \r
   while (PathToReturn[StrLen(PathToReturn)-1] == L'*') {\r
     PathToReturn[StrLen(PathToReturn)-1] = CHAR_NULL;\r
@@ -270,6 +226,10 @@ VerifyIntermediateDirectories (
   PathCopy    = StrnCatGrow(&PathCopy, NULL, Path, 0);\r
   FileHandle  = NULL;\r
 \r
+  if (PathCopy == NULL) {\r
+    return (EFI_OUT_OF_RESOURCES);\r
+  }\r
+\r
   for (TempSpot = &PathCopy[StrLen(PathCopy)-1] ; *TempSpot != CHAR_NULL && *TempSpot != L'\\' ; TempSpot = &PathCopy[StrLen(PathCopy)-1]){\r
     *TempSpot = CHAR_NULL;\r
   }\r
@@ -295,13 +255,29 @@ VerifyIntermediateDirectories (
   return (Status);\r
 }\r
 \r
-// be lazy and borrow from baselib.\r
+/**\r
+  Be lazy and borrow from baselib.\r
+\r
+  @param[in] Char   The character to convert to upper case.\r
+\r
+  @return Char as an upper case character.\r
+**/\r
 CHAR16\r
 EFIAPI\r
 InternalCharToUpper (\r
   IN CONST CHAR16                    Char\r
   );\r
 \r
+/**\r
+  String comparison without regard to case for a limited number of characters.\r
+\r
+  @param[in] Source   The first item to compare.\r
+  @param[in] Target   The second item to compare.\r
+  @param[in] Count    How many characters to compare.\r
+\r
+  @retval NULL Source and Target are identical strings without regard to case.\r
+  @return The location in Source where there is a difference.\r
+**/\r
 CONST CHAR16*\r
 EFIAPI\r
 StrniCmp(\r