public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Dong, Eric" <eric.dong@intel.com>
To: "Bi, Dandan" <dandan.bi@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Gao, Liming" <liming.gao@intel.com>
Subject: Re: [patch] MdeModulePkg/UefiHiiLib: Fix incorrect check for string length
Date: Tue, 29 Aug 2017 05:33:36 +0000	[thread overview]
Message-ID: <ED077930C258884BBCB450DB737E66224A9D6A6C@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <1503889775-332544-1-git-send-email-dandan.bi@intel.com>

Dandan,

Please add more comments why " / 4" is correct here.

+            // e.g Config String: "0041004200430044", Unicode String: "ABCD". Unicode String length = Config String length / 4.
             //
-            if (StrSize (StringPtr) > Width) {
+            if (StrLen (StringPtr) / 4 > IfrString->MaxSize) {



Thanks,
Eric
-----Original Message-----
From: Bi, Dandan 
Sent: Monday, August 28, 2017 11:10 AM
To: edk2-devel@lists.01.org
Cc: Dong, Eric <eric.dong@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [patch] 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 the 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 | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
index cd0cd35..d89e5f3 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,25 @@ 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.
             //
-            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 +1663,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



      reply	other threads:[~2017-08-29  5:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-28  3:09 [patch] MdeModulePkg/UefiHiiLib: Fix incorrect check for string length Dandan Bi
2017-08-29  5:33 ` Dong, Eric [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ED077930C258884BBCB450DB737E66224A9D6A6C@shsmsx102.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox