From: Jian J Wang <jian.j.wang@intel.com>
To: edk2-devel@lists.01.org
Cc: Michael D Kinney <michael.d.kinney@intel.com>,
Liming Gao <liming.gao@intel.com>,
Jiewen Yao <jiewen.yao@intel.com>,
Star Zeng <star.zeng@intel.com>
Subject: [PATCH v2 1/2] MdePkg/BasePrintLib: Fix error in Precision position calculation
Date: Thu, 28 Dec 2017 10:38:27 +0800 [thread overview]
Message-ID: <20171228023828.18752-2-jian.j.wang@intel.com> (raw)
In-Reply-To: <20171228023828.18752-1-jian.j.wang@intel.com>
> v2:
> a. Correct incorrect description in commit log
> b. Fix another similar issue in the same function
Due to a potential hole in the stop condition of loop, the two continuous
access to ArgumentString (index, index+1) inside the loop might cause the
string ending character ('\0') and the byte after it to be read.
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
---
MdePkg/Library/BasePrintLib/PrintLibInternal.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Library/BasePrintLib/PrintLibInternal.c
index 28d946472f..fc57255068 100644
--- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c
+++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c
@@ -1107,7 +1107,10 @@ BasePrintLibSPrintMarker (
// Compute the number of characters in ArgumentString and store it in Count
// ArgumentString is either null-terminated, or it contains Precision characters
//
- for (Count = 0; Count < Precision || ((Flags & PRECISION) == 0); Count++) {
+ for (Count = 0;
+ ArgumentString[Count * BytesPerArgumentCharacter] != '\0' &&
+ (Count < Precision || ((Flags & PRECISION) == 0));
+ Count++) {
ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;
if (ArgumentCharacter == 0) {
break;
@@ -1164,7 +1167,7 @@ BasePrintLibSPrintMarker (
//
// Copy the string into the output buffer performing the required type conversions
//
- while (Index < Count) {
+ while (Index < Count && (*ArgumentString) != '\0') {
ArgumentCharacter = ((*ArgumentString & 0xff) | (((UINT8)*(ArgumentString + 1)) << 8)) & ArgumentMask;
LengthToReturn += (1 * BytesPerOutputCharacter);
--
2.15.1.windows.2
next prev parent reply other threads:[~2017-12-28 2:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-28 2:38 [PATCH v2 0/2] Fix error in PrintLib Jian J Wang
2017-12-28 2:38 ` Jian J Wang [this message]
[not found] ` <CAKv+Gu_W-0etAXve+1Vn-hDL9A-9Oror-L6nCtt9_UqRxkhhCw@mail.gmail.com>
2018-01-02 8:23 ` [PATCH v2 1/2] MdePkg/BasePrintLib: Fix error in Precision position calculation Wang, Jian J
2017-12-28 2:38 ` [PATCH v2 2/2] MdeModulePkg/DxePrintLibPrint2Protocol: Fix potential string over read Jian J Wang
2017-12-28 2:43 ` [PATCH v2 0/2] Fix error in PrintLib Gao, Liming
2017-12-28 3:10 ` Zeng, Star
2017-12-29 1:07 ` Kinney, Michael D
2017-12-29 1:41 ` Wang, Jian J
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=20171228023828.18752-2-jian.j.wang@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