]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
ShellPkg/ConsistMapping.c: Handle memory allocation failure
[mirror_edk2.git] / ShellPkg / Library / UefiShellCommandLib / UefiShellCommandLib.c
index 3829ba1f8c779f11407e7295c464a8a6fe070e79..48e4d4af0dca77301b278888918be9ed622482bc 100644 (file)
@@ -1,8 +1,10 @@
 /** @file\r
   Provides interface to shell internal functions for shell commands.\r
 \r
-  Copyright (c) 2013-2014, Hewlett-Packard Development Company, L.P.<BR>\r
   Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
+  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
+
   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
@@ -29,6 +31,25 @@ STATIC UINTN                              mFsMaxCount = 0;
 STATIC UINTN                              mBlkMaxCount = 0;\r
 STATIC BUFFER_LIST                        mFileHandleList;\r
 \r
+STATIC CONST CHAR8 Hex[] = {\r
+  '0',\r
+  '1',\r
+  '2',\r
+  '3',\r
+  '4',\r
+  '5',\r
+  '6',\r
+  '7',\r
+  '8',\r
+  '9',\r
+  'A',\r
+  'B',\r
+  'C',\r
+  'D',\r
+  'E',\r
+  'F'\r
+};\r
+\r
 // global variables required by library class.\r
 EFI_UNICODE_COLLATION_PROTOCOL    *gUnicodeCollation            = NULL;\r
 SHELL_MAP_LIST                    gShellMapList;\r
@@ -892,7 +913,7 @@ ShellCommandIsOnAliasList(
 }\r
 \r
 /**\r
-  Function to determine current state of ECHO.  Echo determins if lines from scripts\r
+  Function to determine current state of ECHO.  Echo determines if lines from scripts\r
   and ECHO commands are enabled.\r
 \r
   @retval TRUE    Echo is currently enabled\r
@@ -908,7 +929,7 @@ ShellCommandGetEchoState(
 }\r
 \r
 /**\r
-  Function to set current state of ECHO.  Echo determins if lines from scripts\r
+  Function to set current state of ECHO.  Echo determines if lines from scripts\r
   and ECHO commands are enabled.\r
 \r
   If State is TRUE, Echo will be enabled.\r
@@ -1165,7 +1186,7 @@ ShellCommandAddMapItemAndUpdatePath(
     Status = EFI_OUT_OF_RESOURCES;\r
   } else {\r
     MapListNode->Flags = Flags;\r
-    MapListNode->MapName = AllocateZeroPool(StrSize(Name), Name);\r
+    MapListNode->MapName = AllocateCopyPool(StrSize(Name), Name);\r
     MapListNode->DevicePath = DuplicateDevicePath(DevicePath);\r
     if ((MapListNode->MapName == NULL) || (MapListNode->DevicePath == NULL)){\r
       Status = EFI_OUT_OF_RESOURCES;\r
@@ -1261,6 +1282,9 @@ ShellCommandCreateInitialMappingsAndPaths(
         ; MapListNode = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)\r
        ){\r
           RemoveEntryList(&MapListNode->Link);\r
+          SHELL_FREE_NON_NULL(MapListNode->DevicePath);\r
+          SHELL_FREE_NON_NULL(MapListNode->MapName);\r
+          SHELL_FREE_NON_NULL(MapListNode->CurrentDirectoryPath);\r
           FreePool(MapListNode);\r
     } // for loop\r
   }\r
@@ -1622,7 +1646,6 @@ ShellFileHandleEof(
 \r
   gEfiShellProtocol->GetFilePosition(Handle, &Pos);\r
   Info = gEfiShellProtocol->GetFileInfo (Handle);\r
-  ASSERT(Info != NULL);\r
   gEfiShellProtocol->SetFilePosition(Handle, Pos);\r
 \r
   if (Info == NULL) {\r
@@ -1671,3 +1694,110 @@ FreeBufferList (
   }\r
 }\r
 \r
+/**\r
+  Dump some hexadecimal data to the screen.\r
+\r
+  @param[in] Indent     How many spaces to indent the output.\r
+  @param[in] Offset     The offset of the printing.\r
+  @param[in] DataSize   The size in bytes of UserData.\r
+  @param[in] UserData   The data to print out.\r
+**/\r
+VOID\r
+DumpHex (\r
+  IN UINTN        Indent,\r
+  IN UINTN        Offset,\r
+  IN UINTN        DataSize,\r
+  IN VOID         *UserData\r
+  )\r
+{\r
+  UINT8 *Data;\r
+\r
+  CHAR8 Val[50];\r
+\r
+  CHAR8 Str[20];\r
+\r
+  UINT8 TempByte;\r
+  UINTN Size;\r
+  UINTN Index;\r
+\r
+  Data = UserData;\r
+  while (DataSize != 0) {\r
+    Size = 16;\r
+    if (Size > DataSize) {\r
+      Size = DataSize;\r
+    }\r
+\r
+    for (Index = 0; Index < Size; Index += 1) {\r
+      TempByte            = Data[Index];\r
+      Val[Index * 3 + 0]  = Hex[TempByte >> 4];\r
+      Val[Index * 3 + 1]  = Hex[TempByte & 0xF];\r
+      Val[Index * 3 + 2]  = (CHAR8) ((Index == 7) ? '-' : ' ');\r
+      Str[Index]          = (CHAR8) ((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte);\r
+    }\r
+\r
+    Val[Index * 3]  = 0;\r
+    Str[Index]      = 0;\r
+    ShellPrintEx(-1, -1, L"%*a%08X: %-48a *%a*\r\n", Indent, "", Offset, Val, Str);\r
+\r
+    Data += Size;\r
+    Offset += Size;\r
+    DataSize -= Size;\r
+  }\r
+}\r
+
+/**
+  Dump HEX data into buffer.
+   
+  @param[in] Buffer     HEX data to be dumped in Buffer.
+  @param[in] Indent     How many spaces to indent the output.
+  @param[in] Offset     The offset of the printing.
+  @param[in] DataSize   The size in bytes of UserData.
+  @param[in] UserData   The data to print out.
+**/
+CHAR16*
+CatSDumpHex (
+  IN CHAR16  *Buffer,
+  IN UINTN   Indent,
+  IN UINTN   Offset,
+  IN UINTN   DataSize,
+  IN VOID    *UserData
+  )
+{
+  UINT8   *Data;
+  UINT8   TempByte;
+  UINTN   Size;
+  UINTN   Index;
+  CHAR8   Val[50];
+  CHAR8   Str[20];
+  CHAR16  *RetVal;
+  CHAR16  *TempRetVal;
+
+  Data = UserData;
+  RetVal = Buffer;
+  while (DataSize != 0) {
+    Size = 16;
+    if (Size > DataSize) {
+      Size = DataSize;
+    }
+
+    for (Index = 0; Index < Size; Index += 1) {
+      TempByte            = Data[Index];
+      Val[Index * 3 + 0]  = Hex[TempByte >> 4];
+      Val[Index * 3 + 1]  = Hex[TempByte & 0xF];
+      Val[Index * 3 + 2]  = (CHAR8) ((Index == 7) ? '-' : ' ');
+      Str[Index]          = (CHAR8) ((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte);
+    }
+
+    Val[Index * 3]  = 0;
+    Str[Index]      = 0;
+    TempRetVal = CatSPrint (RetVal, L"%*a%08X: %-48a *%a*\r\n", Indent, "", Offset, Val, Str);
+    SHELL_FREE_NON_NULL (RetVal);
+    RetVal = TempRetVal;
+
+    Data += Size;
+    Offset += Size;
+    DataSize -= Size;
+  }
+
+  return RetVal;
+}