From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D995821CB87AC for ; Sun, 24 Dec 2017 18:03:57 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Dec 2017 18:08:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,453,1508828400"; d="scan'208";a="189779778" Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.192.64]) by fmsmga006.fm.intel.com with ESMTP; 24 Dec 2017 18:08:49 -0800 From: Jian J Wang To: edk2-devel@lists.01.org Cc: Michael D Kinney , Liming Gao , Jiewen Yao , Star Zeng Date: Mon, 25 Dec 2017 10:08:47 +0800 Message-Id: <20171225020847.14076-1-jian.j.wang@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 Subject: [PATCH] MdePkg/BasePrintLib: Fix incorrect Precision position calculation X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Dec 2017 02:03:58 -0000 Due to the a potential hole in the stop condition of for-loop, the two continuous access to ArgumentString (index, index+1) inside the loop might cause the string ending character ('\0') to be read. Cc: Michael D Kinney Cc: Liming Gao Cc: Jiewen Yao Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdePkg/Library/BasePrintLib/PrintLibInternal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Library/BasePrintLib/PrintLibInternal.c index 28d946472f..297d5a05b5 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; -- 2.15.1.windows.2