public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] MdeModulePkg/UefiHiiLib: Fix incorrect check for string length
@ 2017-08-29  6:44 Dandan Bi
  2017-08-29  7:25 ` Dong, Eric
  0 siblings, 1 reply; 2+ messages in thread
From: Dandan Bi @ 2017-08-29  6:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: Eric Dong, Liming Gao

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>
---
 MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
index cd0cd35..5249392 100644
--- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
+++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
@@ -1605,11 +1605,11 @@ ValidateQuestionFromVfr (
           IfrString = (EFI_IFR_STRING *) IfrOpHdr;
           if (IfrString->Question.VarStoreId != VarStoreData.VarStoreId) {
             break;
           }
           //
-          // Get Width by OneOf Flags
+          // Get the Max size of the string.
           //
           Width  = (UINT16) (IfrString->MaxSize * sizeof (UINT16));
           if (NameValueType) {
             QuestionName = HiiGetString (HiiHandle, IfrString->Question.VarStoreInfo.VarName, NULL);
             ASSERT (QuestionName != NULL);
@@ -1619,20 +1619,29 @@ ValidateQuestionFromVfr (
               //
               // This question is not in the current configuration string. Skip it.
               //
               break;
             }
+            //
+            // Skip the VarName.
+            //
+            StringPtr += StrLen (QuestionName);
 
             //
             // Skip the "=".
             // 
             StringPtr += 1;
             
             //
             // Check current string length is less than maxsize
+            // e.g Config String: "0041004200430044", Unicode String: "ABCD". Unicode String length = Config String length / 4.
+            // Config string format in UEFI spec.
+            // <NvConfig> ::= <Label>'='<String>
+            // <String> ::= [<Char>]+
+            // <Char> ::= <HexCh>4
             //
-            if (StrSize (StringPtr) > Width) {
+            if (StrLen (StringPtr) / 4 > IfrString->MaxSize) {
               return EFI_INVALID_PARAMETER;
             }
           } else {
             //
             // Get Offset/Width by Question header and OneOf Flags
@@ -1658,11 +1667,11 @@ ValidateQuestionFromVfr (
             }
 
             //
             // Check current string length is less than maxsize
             //
-            if (StrSize ((CHAR16 *) (VarBuffer + Offset)) > Width) {
+            if (StrLen ((CHAR16 *) (VarBuffer + Offset)) > IfrString->MaxSize) {
               return EFI_INVALID_PARAMETER;
             }
           }
           break;
         case EFI_IFR_ONE_OF_OPTION_OP:
-- 
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] MdeModulePkg/UefiHiiLib: Fix incorrect check for string length
  2017-08-29  6:44 [PATCH v2] MdeModulePkg/UefiHiiLib: Fix incorrect check for string length Dandan Bi
@ 2017-08-29  7:25 ` Dong, Eric
  0 siblings, 0 replies; 2+ messages in thread
From: Dong, Eric @ 2017-08-29  7:25 UTC (permalink / raw)
  To: Bi, Dandan, edk2-devel@lists.01.org; +Cc: Gao, Liming

Reviewed-by: Eric Dong <eric.dong@intel.com>

-----Original Message-----
From: Bi, Dandan 
Sent: Tuesday, August 29, 2017 2:45 PM
To: edk2-devel@lists.01.org
Cc: Dong, Eric <eric.dong@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [PATCH v2] MdeModulePkg/UefiHiiLib: Fix incorrect check for string length

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>
---
 MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
index cd0cd35..5249392 100644
--- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
+++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
@@ -1605,11 +1605,11 @@ ValidateQuestionFromVfr (
           IfrString = (EFI_IFR_STRING *) IfrOpHdr;
           if (IfrString->Question.VarStoreId != VarStoreData.VarStoreId) {
             break;
           }
           //
-          // Get Width by OneOf Flags
+          // Get the Max size of the string.
           //
           Width  = (UINT16) (IfrString->MaxSize * sizeof (UINT16));
           if (NameValueType) {
             QuestionName = HiiGetString (HiiHandle, IfrString->Question.VarStoreInfo.VarName, NULL);
             ASSERT (QuestionName != NULL); @@ -1619,20 +1619,29 @@ ValidateQuestionFromVfr (
               //
               // This question is not in the current configuration string. Skip it.
               //
               break;
             }
+            //
+            // Skip the VarName.
+            //
+            StringPtr += StrLen (QuestionName);
 
             //
             // Skip the "=".
             // 
             StringPtr += 1;
             
             //
             // Check current string length is less than maxsize
+            // e.g Config String: "0041004200430044", Unicode String: "ABCD". Unicode String length = Config String length / 4.
+            // Config string format in UEFI spec.
+            // <NvConfig> ::= <Label>'='<String>
+            // <String> ::= [<Char>]+
+            // <Char> ::= <HexCh>4
             //
-            if (StrSize (StringPtr) > Width) {
+            if (StrLen (StringPtr) / 4 > IfrString->MaxSize) {
               return EFI_INVALID_PARAMETER;
             }
           } else {
             //
             // Get Offset/Width by Question header and OneOf Flags @@ -1658,11 +1667,11 @@ ValidateQuestionFromVfr (
             }
 
             //
             // Check current string length is less than maxsize
             //
-            if (StrSize ((CHAR16 *) (VarBuffer + Offset)) > Width) {
+            if (StrLen ((CHAR16 *) (VarBuffer + Offset)) > 
+ IfrString->MaxSize) {
               return EFI_INVALID_PARAMETER;
             }
           }
           break;
         case EFI_IFR_ONE_OF_OPTION_OP:
--
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-29  7:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-29  6:44 [PATCH v2] MdeModulePkg/UefiHiiLib: Fix incorrect check for string length Dandan Bi
2017-08-29  7:25 ` Dong, Eric

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox