From nobody Fri May 3 09:01:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1514428716913296.26466878581596; Wed, 27 Dec 2017 18:38:36 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E97A52219BCB4; Wed, 27 Dec 2017 18:33:37 -0800 (PST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 E982B21CB87A9 for ; Wed, 27 Dec 2017 18:33:35 -0800 (PST) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Dec 2017 18:38:32 -0800 Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.192.35]) by orsmga008.jf.intel.com with ESMTP; 27 Dec 2017 18:38:30 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,468,1508828400"; d="scan'208";a="6081048" From: Jian J Wang To: edk2-devel@lists.01.org Date: Thu, 28 Dec 2017 10:38:27 +0800 Message-Id: <20171228023828.18752-2-jian.j.wang@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 In-Reply-To: <20171228023828.18752-1-jian.j.wang@intel.com> References: <20171228023828.18752-1-jian.j.wang@intel.com> Subject: [edk2] [PATCH v2 1/2] MdePkg/BasePrintLib: Fix error in 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: , Cc: Michael D Kinney , Jiewen Yao , Star Zeng , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" > 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 Cc: Liming Gao Cc: Jiewen Yao Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang Reviewed-by: Liming Gao Reviewed-by: Star Zeng --- MdePkg/Library/BasePrintLib/PrintLibInternal.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Librar= y/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 i= n Count // ArgumentString is either null-terminated, or it contains Precisio= n characters // - for (Count =3D 0; Count < Precision || ((Flags & PRECISION) =3D=3D 0= ); Count++) { + for (Count =3D 0; + ArgumentString[Count * BytesPerArgumentCharacter] !=3D '\0' && + (Count < Precision || ((Flags & PRECISION) =3D=3D 0)); + Count++) { ArgumentCharacter =3D ((ArgumentString[Count * BytesPerArgumentCha= racter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) = << 8)) & ArgumentMask; if (ArgumentCharacter =3D=3D 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) !=3D '\0') { ArgumentCharacter =3D ((*ArgumentString & 0xff) | (((UINT8)*(Argumen= tString + 1)) << 8)) & ArgumentMask; =20 LengthToReturn +=3D (1 * BytesPerOutputCharacter); --=20 2.15.1.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Fri May 3 09:01:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1514428721519705.8272107211516; Wed, 27 Dec 2017 18:38:41 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4C48B21CB87C7; Wed, 27 Dec 2017 18:33:40 -0800 (PST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 58F2A21CB87C4 for ; Wed, 27 Dec 2017 18:33:37 -0800 (PST) Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Dec 2017 18:38:33 -0800 Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.192.35]) by orsmga008.jf.intel.com with ESMTP; 27 Dec 2017 18:38:32 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,468,1508828400"; d="scan'208";a="6081056" From: Jian J Wang To: edk2-devel@lists.01.org Date: Thu, 28 Dec 2017 10:38:28 +0800 Message-Id: <20171228023828.18752-3-jian.j.wang@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 In-Reply-To: <20171228023828.18752-1-jian.j.wang@intel.com> References: <20171228023828.18752-1-jian.j.wang@intel.com> Subject: [edk2] [PATCH v2 2/2] MdeModulePkg/DxePrintLibPrint2Protocol: Fix potential string over read 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: , Cc: Michael D Kinney , Jiewen Yao , Star Zeng , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" > v2: > Add in v2 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 Cc: Liming Gao Cc: Jiewen Yao Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang Reviewed-by: Liming Gao Reviewed-by: Star Zeng --- MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c b/Md= eModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c index 56534e56c3..570d06d82e 100644 --- a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c +++ b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c @@ -2050,7 +2050,10 @@ InternalPrintLibSPrintMarker ( // Compute the number of characters in ArgumentString and store it i= n Count // ArgumentString is either null-terminated, or it contains Precisio= n characters // - for (Count =3D 0; Count < Precision || ((Flags & PRECISION) =3D=3D 0= ); Count++) { + for (Count =3D 0; + ArgumentString[Count * BytesPerArgumentCharacter] !=3D '\0' && + Count < Precision || ((Flags & PRECISION) =3D=3D 0); + Count++) { ArgumentCharacter =3D ((ArgumentString[Count * BytesPerArgumentCha= racter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) = << 8)) & ArgumentMask; if (ArgumentCharacter =3D=3D 0) { break; @@ -2107,7 +2110,7 @@ InternalPrintLibSPrintMarker ( // // Copy the string into the output buffer performing the required type= conversions // - while (Index < Count) { + while (Index < Count && (*ArgumentString) !=3D '\0') { ArgumentCharacter =3D ((*ArgumentString & 0xff) | (((UINT8)*(Argumen= tString + 1)) << 8)) & ArgumentMask; =20 LengthToReturn +=3D (1 * BytesPerOutputCharacter); --=20 2.15.1.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel