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.93; helo=mga11.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 59D492205BE9D for ; Tue, 2 Jan 2018 00:15:36 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jan 2018 00:20:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,495,1508828400"; d="scan'208";a="6802861" Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.192.34]) by fmsmga008.fm.intel.com with ESMTP; 02 Jan 2018 00:20:37 -0800 From: Jian J Wang To: edk2-devel@lists.01.org Cc: Liming Gao , Jiewen Yao , Star Zeng Date: Tue, 2 Jan 2018 16:20:21 +0800 Message-Id: <20180102082021.17792-3-jian.j.wang@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 In-Reply-To: <20180102082021.17792-1-jian.j.wang@intel.com> References: <20180102082021.17792-1-jian.j.wang@intel.com> Subject: [PATCH 2/2] MdeModulePkg/DxePrintLibPrint2Protocol: Fix incomplete print output 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: Tue, 02 Jan 2018 08:15:36 -0000 This is caused by a previous patch which tried to fix string over-read. It's found that that patch for PrintLib in MdePkg will cause premature terminating of loop used to traversing format string and cause incomplete string output. Because this library uses similar code to do the same job, it has the same issue too. So the fix is also the same. Cc: Liming Gao Cc: Jiewen Yao Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c index 0e6178fc9c..e09520c81b 100644 --- a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c +++ b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c @@ -2051,7 +2051,9 @@ InternalPrintLibSPrintMarker ( // ArgumentString is either null-terminated, or it contains Precision characters // for (Count = 0; - ArgumentString[Count * BytesPerArgumentCharacter] != '\0' && + (ArgumentString[Count * BytesPerArgumentCharacter] != '\0' || + (BytesPerArgumentCharacter > 1 && + ArgumentString[Count * BytesPerArgumentCharacter + 1]!= '\0')) && (Count < Precision || ((Flags & PRECISION) == 0)); Count++) { ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask; @@ -2110,7 +2112,9 @@ InternalPrintLibSPrintMarker ( // // Copy the string into the output buffer performing the required type conversions // - while (Index < Count && (*ArgumentString) != '\0') { + while (Index < Count && + (ArgumentString[0] != '\0' || + (BytesPerArgumentCharacter > 1 && ArgumentString[1] != '\0'))) { ArgumentCharacter = ((*ArgumentString & 0xff) | (((UINT8)*(ArgumentString + 1)) << 8)) & ArgumentMask; LengthToReturn += (1 * BytesPerOutputCharacter); -- 2.15.1.windows.2