]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c
ShellPkg/for: Fix potential null pointer deference
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / DmpStore.c
index 713388150a43ebc1ba21fdf05fc50788a937b052..5791da9acc8c5f0192dfa733e6f5247bb1427c25 100644 (file)
@@ -2,7 +2,7 @@
   Main file for DmpStore shell Debug1 function.\r
    \r
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 2017, 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
@@ -84,8 +84,8 @@ GetAttrType (
 /**\r
   Convert binary to hex format string.\r
 \r
-  @param[in]  BufferSize        The size in bytes of the binary data.\r
   @param[in]  Buffer            The binary data.\r
+  @param[in]  BufferSize        The size in bytes of the binary data.\r
   @param[in, out] HexString     Hex format string.\r
   @param[in]      HexStringSize The size in bytes of the string.\r
 \r
@@ -364,7 +364,7 @@ AppendSingleVariableToFile (
   //\r
   // Crc32\r
   //\r
-  gBS->CalculateCrc32 (Buffer, (UINTN) (Ptr - Buffer), (UINT32 *) Ptr);\r
+  gBS->CalculateCrc32 (Buffer, (UINTN) Ptr - (UINTN) Buffer, (UINT32 *) Ptr);\r
 \r
   Status = ShellWriteFile (FileHandle, &BufferSize, Buffer);\r
   FreePool (Buffer);\r
@@ -423,6 +423,8 @@ CascadeProcessVariables (
   UINTN                     NameSize;\r
   CHAR16                    *AttrString;\r
   CHAR16                    *HexString;\r
+  EFI_STATUS                SetStatus;\r
+  CONST CHAR16              *GuidName;\r
 \r
   if (ShellGetExecutionBreakFlag()) {\r
     return (SHELL_ABORTED);\r
@@ -435,6 +437,7 @@ CascadeProcessVariables (
     StrnCatGrow(&FoundVarName, &NameSize, PrevName, 0);\r
   } else {\r
     FoundVarName = AllocateZeroPool(sizeof(CHAR16));\r
+    NameSize = sizeof(CHAR16);\r
   }\r
 \r
   Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);\r
@@ -519,10 +522,18 @@ CascadeProcessVariables (
             Status = EFI_OUT_OF_RESOURCES;\r
           }\r
         } else {\r
-          ShellPrintHiiEx (\r
-            -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_HEADER_LINE), gShellDebug1HiiHandle,\r
-            AttrString, &FoundVarGuid, FoundVarName, DataSize\r
-            );\r
+          Status = gEfiShellProtocol->GetGuidName(&FoundVarGuid, &GuidName);\r
+          if (EFI_ERROR (Status)) {\r
+            ShellPrintHiiEx (\r
+              -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_HEADER_LINE), gShellDebug1HiiHandle,\r
+              AttrString, &FoundVarGuid, FoundVarName, DataSize\r
+              );\r
+          } else {\r
+            ShellPrintHiiEx (\r
+              -1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_HEADER_LINE2), gShellDebug1HiiHandle,\r
+              AttrString, GuidName, FoundVarName, DataSize\r
+              );\r
+          }\r
           DumpHex (2, 0, DataSize, DataBuffer);\r
         }\r
         SHELL_FREE_NON_NULL (AttrString);\r
@@ -548,7 +559,7 @@ CascadeProcessVariables (
       //\r
       // We only need name to delete it...\r
       //\r
-      EFI_STATUS SetStatus = gRT->SetVariable (FoundVarName, &FoundVarGuid, Atts, 0, NULL);\r
+      SetStatus = gRT->SetVariable (FoundVarName, &FoundVarGuid, Atts, 0, NULL);\r
       if (StandardFormatOutput) {\r
         if (SetStatus == EFI_SUCCESS) {\r
           ShellPrintHiiEx (\r
@@ -675,6 +686,7 @@ ShellCommandRunDmpStore (
   )\r
 {\r
   EFI_STATUS        Status;\r
+  RETURN_STATUS     RStatus;\r
   LIST_ENTRY        *Package;\r
   CHAR16            *ProblemParam;\r
   SHELL_STATUS      ShellStatus;\r
@@ -727,8 +739,8 @@ ShellCommandRunDmpStore (
       if (!ShellCommandLineGetFlag(Package, L"-all")) {\r
         GuidStr = ShellCommandLineGetValue(Package, L"-guid");\r
         if (GuidStr != NULL) {\r
-          Status = ConvertStringToGuid(GuidStr, &GuidData);\r
-          if (EFI_ERROR(Status)) {\r
+          RStatus = StrToGuid (GuidStr, &GuidData);\r
+          if (RETURN_ERROR (RStatus) || (GuidStr[GUID_STRING_LENGTH] != L'\0')) {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmpstore", GuidStr);  \r
             ShellStatus = SHELL_INVALID_PARAMETER;\r
           }\r