X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=ShellPkg%2FApplication%2FShell%2FShellManParser.c;h=0cbfbaabbaf4199f7a97b654d9b83d2f6e353f9f;hb=7f79b01e8ef43901785dbccc1f4676cdf9a53d31;hp=525c9343bd96c9481ab78287eb07d74404b6e9d2;hpb=8ac6e336ff573f6105d4f776bdf7db1d189c7093;p=mirror_edk2.git diff --git a/ShellPkg/Application/Shell/ShellManParser.c b/ShellPkg/Application/Shell/ShellManParser.c index 525c9343bd..0cbfbaabba 100644 --- a/ShellPkg/Application/Shell/ShellManParser.c +++ b/ShellPkg/Application/Shell/ShellManParser.c @@ -1,7 +1,7 @@ /** @file Provides interface to shell MAN file parser. - Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 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 @@ -39,15 +39,12 @@ GetManFileName( // Fix the file name // if (StrnCmp(ManFileName+StrLen(ManFileName)-4, L".man", 4)==0) { - Buffer = AllocateZeroPool(StrSize(ManFileName)); - if (Buffer != NULL) { - StrCpy(Buffer, ManFileName); - } + Buffer = AllocateCopyPool(StrSize(ManFileName), ManFileName); } else { Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16)); if (Buffer != NULL) { - StrCpy(Buffer, ManFileName); - StrCat(Buffer, L".man"); + StrnCpy(Buffer, ManFileName, StrLen(ManFileName)); + StrnCat(Buffer, L".man", 4); } } return (Buffer); @@ -374,6 +371,9 @@ ManBufferFindTitleSection( CHAR16 *TitleString; CHAR16 *TitleEnd; CHAR16 *CurrentLocation; + UINTN TitleLength; + CONST CHAR16 StartString[] = L".TH "; + CONST CHAR16 EndString[] = L" 0 "; if ( Buffer == NULL || Command == NULL @@ -384,13 +384,17 @@ ManBufferFindTitleSection( Status = EFI_SUCCESS; - TitleString = AllocateZeroPool((7*sizeof(CHAR16)) + StrSize(Command)); + // + // more characters for StartString and EndString + // + TitleLength = StrSize(Command) + (StrLen(StartString) + StrLen(EndString)) * sizeof(CHAR16); + TitleString = AllocateZeroPool(TitleLength); if (TitleString == NULL) { return (EFI_OUT_OF_RESOURCES); } - StrCpy(TitleString, L".TH "); - StrCat(TitleString, Command); - StrCat(TitleString, L" 0 "); + StrnCpy(TitleString, StartString, TitleLength/sizeof(CHAR16) - 1); + StrnCat(TitleString, Command, TitleLength/sizeof(CHAR16) - 1 - StrLen(TitleString)); + StrnCat(TitleString, EndString, TitleLength/sizeof(CHAR16) - 1 - StrLen(TitleString)); CurrentLocation = StrStr(*Buffer, TitleString); if (CurrentLocation == NULL){ @@ -467,6 +471,7 @@ ManFileFindTitleSection( CHAR16 *TitleEnd; UINTN TitleLen; BOOLEAN Found; + UINTN TitleSize; if ( Handle == NULL || Command == NULL @@ -484,13 +489,14 @@ ManFileFindTitleSection( return (EFI_OUT_OF_RESOURCES); } - TitleString = AllocateZeroPool((4*sizeof(CHAR16)) + StrSize(Command)); + TitleSize = (4*sizeof(CHAR16)) + StrSize(Command); + TitleString = AllocateZeroPool(TitleSize); if (TitleString == NULL) { FreePool(ReadLine); return (EFI_OUT_OF_RESOURCES); } - StrCpy(TitleString, L".TH "); - StrCat(TitleString, Command); + StrnCpy(TitleString, L".TH ", TitleSize/sizeof(CHAR16) - 1); + StrnCat(TitleString, Command, TitleSize/sizeof(CHAR16) - 1 - StrLen(TitleString)); TitleLen = StrLen(TitleString); for (;!ShellFileHandleEof(Handle);Size = 1024) { @@ -526,7 +532,7 @@ ManFileFindTitleSection( Status = EFI_OUT_OF_RESOURCES; break; } - StrCpy(*BriefDesc, TitleEnd); + StrnCpy(*BriefDesc, TitleEnd, (*BriefSize)/sizeof(CHAR16) - 1); } break; }