Revision: 16194
          http://sourceforge.net/p/edk2/code/16194
Author:   jcarsey
Date:     2014-10-02 16:41:28 +0000 (Thu, 02 Oct 2014)
Log Message:
-----------
ShellPkg: Update SetVar to use existing attributes for updating existing 
variables.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <[email protected]>
Reviewed-by: Erik Bjorge <[email protected]>
Reviewed-by: Tapan Shah <[email protected]>

Modified Paths:
--------------
    trunk/edk2/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c

Modified: trunk/edk2/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c
===================================================================
--- trunk/edk2/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c     
2014-10-02 16:40:49 UTC (rev 16193)
+++ trunk/edk2/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c     
2014-10-02 16:41:28 UTC (rev 16194)
@@ -1,7 +1,7 @@
 /** @file
   Main file for SetVar shell Debug1 function.
 
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -44,7 +44,6 @@
   EFI_GUID            Guid;
   CONST CHAR16        *StringGuid;
   UINT32              Attributes;
-  UINT32              Attributes2;
   VOID                *Buffer;
   UINTN               Size;
   UINTN               LoopVar;
@@ -98,7 +97,7 @@
           ShellStatus = SHELL_INVALID_PARAMETER;
         }
       }
-      if (Data == NULL) {
+      if (Data == NULL || Data[0] !=  L'=') {
         //
         // Display what's there
         //
@@ -129,22 +128,43 @@
           ASSERT(ShellStatus == SHELL_SUCCESS);
         }
       } else {
-        if (Data[0] == L'=') {
-          Data++;
-        }
         //
-        // Change what's there
+        // Change what's there or create a new one.
         //
-        if (ShellCommandLineGetFlag(Package, L"-bs")) {
-          Attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
+
+        ASSERT(Data[0] == L'=');
+        Data++;
+
+        //
+        // Determine if the variable exists and get the attributes
+        //
+        Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes, 
&Size, Buffer);
+        if (Status == EFI_BUFFER_TOO_SMALL) {
+          Buffer = AllocateZeroPool(Size);
+          Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes, 
&Size, Buffer);
         }
-        if (ShellCommandLineGetFlag(Package, L"-rt")) {
-          Attributes |= EFI_VARIABLE_RUNTIME_ACCESS |
-                        EFI_VARIABLE_BOOTSERVICE_ACCESS;
+
+        if (EFI_ERROR(Status) || Buffer == NULL) {
+          //
+          // Creating a new variable.  determine attributes from command line.
+          //
+          Attributes = 0;
+          if (ShellCommandLineGetFlag(Package, L"-bs")) {
+            Attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
+          }
+          if (ShellCommandLineGetFlag(Package, L"-rt")) {
+            Attributes |= EFI_VARIABLE_RUNTIME_ACCESS |
+                          EFI_VARIABLE_BOOTSERVICE_ACCESS;
+          }
+          if (ShellCommandLineGetFlag(Package, L"-nv")) {
+            Attributes |= EFI_VARIABLE_NON_VOLATILE;
+          }
         }
-        if (ShellCommandLineGetFlag(Package, L"-nv")) {
-          Attributes |= EFI_VARIABLE_NON_VOLATILE;
-        }
+        SHELL_FREE_NON_NULL(Buffer);
+
+        //
+        // What type is the new data.
+        //
         if (ShellIsHexOrDecimalNumber(Data, TRUE, FALSE)) {
           if (StrLen(Data) % 2 != 0) {
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), 
gShellDebug1HiiHandle, Data);
@@ -171,17 +191,6 @@
             }
           }
         } else if (StrnCmp(Data, L"\"", 1) == 0) {
-          Size = 0;
-          Attributes2 = 0;
-          Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, 
&Attributes2, &Size, Buffer);
-          if (Status == EFI_BUFFER_TOO_SMALL) {
-            Buffer = AllocateZeroPool(Size);
-            Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, 
&Attributes2, &Size, Buffer);
-            if (Buffer != NULL) {
-              FreePool(Buffer);
-            }
-            Attributes = Attributes2;
-          }          
           //
           // ascii text
           //


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to