]> git.proxmox.com Git - mirror_edk2.git/blobdiff - DuetPkg/FSVariable/FSVariable.c
BaseTools/BinToPcd: Fix Python 2.7.x compatibility issue
[mirror_edk2.git] / DuetPkg / FSVariable / FSVariable.c
index 50729060c21deef1c65031ea57ae6003b1e641ce..5feeade10d2f6f0ac5dc7fdf11dec92734940beb 100644 (file)
@@ -1,6 +1,12 @@
 /*++\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Caution: This file is used for Duet platform only, do not use them in real platform.\r
+All variable code, variable metadata, and variable data used by Duet platform are on \r
+disk. They can be changed by user. BIOS is not able to protoect those.\r
+Duet trusts all meta data from disk. If variable code, variable metadata and variable\r
+data is modified in inproper way, the behavior is undefined.\r
+\r
+Copyright (c) 2006 - 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
@@ -1299,7 +1305,7 @@ DuetGetVariable (
   IN      EFI_GUID          *VendorGuid,\r
   OUT     UINT32            *Attributes OPTIONAL,\r
   IN OUT  UINTN             *DataSize,\r
-  OUT     VOID              *Data\r
+  OUT     VOID              *Data OPTIONAL\r
   )\r
 /*++\r
 \r
@@ -1314,7 +1320,8 @@ Arguments:
   Attributes OPTIONAL             Attribute value of the variable found\r
   DataSize                        Size of Data found. If size is less than the\r
                                   data, this value contains the required size.\r
-  Data                            Data pointer\r
+  Data                            The buffer to return the contents of the variable. May be NULL\r
+                                  with a zero DataSize in order to determine the size buffer needed.\r
 \r
 Returns:\r
 \r
@@ -1330,6 +1337,10 @@ Returns:
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (VariableName[0] == 0) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
   //\r
   // Find existing variable\r
   //\r
@@ -1376,7 +1387,8 @@ Routine Description:
 \r
 Arguments:\r
 \r
-  VariableNameSize            Size of the variable\r
+  VariableNameSize            The size of the VariableName buffer. The size must be large\r
+                              enough to fit input string supplied in VariableName buffer.\r
   VariableName                Pointer to variable name\r
   VendorGuid                  Variable Vendor Guid\r
 \r
@@ -1389,14 +1401,40 @@ Returns:
   VARIABLE_POINTER_TRACK  Variable;\r
   UINTN                   VarNameSize;\r
   EFI_STATUS              Status;\r
+  UINTN                   MaxLen;\r
 \r
   if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  //\r
+  // Calculate the possible maximum length of name string, including the Null terminator.\r
+  //\r
+  MaxLen = *VariableNameSize / sizeof (CHAR16);\r
+  if ((MaxLen == 0) || (StrnLenS (VariableName, MaxLen) == MaxLen)) {\r
+    //\r
+    // Null-terminator is not found in the first VariableNameSize bytes of the input VariableName buffer,\r
+    // follow spec to return EFI_INVALID_PARAMETER.\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   Status = FindVariable (VariableName, VendorGuid, &Variable);\r
 \r
   if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
+    //\r
+    // For VariableName is an empty string, FindVariable() will try to find and return\r
+    // the first qualified variable, and if FindVariable() returns error (EFI_NOT_FOUND)\r
+    // as no any variable is found, still go to return the error (EFI_NOT_FOUND).\r
+    //\r
+    if (VariableName[0] != 0) {\r
+      //\r
+      // For VariableName is not an empty string, and FindVariable() returns error as\r
+      // VariableName and VendorGuid are not a name and GUID of an existing variable,\r
+      // there is no way to get next variable, follow spec to return EFI_INVALID_PARAMETER.\r
+      //\r
+      Status = EFI_INVALID_PARAMETER;\r
+    }\r
     return Status;\r
   }\r
 \r