]> 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 06df161e5debdd6beb3eb9228a220f0c29a35b94..5feeade10d2f6f0ac5dc7fdf11dec92734940beb 100644 (file)
@@ -6,7 +6,7 @@ disk. They can be changed by user. BIOS is not able to protoect those.
 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 - 2016, Intel Corporation. All rights reserved.<BR>\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
@@ -1337,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
@@ -1383,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
@@ -1396,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