]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg: Fixed GetEnvironmentVariable() when the UEFI Variable did not exist
authorOlivier Martin <olivier.martin@arm.com>
Wed, 2 Apr 2014 17:32:29 +0000 (17:32 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 2 Apr 2014 17:32:29 +0000 (17:32 +0000)
The function was allocating a buffer for the read value from the UEFI Variable.
But it was returning the pointer of the default value when the variable was
not present.
It could cause error when the default value and the returned value were free
when these addresses were the same (double FreePool on the same address).

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15427 6f19259b-4bc3-4df7-8a09-765794883524

ArmPkg/Include/Library/BdsLib.h
ArmPkg/Library/BdsLib/BdsHelper.c

index d16748da46f32818517a34585c3f150b524880c0..9fa687041860f2f74dbdcac2c9af6b676280d237 100644 (file)
@@ -66,6 +66,23 @@ BdsConnectAllDrivers (
   VOID\r
   );\r
 \r
+/**\r
+  Return the value of a global variable defined by its VariableName.\r
+  The variable must be defined with the VendorGuid gEfiGlobalVariableGuid.\r
+\r
+  @param  VariableName          A Null-terminated string that is the name of the vendor's\r
+                                variable.\r
+  @param  DefaultValue          Value returned by the function if the variable does not exist\r
+  @param  DataSize              On input, the size in bytes of the return Data buffer.\r
+                                On output the size of data returned in Data.\r
+  @param  Value                 Value read from the UEFI Variable or copy of the default value\r
+                                if the UEFI Variable does not exist\r
+\r
+  @retval EFI_SUCCESS           All drivers have been connected\r
+  @retval EFI_NOT_FOUND         No handles match the search.\r
+  @retval EFI_OUT_OF_RESOURCES  There is not resource pool memory to store the matching results.\r
+\r
+**/\r
 EFI_STATUS\r
 GetGlobalEnvironmentVariable (\r
   IN     CONST CHAR16*   VariableName,\r
@@ -74,6 +91,23 @@ GetGlobalEnvironmentVariable (
   OUT    VOID**          Value\r
   );\r
 \r
+/**\r
+  Return the value of the variable defined by its VariableName and VendorGuid\r
+\r
+  @param  VariableName          A Null-terminated string that is the name of the vendor's\r
+                                variable.\r
+  @param  VendorGuid            A unique identifier for the vendor.\r
+  @param  DefaultValue          Value returned by the function if the variable does not exist\r
+  @param  DataSize              On input, the size in bytes of the return Data buffer.\r
+                                On output the size of data returned in Data.\r
+  @param  Value                 Value read from the UEFI Variable or copy of the default value\r
+                                if the UEFI Variable does not exist\r
+\r
+  @retval EFI_SUCCESS           All drivers have been connected\r
+  @retval EFI_NOT_FOUND         No handles match the search.\r
+  @retval EFI_OUT_OF_RESOURCES  There is not resource pool memory to store the matching results.\r
+\r
+**/\r
 EFI_STATUS\r
 GetEnvironmentVariable (\r
   IN     CONST CHAR16*   VariableName,\r
index fb2ac9b8062ea5df9ef391ad519197664c52f88e..1d4aa3572840d7d3169949549069f9a330eefbdb 100644 (file)
@@ -331,7 +331,7 @@ GetEnvironmentVariable (
                     *Size,\r
                     DefaultValue\r
                     );\r
-      *Value = DefaultValue;\r
+      *Value = AllocateCopyPool (*Size, DefaultValue);\r
     } else {\r
       return EFI_NOT_FOUND;\r
     }\r
@@ -352,7 +352,7 @@ GetEnvironmentVariable (
       *Size = VariableSize;\r
     }\r
   } else {\r
-    *Value = DefaultValue;\r
+    *Value = AllocateCopyPool (*Size, DefaultValue);\r
     return Status;\r
   }\r
 \r