public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Nate DeSimone" <nathaniel.l.desimone@intel.com>
To: devel@edk2.groups.io
Cc: Chasel Chiu <chasel.chiu@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Eric Dong <eric.dong@intel.com>
Subject: [edk2-platforms] [PATCH V1 1/2] MinPlatformPkg: Add missing bounds checks to CompressLib
Date: Tue, 29 Sep 2020 17:15:28 -0700	[thread overview]
Message-ID: <20200930001529.2212-2-nathaniel.l.desimone@intel.com> (raw)
In-Reply-To: <20200930001529.2212-1-nathaniel.l.desimone@intel.com>

Current code only as bounds checks in ASSERT macros.
They are also needed in release mode where ASSERT is not used.

Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
---
 .../MinPlatformPkg/Library/CompressLib/CompressLib.c   | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Library/CompressLib/CompressLib.c b/Platform/Intel/MinPlatformPkg/Library/CompressLib/CompressLib.c
index 9f93e1ee2d..537eb3b693 100644
--- a/Platform/Intel/MinPlatformPkg/Library/CompressLib/CompressLib.c
+++ b/Platform/Intel/MinPlatformPkg/Library/CompressLib/CompressLib.c
@@ -1002,7 +1002,10 @@ CountTFreq (
         mTFreq[2]++;
       }
     } else {
-      ASSERT((LoopVar3+2)<(2 * NT - 1));
+      ASSERT ((LoopVar3 + 2) < (2 * NT - 1));
+      if ((LoopVar3 + 2) >= (2 * NT - 1)) {
+        return;
+      }
       mTFreq[LoopVar3 + 2]++;
     }
   }
@@ -1101,7 +1104,10 @@ WriteCLen (
         PutBits (CBIT, Count - 20);
       }
     } else {
-      ASSERT((LoopVar3+2)<NPT);
+      ASSERT ((LoopVar3 + 2) < NPT);
+      if ((LoopVar3 + 2) >= NPT) {
+        return;
+      }
       PutBits (mPTLen[LoopVar3 + 2], mPTCode[LoopVar3 + 2]);
     }
   }
-- 
2.27.0.windows.1


  reply	other threads:[~2020-09-30  0:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-30  0:15 [edk2-platforms] [PATCH V1 0/2] MinPlatformPkg: Minor fixes in CompressLib Nate DeSimone
2020-09-30  0:15 ` Nate DeSimone [this message]
2020-10-01 17:25   ` [edk2-platforms] [PATCH V1 1/2] MinPlatformPkg: Add missing bounds checks to CompressLib Chiu, Chasel
2020-09-30  0:15 ` [edk2-platforms] [PATCH V1 2/2] MinPlatformPkg: Coding style cleanups in CompressLib Nate DeSimone
2020-10-01 17:25   ` Chiu, Chasel

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=20200930001529.2212-2-nathaniel.l.desimone@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