Current GetVariable implementation will return the first variable for
empty str VariableName, it is because GetVariable and GetNextVariablename
are sharing same function FindVariable.
But UEFI sepc defines SetVariable that If VariableName is an empty string,
then EFI_INVALID_PARAMETER is returned, that means an empty string variable
could never be set successfully, so GetVariable should return error for
empty string VariableName.

Cc: Jiewen Yao <jiewen....@intel.com>
Cc: Feng Tian <feng.t...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.z...@intel.com>
---
 MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c | 6 +++++-
 MdeModulePkg/Universal/Variable/Pei/Variable.c              | 6 +++++-
 MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c       | 4 ++++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c 
b/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c
index 977332e1cf49..27ea1496a044 100644
--- a/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c
+++ b/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c
@@ -3,7 +3,7 @@
   Emulation Variable services operate on the runtime volatile memory.
   The nonvolatile variable space doesn't exist.
 
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2016, 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
@@ -1183,6 +1183,10 @@ EmuGetVariable (
     return EFI_INVALID_PARAMETER;
   }
 
+  if (VariableName[0] == 0) {
+    return EFI_NOT_FOUND;
+  }
+
   AcquireLockOnlyAtBootTime(&Global->VariableServicesLock);
 
   //
diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c 
b/MdeModulePkg/Universal/Variable/Pei/Variable.c
index c68a41ddfe7d..a072c31e60e7 100644
--- a/MdeModulePkg/Universal/Variable/Pei/Variable.c
+++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c
@@ -2,7 +2,7 @@
   Implement ReadOnly Variable Services required by PEIM and install
   PEI ReadOnly Varaiable2 PPI. These services operates the non volatile 
storage space.
 
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2016, 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
@@ -978,6 +978,10 @@ PeiGetVariable (
     return EFI_INVALID_PARAMETER;
   }
 
+  if (VariableName[0] == 0) {
+    return EFI_NOT_FOUND;
+  }
+
   VariableHeader = NULL;
 
   //
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c 
b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
index 3f0240bc072f..17475be32386 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -2849,6 +2849,10 @@ VariableServiceGetVariable (
     return EFI_INVALID_PARAMETER;
   }
 
+  if (VariableName[0] == 0) {
+    return EFI_NOT_FOUND;
+  }
+
   
AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
 
   Status = FindVariable (VariableName, VendorGuid, &Variable, 
&mVariableModuleGlobal->VariableGlobal, FALSE);
-- 
2.7.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to