From 81cd2f536ef0097392b51f96405321ce7b01350c Mon Sep 17 00:00:00 2001 From: Eric Dong Date: Thu, 26 Jun 2014 01:38:46 +0000 Subject: Refine code to make it more safely. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong Reviewed-by: Jaben Carsey git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15593 6f19259b-4bc3-4df7-8a09-765794883524 --- .../UefiShellDebug1CommandsLib/Edit/FileBuffer.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c') diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c index 179559833e..897700bd34 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c @@ -1,7 +1,7 @@ /** @file Implements filebuffer interface functions. - Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.
+ Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -489,8 +489,9 @@ FileBufferPrintLine ( CHAR16 *Buffer; UINTN Limit; - CHAR16 PrintLine[200]; - CHAR16 PrintLine2[250]; + CHAR16 *PrintLine; + CHAR16 *PrintLine2; + UINTN BufLen; // // print start from correct character @@ -502,13 +503,21 @@ FileBufferPrintLine ( Limit = 0; } - StrnCpy (PrintLine, Buffer, MIN(MIN(Limit,MainEditor.ScreenSize.Column), 200)); + BufLen = (MainEditor.ScreenSize.Column + 1) * sizeof (CHAR16); + PrintLine = AllocatePool (BufLen); + ASSERT (PrintLine != NULL); + + StrnCpy (PrintLine, Buffer, MIN(Limit, MainEditor.ScreenSize.Column)); for (; Limit < MainEditor.ScreenSize.Column; Limit++) { PrintLine[Limit] = L' '; } PrintLine[MainEditor.ScreenSize.Column] = CHAR_NULL; - ShellCopySearchAndReplace(PrintLine, PrintLine2, 250, L"%", L"^%", FALSE, FALSE); + + PrintLine2 = AllocatePool (BufLen * 2); + ASSERT (PrintLine2 != NULL); + + ShellCopySearchAndReplace(PrintLine, PrintLine2, BufLen * 2, L"%", L"^%", FALSE, FALSE); ShellPrintEx ( 0, @@ -517,6 +526,9 @@ FileBufferPrintLine ( PrintLine2 ); + FreePool (PrintLine); + FreePool (PrintLine2); + return EFI_SUCCESS; } -- cgit v1.2.3