From nobody Mon Dec 23 09:40:09 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 1518362282167488.4073942650226; Sun, 11 Feb 2018 07:18:02 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EB5F5222DE157; Sun, 11 Feb 2018 07:12:09 -0800 (PST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 C4989223DB795 for ; Sun, 11 Feb 2018 07:12:08 -0800 (PST) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Feb 2018 07:17:55 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.37]) by fmsmga007.fm.intel.com with ESMTP; 11 Feb 2018 07:17:54 -0800 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=134.134.136.31; helo=mga06.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,496,1511856000"; d="scan'208";a="16932674" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Sun, 11 Feb 2018 23:17:52 +0800 Message-Id: <20180211151752.468524-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.16.1.windows.1 Subject: [edk2] [PATCH] ShellPkg/help: Fix "-?" may not show manual sometimes Shell core was enhanced to find the manual string in PE resource section. But the finding algorithm is too strict: If the manual is written beginning with: .TH command 0 "descripton of command" X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 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" but user types "COMMAND.efi -?". The finding algorithm uses case-sensitive compare between "command" and "COMMAND" resulting in the manual cannot be found. The patch fixes this issue by using existing ManFileFindTitleSection and ManFileFindSections which compare command case-insensitive. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Jaben Carsey --- ShellPkg/Application/Shell/FileHandleWrappers.c | 52 ++++- ShellPkg/Application/Shell/ShellManParser.c | 275 ++------------------= ---- 2 files changed, 73 insertions(+), 254 deletions(-) diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/App= lication/Shell/FileHandleWrappers.c index 0a7a60294d..63aad69fe8 100644 --- a/ShellPkg/Application/Shell/FileHandleWrappers.c +++ b/ShellPkg/Application/Shell/FileHandleWrappers.c @@ -3,7 +3,7 @@ StdIn, StdOut, StdErr, etc...). =20 Copyright 2016 Dell Inc. - Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2013 Hewlett-Packard Development Company, L.P.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License @@ -1554,6 +1554,54 @@ FileInterfaceMemGetPosition( return (EFI_SUCCESS); } =20 +/** + File style interface for Mem (GetInfo). + + @param This Protocol instance pointer. + @param InformationType Type of information to return in Buffer. + @param BufferSize On input size of buffer, on output amount of dat= a in buffer. + @param Buffer The buffer to return data. + + @retval EFI_SUCCESS Data was returned. + @retval EFI_UNSUPPORT InformationType is not supported. + @retval EFI_NO_MEDIA The device has no media. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED The device is write protected. + @retval EFI_ACCESS_DENIED The file was open for read only. + @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returne= d in BufferSize. + +**/ +EFI_STATUS +EFIAPI +FileInterfaceMemGetInfo( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + EFI_FILE_INFO *FileInfo; + + if (CompareGuid (InformationType, &gEfiFileInfoGuid)) { + if (*BufferSize < sizeof (EFI_FILE_INFO)) { + *BufferSize =3D sizeof (EFI_FILE_INFO); + return EFI_BUFFER_TOO_SMALL; + } + if (Buffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + FileInfo =3D (EFI_FILE_INFO *)Buffer; + FileInfo->Size =3D sizeof (*FileInfo); + ZeroMem (FileInfo, sizeof (*FileInfo)); + FileInfo->FileSize =3D ((EFI_FILE_PROTOCOL_MEM*)This)->FileSize; + FileInfo->PhysicalSize =3D FileInfo->FileSize; + return EFI_SUCCESS; + } + + return EFI_UNSUPPORTED; +} + /** File style interface for Mem (Write). =20 @@ -1689,7 +1737,7 @@ CreateFileInterfaceMem( FileInterface->Close =3D FileInterfaceMemClose; FileInterface->GetPosition =3D FileInterfaceMemGetPosition; FileInterface->SetPosition =3D FileInterfaceMemSetPosition; - FileInterface->GetInfo =3D FileInterfaceNopGetInfo; + FileInterface->GetInfo =3D FileInterfaceMemGetInfo; FileInterface->SetInfo =3D FileInterfaceNopSetInfo; FileInterface->Flush =3D FileInterfaceNopGeneric; FileInterface->Delete =3D FileInterfaceNopGeneric; diff --git a/ShellPkg/Application/Shell/ShellManParser.c b/ShellPkg/Applica= tion/Shell/ShellManParser.c index 7a290e16f6..975f3c22da 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. =20 - Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
Copyright 2015 Dell Inc. This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License @@ -205,138 +205,6 @@ SearchPathForFile( return (Status); } =20 -/** - parses through Buffer (which is MAN file formatted) and returns the - detailed help for any sub section specified in the comma seperated list = of - sections provided. If the end of the file or a .TH section is found then - return. - - Upon a sucessful return the caller is responsible to free the memory in = *HelpText - - @param[in] Buffer Buffer to read from - @param[in] Sections name of command's sub sections to find - @param[in] HelpText pointer to pointer to string where text go= es. - @param[in] HelpSize pointer to size of allocated HelpText (may= be updated) - - @retval EFI_OUT_OF_RESOURCES a memory allocation failed. - @retval EFI_SUCCESS the section was found and its description = sotred in - an alloceted buffer. -**/ -EFI_STATUS -ManBufferFindSections( - IN CONST CHAR16 *Buffer, - IN CONST CHAR16 *Sections, - IN CHAR16 **HelpText, - IN UINTN *HelpSize - ) -{ - EFI_STATUS Status; - CONST CHAR16 *CurrentLocation; - BOOLEAN CurrentlyReading; - CHAR16 *SectionName; - UINTN SectionLen; - BOOLEAN Found; - CHAR16 *TempString; - CHAR16 *TempString2; - - if ( Buffer =3D=3D NULL - || HelpText =3D=3D NULL - || HelpSize =3D=3D NULL - ){ - return (EFI_INVALID_PARAMETER); - } - - Status =3D EFI_SUCCESS; - CurrentlyReading =3D FALSE; - Found =3D FALSE; - - for (CurrentLocation =3D Buffer,TempString =3D NULL - ; CurrentLocation !=3D NULL && *CurrentLocation !=3D CHAR_NULL - ; CurrentLocation=3DStrStr(CurrentLocation, L"\r\n"),TempString =3D N= ULL - ){ - while(CurrentLocation[0] =3D=3D L'\r' || CurrentLocation[0] =3D=3D L'\= n') { - CurrentLocation++; - } - if (CurrentLocation[0] =3D=3D L'#') { - // - // Skip comment lines - // - continue; - } - if (StrnCmp(CurrentLocation, L".TH", 3) =3D=3D 0) { - // - // we hit the end of this commands section so stop. - // - break; - } - if (StrnCmp(CurrentLocation, L".SH ", 4) =3D=3D 0) { - if (Sections =3D=3D NULL) { - CurrentlyReading =3D TRUE; - continue; - } else if (CurrentlyReading) { - CurrentlyReading =3D FALSE; - } - CurrentLocation +=3D 4; - // - // is this a section we want to read in? - // - if (StrLen(CurrentLocation)!=3D0) { - TempString2 =3D StrStr(CurrentLocation, L" "); - TempString2 =3D MIN(TempString2, StrStr(CurrentLocation, L"\r")); - TempString2 =3D MIN(TempString2, StrStr(CurrentLocation, L"\n")); - ASSERT(TempString =3D=3D NULL); - TempString =3D StrnCatGrow(&TempString, NULL, CurrentLocation, Tem= pString2=3D=3DNULL?0:TempString2 - CurrentLocation); - if (TempString =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - break; - } - SectionName =3D TempString; - SectionLen =3D StrLen(SectionName); - SectionName =3D StrStr(Sections, SectionName); - if (SectionName =3D=3D NULL) { - SHELL_FREE_NON_NULL(TempString); - continue; - } - if (*(SectionName + SectionLen) =3D=3D CHAR_NULL || *(SectionName = + SectionLen) =3D=3D L',') { - CurrentlyReading =3D TRUE; - } - } - } else if (CurrentlyReading) { - Found =3D TRUE; - if (StrLen(CurrentLocation)!=3D0) { - TempString2 =3D StrStr(CurrentLocation, L"\r"); - TempString2 =3D MIN(TempString2, StrStr(CurrentLocation, L"\n")); - ASSERT(TempString =3D=3D NULL); - TempString =3D StrnCatGrow(&TempString, NULL, CurrentLocation, Tem= pString2=3D=3DNULL?0:TempString2 - CurrentLocation); - if (TempString =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - break; - } - // - // copy and save the current line. - // - ASSERT((*HelpText =3D=3D NULL && *HelpSize =3D=3D 0) || (*HelpText= !=3D NULL)); - StrnCatGrow (HelpText, HelpSize, TempString, 0); - if (HelpText =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - break; - } - StrnCatGrow (HelpText, HelpSize, L"\r\n", 0); - if (HelpText =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - break; - } - } - } - SHELL_FREE_NON_NULL(TempString); - } - SHELL_FREE_NON_NULL(TempString); - if (!Found && !EFI_ERROR(Status)) { - return (EFI_NOT_FOUND); - } - return (Status); -} - /** parses through the MAN file specified by SHELL_FILE_HANDLE and returns t= he detailed help for any sub section specified in the comma seperated list = of @@ -452,111 +320,6 @@ ManFileFindSections( return (Status); } =20 -/** - parses through the MAN file formatted Buffer and returns the - "Brief Description" for the .TH section as specified by Command. If the - command section is not found return EFI_NOT_FOUND. - - Upon a sucessful return the caller is responsible to free the memory in = *BriefDesc - - @param[in] Buffer Buffer to read from - @param[in] Command name of command's section to find - @param[in] BriefDesc pointer to pointer to string where descrip= tion goes. - @param[in] BriefSize pointer to size of allocated BriefDesc - - @retval EFI_OUT_OF_RESOURCES a memory allocation failed. - @retval EFI_SUCCESS the section was found and its description = sotred in - an alloceted buffer. -**/ -EFI_STATUS -ManBufferFindTitleSection( - IN CHAR16 **Buffer, - IN CONST CHAR16 *Command, - IN CHAR16 **BriefDesc, - IN UINTN *BriefSize - ) -{ - EFI_STATUS Status; - CHAR16 *TitleString; - CHAR16 *TitleEnd; - CHAR16 *CurrentLocation; - UINTN TitleLength; - UINTN Start; - CONST CHAR16 StartString[] =3D L".TH "; - CONST CHAR16 EndString[] =3D L" 0 "; - - if ( Buffer =3D=3D NULL - || Command =3D=3D NULL - || (BriefDesc !=3D NULL && BriefSize =3D=3D NULL) - ){ - return (EFI_INVALID_PARAMETER); - } - - Status =3D EFI_SUCCESS; - - // - // Do not pass any leading path information that may be present to IsTit= leHeader(). - // - Start =3D StrLen(Command); - while ((Start !=3D 0) - && (*(Command + Start - 1) !=3D L'\\') - && (*(Command + Start - 1) !=3D L'/') - && (*(Command + Start - 1) !=3D L':')) { - --Start; - } - - // - // more characters for StartString and EndString - // - TitleLength =3D StrSize(Command + Start) + (StrLen(StartString) + StrLen= (EndString)) * sizeof(CHAR16); - TitleString =3D AllocateZeroPool(TitleLength); - if (TitleString =3D=3D NULL) { - return (EFI_OUT_OF_RESOURCES); - } - StrCpyS(TitleString, TitleLength/sizeof(CHAR16), StartString); - StrCatS(TitleString, TitleLength/sizeof(CHAR16), Command + Start); - StrCatS(TitleString, TitleLength/sizeof(CHAR16), EndString); - - CurrentLocation =3D StrStr(*Buffer, TitleString); - if (CurrentLocation =3D=3D NULL){ - Status =3D EFI_NOT_FOUND; - } else { - // - // we found it so copy out the rest of the line into BriefDesc - // After skipping any spaces or zeroes - // - for (CurrentLocation +=3D StrLen(TitleString) - ; *CurrentLocation =3D=3D L' ' || *CurrentLocation =3D=3D L'0' || *= CurrentLocation =3D=3D L'1' || *CurrentLocation =3D=3D L'\"' - ; CurrentLocation++); - - TitleEnd =3D StrStr(CurrentLocation, L"\""); - if (TitleEnd =3D=3D NULL) { - Status =3D EFI_DEVICE_ERROR; - } else { - if (BriefDesc !=3D NULL) { - *BriefSize =3D StrSize(TitleEnd); - *BriefDesc =3D AllocateZeroPool(*BriefSize); - if (*BriefDesc =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - } else { - StrnCpyS(*BriefDesc, (*BriefSize)/sizeof(CHAR16), CurrentLocatio= n, TitleEnd-CurrentLocation); - } - } - - for (CurrentLocation =3D TitleEnd - ; *CurrentLocation !=3D L'\n' - ; CurrentLocation++); - for ( - ; *CurrentLocation =3D=3D L' ' || *CurrentLocation =3D=3D L'\n' |= | *CurrentLocation =3D=3D L'\r' - ; CurrentLocation++); - *Buffer =3D CurrentLocation; - } - } - - FreePool(TitleString); - return (Status); -} - /** Parses a line from a MAN file to see if it is the Title Header. If it is= , then if the "Brief Description" is desired, allocate a buffer for it and retu= rn a @@ -813,10 +576,8 @@ ProcessManFile( UINTN BriefSize; UINTN StringIdWalker; BOOLEAN Ascii; - CHAR16 *TempString2; CHAR16 *CmdFileName; CHAR16 *CmdFilePathName; - CHAR16 *StringBuff; EFI_DEVICE_PATH_PROTOCOL *FileDevPath; EFI_DEVICE_PATH_PROTOCOL *DevPath; EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; @@ -836,7 +597,6 @@ ProcessManFile( CmdFileName =3D NULL; CmdFilePathName =3D NULL; CmdFileImgHandle =3D NULL; - StringBuff =3D NULL; PackageListHeader =3D NULL; FileDevPath =3D NULL; DevPath =3D NULL; @@ -846,11 +606,17 @@ ProcessManFile( // TempString =3D ShellCommandGetCommandHelp(Command); if (TempString !=3D NULL) { - TempString2 =3D TempString; - Status =3D ManBufferFindTitleSection(&TempString2, Command, BriefDesc,= &BriefSize); + FileHandle =3D ConvertEfiFileProtocolToShellHandle (CreateFileInterfac= eMem (TRUE), NULL); + HelpSize =3D StrLen (TempString) * sizeof (CHAR16); + ShellWriteFile (FileHandle, &HelpSize, TempString); + ShellSetFilePosition (FileHandle, 0); + HelpSize =3D 0; + BriefSize =3D 0; + Status =3D ManFileFindTitleSection(FileHandle, Command, BriefDesc, &Br= iefSize, &Ascii); if (!EFI_ERROR(Status) && HelpText !=3D NULL){ - Status =3D ManBufferFindSections(TempString2, Sections, HelpText, &H= elpSize); + Status =3D ManFileFindSections(FileHandle, Sections, HelpText, &Help= Size, Ascii); } + ShellCloseFile (&FileHandle); } else { // // If the image is a external app, check .MAN file first. @@ -947,20 +713,26 @@ ProcessManFile( =20 StringIdWalker =3D 1; do { - SHELL_FREE_NON_NULL(StringBuff); + SHELL_FREE_NON_NULL(TempString); if (BriefDesc !=3D NULL) { SHELL_FREE_NON_NULL(*BriefDesc); } - StringBuff =3D HiiGetString (mShellManHiiHandle, (EFI_STRING_ID)St= ringIdWalker, NULL); - if (StringBuff =3D=3D NULL) { + TempString =3D HiiGetString (mShellManHiiHandle, (EFI_STRING_ID)St= ringIdWalker, NULL); + if (TempString =3D=3D NULL) { Status =3D EFI_NOT_FOUND; goto Done; } - TempString2 =3D StringBuff; - Status =3D ManBufferFindTitleSection(&TempString2, Command, BriefD= esc, &BriefSize); + FileHandle =3D ConvertEfiFileProtocolToShellHandle (CreateFileInte= rfaceMem (TRUE), NULL); + HelpSize =3D StrLen (TempString) * sizeof (CHAR16); + ShellWriteFile (FileHandle, &HelpSize, TempString); + ShellSetFilePosition (FileHandle, 0); + HelpSize =3D 0; + BriefSize =3D 0; + Status =3D ManFileFindTitleSection(FileHandle, Command, BriefDesc,= &BriefSize, &Ascii); if (!EFI_ERROR(Status) && HelpText !=3D NULL){ - Status =3D ManBufferFindSections(TempString2, Sections, HelpText= , &HelpSize); + Status =3D ManFileFindSections(FileHandle, Sections, HelpText, &= HelpSize, Ascii); } + ShellCloseFile (&FileHandle); if (!EFI_ERROR(Status)){ // // Found what we need and return @@ -969,7 +741,7 @@ ProcessManFile( } =20 StringIdWalker +=3D 1; - } while (StringIdWalker < 0xFFFF && StringBuff !=3D NULL); + } while (StringIdWalker < 0xFFFF && TempString !=3D NULL); =20 } =20 @@ -992,7 +764,6 @@ Done: Status =3D gBS->UnloadImage (CmdFileImgHandle); } =20 - SHELL_FREE_NON_NULL(StringBuff); SHELL_FREE_NON_NULL(TempString); SHELL_FREE_NON_NULL(CmdFileName); SHELL_FREE_NON_NULL(CmdFilePathName); --=20 2.16.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel