]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c
ShellPkg/Debug1CommandLib: Use StrToGuid/StrHexToBytes in BaseLib
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SetVar.c
index d98a3469a31ddf2d951c403d99ef8c110f1baeb6..c59032a81162ea4c523da28ab1fe4763b2760eaa 100644 (file)
@@ -2,7 +2,7 @@
   Main file for SetVar shell Debug1 function.\r
 \r
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 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
@@ -65,6 +65,7 @@ ShellCommandRunSetVar (
   )\r
 {\r
   EFI_STATUS          Status;\r
+  RETURN_STATUS       RStatus;\r
   LIST_ENTRY          *Package;\r
   CHAR16              *ProblemParam;\r
   SHELL_STATUS        ShellStatus;\r
@@ -120,8 +121,8 @@ ShellCommandRunSetVar (
         CopyGuid(&Guid, &gEfiGlobalVariableGuid);\r
       } else {\r
         StringGuid = ShellCommandLineGetValue(Package, L"-guid");\r
-        Status = ConvertStringToGuid(StringGuid, &Guid);\r
-        if (EFI_ERROR(Status)) {\r
+        RStatus = StrToGuid (StringGuid, &Guid);\r
+        if (RETURN_ERROR (RStatus) || (StringGuid[GUID_STRING_LENGTH] != L'\0')) {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid);  \r
           ShellStatus = SHELL_INVALID_PARAMETER;\r
         }\r
@@ -207,10 +208,7 @@ ShellCommandRunSetVar (
             if (Buffer == NULL) {\r
               Status = EFI_OUT_OF_RESOURCES;\r
             } else {\r
-              for (LoopVar = 0 ; LoopVar < (StrLen(Data) / 2) ; LoopVar++) {\r
-                ((UINT8*)Buffer)[LoopVar] = (UINT8)(HexCharToUintn(Data[LoopVar*2]) * 16);\r
-                ((UINT8*)Buffer)[LoopVar] = (UINT8)(((UINT8*)Buffer)[LoopVar] + HexCharToUintn(Data[LoopVar*2+1]));\r
-              }\r
+              StrHexToBytes (Data, StrLen (Data), Buffer, StrLen (Data) / 2);\r
               Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, StrLen(Data) / 2, Buffer);\r
             }\r
             if (EFI_ERROR(Status)) {\r