From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 9F5082034C087 for ; Thu, 19 Oct 2017 07:41:58 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Oct 2017 07:45:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,402,1503385200"; d="scan'208";a="165037628" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga006.fm.intel.com with ESMTP; 19 Oct 2017 07:45:35 -0700 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.182]) by fmsmsx107.amr.corp.intel.com ([169.254.6.9]) with mapi id 14.03.0319.002; Thu, 19 Oct 2017 07:45:35 -0700 From: "Carsey, Jaben" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] ShellPkg/editor: Fix system hang when console max column > 200 Thread-Index: AQHTSKGa7CSzljTNIEWg/7vC86pNhaLrQI/A Date: Thu, 19 Oct 2017 14:45:35 +0000 Message-ID: References: <20171019061458.378320-1-ruiyu.ni@intel.com> In-Reply-To: <20171019061458.378320-1-ruiyu.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNmNjMjZkNjUtN2U2OS00YjAyLWIzZjMtYjVlNzljYWM1ODFlIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6Ik1cLzVFYWEzSFJWUWxzWDk3VnlWcEV2UGNvQjdsalRSTVo3dUUyVEoyZWYwPSJ9 x-ctpclassification: CTP_IC x-originating-ip: [10.1.200.106] MIME-Version: 1.0 Subject: Re: [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: , X-List-Received-Date: Thu, 19 Oct 2017 14:41:59 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jaben Carsey > -----Original Message----- > From: Ni, Ruiyu > Sent: Wednesday, October 18, 2017 11:15 PM > To: edk2-devel@lists.01.org > Cc: Carsey, Jaben > Subject: [PATCH] ShellPkg/editor: Fix system hang when console max column > > 200 > Importance: High >=20 > 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. >=20 > The patch changes the function to print several times when > the max column is bigger than 200. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ruiyu Ni > Cc: Jaben Carsey > --- > .../UefiShellDebug1CommandsLib.c | 31 +++++++++++++---= ------ > 1 file changed, 19 insertions(+), 12 deletions(-) >=20 > diff --git > a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman > dsLib.c > b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman > dsLib.c > index 8e2141bf43..d26d08f95c 100644 > --- > a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman > dsLib.c > +++ > b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman > dsLib.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 firs= t line error > + // > + Line[(LastCol % (ARRAY_SIZE (Line) - 1)) - 1] =3D CHAR_NULL; > + } else { > + Line[LastCol % (ARRAY_SIZE (Line) - 1)] =3D CHAR_NULL; > + } > + } > + > // > - // if CHAR_NULL is still at position 80, it will cause first line er= ror > + // 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 > /** > -- > 2.12.2.windows.2