From nobody Sat May 4 00:26:46 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 1508393703548435.66250368025; Wed, 18 Oct 2017 23:15:03 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1EC2420347146; Wed, 18 Oct 2017 23:11:24 -0700 (PDT) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 D548520347143 for ; Wed, 18 Oct 2017 23:11:22 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP; 18 Oct 2017 23:15:00 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.7]) by fmsmga001.fm.intel.com with ESMTP; 18 Oct 2017 23:14:59 -0700 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=192.55.52.43; helo=mga05.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,400,1503385200"; d="scan'208";a="1207485363" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Thu, 19 Oct 2017 14:14:58 +0800 Message-Id: <20171019061458.378320-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 Subject: [edk2] [PATCH] ShellPkg/editor: Fix system hang when console max column > 200 X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jaben Carsey 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" EditorClearLine() assumes the console max column is less than 200. When the max column is bigger than 200, the code incorrectly modifies the content out side of Line buffer. It may cause system hang or reset. The patch changes the function to print several times when the max column is bigger than 200. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Jaben Carsey Reviewed-by: Jaben Carsey --- .../UefiShellDebug1CommandsLib.c | 31 +++++++++++++-----= ---- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Com= mandsLib.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Com= mandsLib.c index 8e2141bf43..d26d08f95c 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.c @@ -185,6 +185,7 @@ EditorClearLine ( IN UINTN LastRow ) { + UINTN Col; CHAR16 Line[200]; =20 if (Row =3D=3D 0) { @@ -193,22 +194,28 @@ EditorClearLine ( =20 // // prepare a blank line + // If max column is larger, split to multiple prints. // - SetMem16(Line, LastCol*sizeof(CHAR16), L' '); - - if (Row =3D=3D LastRow) { + SetMem16 (Line, sizeof (Line), L' '); + Line[ARRAY_SIZE (Line) - 1] =3D CHAR_NULL; + + for (Col =3D 1; Col <=3D LastCol; Col +=3D ARRAY_SIZE (Line) - 1) { + if (Col + ARRAY_SIZE (Line) - 1 > LastCol) { + if (Row =3D=3D LastRow) { + // + // if CHAR_NULL is still at position LastCol, it will cause first = line error + // + Line[(LastCol % (ARRAY_SIZE (Line) - 1)) - 1] =3D CHAR_NULL; + } else { + Line[LastCol % (ARRAY_SIZE (Line) - 1)] =3D CHAR_NULL; + } + } +=20 // - // if CHAR_NULL is still at position 80, it will cause first line error + // print out the blank line // - Line[LastCol - 1] =3D CHAR_NULL; - } else { - Line[LastCol] =3D CHAR_NULL; + ShellPrintEx ((INT32) Col - 1, (INT32) Row - 1, Line); } - - // - // print out the blank line - // - ShellPrintEx (0, ((INT32)Row) - 1, Line); } =20 /** --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel