]> 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 bb2c0b98ec6fdceccb383ad1734ef0649240fdac..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
@@ -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
@@ -424,6 +424,7 @@ CascadeProcessVariables (
   CHAR16                    *AttrString;\r
   CHAR16                    *HexString;\r
   EFI_STATUS                SetStatus;\r
+  CONST CHAR16              *GuidName;\r
 \r
   if (ShellGetExecutionBreakFlag()) {\r
     return (SHELL_ABORTED);\r
@@ -436,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
@@ -520,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
@@ -676,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
@@ -728,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