]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
MdeModulePkg Variable: Use comparison logic to check UINTN parameter
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / Variable.c
index 6caf603b3d305f41b43c45c966a6957a014bff31..835a66bc3bc8f8f4a2dfa6ad75ffdebed96cd6bf 100644 (file)
@@ -16,8 +16,8 @@
   VariableServiceSetVariable() should also check authenticate data to avoid buffer overflow,\r
   integer overflow. It should also check attribute to avoid authentication bypass.\r
 \r
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
-(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2015-2018 Hewlett Packard Enterprise Development LP<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
@@ -238,6 +238,8 @@ IsValidVariableHeader (
   @param Buffer                  Pointer to the buffer from which data is written.\r
 \r
   @retval EFI_INVALID_PARAMETER  Parameters not valid.\r
+  @retval EFI_UNSUPPORTED        Fvb is a NULL for Non-Volatile variable update.\r
+  @retval EFI_OUT_OF_RESOURCES   The remaining size is not enough.\r
   @retval EFI_SUCCESS            Variable store successfully updated.\r
 \r
 **/\r
@@ -274,7 +276,7 @@ UpdateVariableStore (
   //\r
   if (!Volatile) {\r
     if (Fvb == NULL) {\r
-      return EFI_INVALID_PARAMETER;\r
+      return EFI_UNSUPPORTED;\r
     }\r
     Status = Fvb->GetPhysicalAddress(Fvb, &FvVolHdr);\r
     ASSERT_EFI_ERROR (Status);\r
@@ -288,8 +290,8 @@ UpdateVariableStore (
       DataPtr += mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase;\r
     }\r
 \r
-    if ((DataPtr + DataSize) >= ((EFI_PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) FwVolHeader + FwVolHeader->FvLength))) {\r
-      return EFI_INVALID_PARAMETER;\r
+    if ((DataPtr + DataSize) > ((EFI_PHYSICAL_ADDRESS) (UINTN) ((UINT8 *) FwVolHeader + FwVolHeader->FvLength))) {\r
+      return EFI_OUT_OF_RESOURCES;\r
     }\r
   } else {\r
     //\r
@@ -301,8 +303,8 @@ UpdateVariableStore (
       DataPtr += mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;\r
     }\r
 \r
-    if ((DataPtr + DataSize) >= ((UINTN) ((UINT8 *) VolatileBase + VolatileBase->Size))) {\r
-      return EFI_INVALID_PARAMETER;\r
+    if ((DataPtr + DataSize) > ((UINTN) ((UINT8 *) VolatileBase + VolatileBase->Size))) {\r
+      return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
     //\r
@@ -1531,8 +1533,8 @@ GetLangFromSupportedLangCodes (
   @param[in]  SupportedLanguages  A pointer to a Null-terminated ASCII string that\r
                                   contains a set of language codes in the format\r
                                   specified by Iso639Language.\r
-  @param[in]  Iso639Language      If TRUE, then all language codes are assumed to be\r
-                                  in ISO 639-2 format.  If FALSE, then all language\r
+  @param[in]  Iso639Language      If not zero, then all language codes are assumed to be\r
+                                  in ISO 639-2 format.  If zero, then all language\r
                                   codes are assumed to be in RFC 4646 language format\r
   @param[in]  ...                 A variable argument list that contains pointers to\r
                                   Null-terminated ASCII strings that contain one or more\r
@@ -1560,7 +1562,7 @@ CHAR8 *
 EFIAPI\r
 VariableGetBestLanguage (\r
   IN CONST CHAR8  *SupportedLanguages,\r
-  IN BOOLEAN      Iso639Language,\r
+  IN UINTN        Iso639Language,\r
   ...\r
   )\r
 {\r
@@ -1586,7 +1588,7 @@ VariableGetBestLanguage (
     //\r
     // If in RFC 4646 mode, then determine the length of the first RFC 4646 language code in Language\r
     //\r
-    if (!Iso639Language) {\r
+    if (Iso639Language == 0) {\r
       for (LanguageLength = 0; Language[LanguageLength] != 0 && Language[LanguageLength] != ';'; LanguageLength++);\r
     }\r
 \r
@@ -1601,7 +1603,7 @@ VariableGetBestLanguage (
         //\r
         // In RFC 4646 mode, then Loop through all language codes in SupportedLanguages\r
         //\r
-        if (!Iso639Language) {\r
+        if (Iso639Language == 0) {\r
           //\r
           // Skip ';' characters in Supported\r
           //\r
@@ -1623,13 +1625,13 @@ VariableGetBestLanguage (
         if (AsciiStrnCmp (Supported, Language, LanguageLength) == 0) {\r
           VA_END (Args);\r
 \r
-          Buffer = Iso639Language ? mVariableModuleGlobal->Lang : mVariableModuleGlobal->PlatformLang;\r
+          Buffer = (Iso639Language != 0) ? mVariableModuleGlobal->Lang : mVariableModuleGlobal->PlatformLang;\r
           Buffer[CompareLength] = '\0';\r
           return CopyMem (Buffer, Supported, CompareLength);\r
         }\r
       }\r
 \r
-      if (Iso639Language) {\r
+      if (Iso639Language != 0) {\r
         //\r
         // If ISO 639 mode, then each language can only be tested once\r
         //\r