]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/UefiHiiLib: Fix incorrect check for string length
authorBi, Dandan <dandan.bi@intel.com>
Tue, 29 Aug 2017 06:44:37 +0000 (14:44 +0800)
committerEric Dong <eric.dong@intel.com>
Tue, 29 Aug 2017 07:57:12 +0000 (15:57 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=681

For string opcode,when checking the valid string length,
it should exclude the Null-terminated character.
And for string in NameValue storage, need to exclude
the varname and also need to convert the Config string
length to Unicode string length.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
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