]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiHiiLib/HiiLib.c
MdeModulePkg/UefiHiiLib: Fix incorrect check for string length
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLib.c
index cd0cd35a0f304600e30cc2133a1d234681af049c..583b9e516c65645d06c6e98cc674fd9f6bd1ff3e 100644 (file)
@@ -1607,7 +1607,7 @@ ValidateQuestionFromVfr (
             break;\r
           }\r
           //\r
-          // Get Width by OneOf Flags\r
+          // Get the Max size of the string.\r
           //\r
           Width  = (UINT16) (IfrString->MaxSize * sizeof (UINT16));\r
           if (NameValueType) {\r
@@ -1621,6 +1621,10 @@ ValidateQuestionFromVfr (
               //\r
               break;\r
             }\r
+            //\r
+            // Skip the VarName.\r
+            //\r
+            StringPtr += StrLen (QuestionName);\r
 \r
             //\r
             // Skip the "=".\r
@@ -1629,8 +1633,13 @@ ValidateQuestionFromVfr (
             \r
             //\r
             // Check current string length is less than maxsize\r
+            // e.g Config String: "0041004200430044", Unicode String: "ABCD". Unicode String length = Config String length / 4.\r
+            // Config string format in UEFI spec.\r
+            // <NvConfig> ::= <Label>'='<String>\r
+            // <String> ::= [<Char>]+\r
+            // <Char> ::= <HexCh>4\r
             //\r
-            if (StrSize (StringPtr) > Width) {\r
+            if (StrLen (StringPtr) / 4 > IfrString->MaxSize) {\r
               return EFI_INVALID_PARAMETER;\r
             }\r
           } else {\r
@@ -1660,7 +1669,7 @@ ValidateQuestionFromVfr (
             //\r
             // Check current string length is less than maxsize\r
             //\r
-            if (StrSize ((CHAR16 *) (VarBuffer + Offset)) > Width) {\r
+            if (StrLen ((CHAR16 *) (VarBuffer + Offset)) > IfrString->MaxSize) {\r
               return EFI_INVALID_PARAMETER;\r
             }\r
           }\r