]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
Refine code to make it more safely.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Edit / FileBuffer.c
index 179559833eec5d17bc52ee0926f3409cc7e51854..897700bd341bd7a0b5e085fc8f2ac26314fe3cac 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implements filebuffer interface functions.\r
 \r
-  Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -489,8 +489,9 @@ FileBufferPrintLine (
 \r
   CHAR16  *Buffer;\r
   UINTN   Limit;\r
-  CHAR16  PrintLine[200];\r
-  CHAR16  PrintLine2[250];\r
+  CHAR16  *PrintLine;\r
+  CHAR16  *PrintLine2;\r
+  UINTN   BufLen; \r
 \r
   //\r
   // print start from correct character\r
@@ -502,13 +503,21 @@ FileBufferPrintLine (
     Limit = 0;\r
   }\r
 \r
-  StrnCpy (PrintLine, Buffer, MIN(MIN(Limit,MainEditor.ScreenSize.Column), 200));\r
+  BufLen = (MainEditor.ScreenSize.Column + 1) * sizeof (CHAR16);\r
+  PrintLine = AllocatePool (BufLen);\r
+  ASSERT (PrintLine != NULL);\r
+\r
+  StrnCpy (PrintLine, Buffer, MIN(Limit, MainEditor.ScreenSize.Column));\r
   for (; Limit < MainEditor.ScreenSize.Column; Limit++) {\r
     PrintLine[Limit] = L' ';\r
   }\r
 \r
   PrintLine[MainEditor.ScreenSize.Column] = CHAR_NULL;\r
-  ShellCopySearchAndReplace(PrintLine, PrintLine2,  250, L"%", L"^%", FALSE, FALSE);\r
+\r
+  PrintLine2 = AllocatePool (BufLen * 2);\r
+  ASSERT (PrintLine2 != NULL);\r
+\r
+  ShellCopySearchAndReplace(PrintLine, PrintLine2, BufLen * 2, L"%", L"^%", FALSE, FALSE);\r
 \r
   ShellPrintEx (\r
     0,\r
@@ -517,6 +526,9 @@ FileBufferPrintLine (
     PrintLine2\r
     );\r
 \r
+  FreePool (PrintLine);\r
+  FreePool (PrintLine2);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r