From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 036B681901 for ; Tue, 27 Dec 2016 15:01:23 -0800 (PST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP; 27 Dec 2016 15:01:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,418,1477983600"; d="scan'208,217";a="46968453" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga005.jf.intel.com with ESMTP; 27 Dec 2016 15:01:22 -0800 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 27 Dec 2016 15:01:22 -0800 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.47]) by fmsmsx116.amr.corp.intel.com ([169.254.2.162]) with mapi id 14.03.0248.002; Tue, 27 Dec 2016 15:01:22 -0800 From: "Carsey, Jaben" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" CC: "Chen, Chen A" , "Carsey, Jaben" Thread-Topic: [PATCH 2/2] ShellPkg/cd: Fix "cd" to support "fs0:dir" (no slash after ':') Thread-Index: AQHSW2f2cx9geD9isESb/k2EGUKhv6ESlZLggAL4kwCABuULgA== Date: Tue, 27 Dec 2016 23:01:21 +0000 Message-ID: References: <20161221085501.159796-1-ruiyu.ni@intel.com> <20161221085501.159796-3-ruiyu.ni@intel.com> <734D49CCEBEEF84792F5B80ED585239D5B86005E@SHSMSX104.ccr.corp.intel.com> In-Reply-To: <734D49CCEBEEF84792F5B80ED585239D5B86005E@SHSMSX104.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYWYwZWMzNjUtODVjMS00NWMyLTk1NWItNjg0NjVjZjQ4MTlkIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IjEwY2hjeE84VFJ1MWxWWFZlV2NjYk85cGUxUzUyRld0UitmcVV0SlwvaVEwPSJ9 x-ctpclassification: CTP_IC x-originating-ip: [10.1.200.107] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: Re: [PATCH 2/2] ShellPkg/cd: Fix "cd" to support "fs0:dir" (no slash after ':') X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Dec 2016 23:01:24 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Right. The question is can the user from the shell prompt trigger the asse= rt. I didn't see clear protection from the users input to the function's a= ssert. -Jaben From: Ni, Ruiyu Sent: Thursday, December 22, 2016 9:43 PM To: Carsey, Jaben ; edk2-devel@lists.01.org Cc: Carsey, Jaben ; Chen, Chen A Subject: RE: [PATCH 2/2] ShellPkg/cd: Fix "cd" to support "fs0:dir" (no sla= sh after ':') Importance: High Jaben, The assertion is to check caller instead of check user's input. It's to make sure future modification won't break the parameter assumption = of this function. It's like the below assertion in StrCpy: ASSERT (Destination !=3D NULL); ASSERT (((UINTN) Destination & BIT0) =3D=3D 0); Regards, Ray From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Cars= ey, Jaben Sent: Thursday, December 22, 2016 12:23 AM To: Ni, Ruiyu >; edk2-devel@l= ists.01.org Cc: Carsey, Jaben >; = Chen, Chen A > Subject: Re: [edk2] [PATCH 2/2] ShellPkg/cd: Fix "cd" to support "fs0:dir" = (no slash after ':') > -----Original Message----- > From: Ni, Ruiyu > Sent: Wednesday, December 21, 2016 12:55 AM > To: edk2-devel@lists.01.org > Cc: Chen, Chen A >; C= arsey, Jaben > > > Subject: [PATCH 2/2] ShellPkg/cd: Fix "cd" to support "fs0:dir" (no slash= after > ':') > Importance: High > > When "fs0:dir"(drive letter without slash) is used as destination > of "cd", "cd" tries to change to "dir" in root directory of "fs0:". > It's incorrect. The correct behavior is to change to "dir" in > current directory of "fs0:" > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ruiyu Ni > > Signed-off-by: Chen A Chen > > Cc: Jaben Carsey > > --- > ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c | 415 +++++++++++++-- > -------- > 1 file changed, 240 insertions(+), 175 deletions(-) > > diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c > b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c > index 0967bc7..0b4becf 100644 > --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c > +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c > @@ -17,6 +17,156 @@ > #include "UefiShellLevel2CommandsLib.h" > > /** > + Function will replace drive identifier with CWD. > + > + If FullPath begining with ':' is invalid path, then ASSERT. Is there any way for the user from the shell prompt to hit the ASSERT? Is = there a good reason to use ASSERT and not just return an error (NULL for ex= ample)? > + If FullPath not include dirve identifier , then do nothing. > + If FullPath likes "fs0:\xx" or "fs0:/xx" , then do nothing. > + If FullPath likes "fs0:xxx" or "fs0:", the drive replaced by CWD. > + > + @param[in, out] FullPath The pointer to the string containing the= path. > + @param[in] Cwd Current directory. > + > + @retval EFI_SUCCESS Success. > + @retval EFI_OUT_OF_SOURCES A memory allocation failed. > +**/ > +EFI_STATUS > +ReplaceDriveWithCwd( > + IN OUT CHAR16 **FullPath, > + IN CONST CHAR16 *Cwd > + ) > +{ > + CHAR16 *Splitter; > + CHAR16 *TempBuffer; > + UINTN TotalSize; > + > + Splitter =3D NULL; > + TempBuffer =3D NULL; > + TotalSize =3D 0; > + > + if (FullPath =3D=3D NULL || *FullPath =3D=3D NULL) { > + return EFI_SUCCESS; > + } > + > + Splitter =3D StrStr (*FullPath, L":"); > + ASSERT(Splitter !=3D *FullPath); > + > + if (Splitter !=3D NULL && *(Splitter + 1) !=3D L'\\' && *(Splitter + 1= ) !=3D L'/') { > + TotalSize =3D StrSize (Cwd) + StrSize (Splitter + 1); > + TempBuffer =3D AllocateZeroPool (TotalSize); > + if (TempBuffer =3D=3D NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + > + StrCpyS (TempBuffer, TotalSize / sizeof(CHAR16), Cwd); > + StrCatS (TempBuffer, TotalSize / sizeof(CHAR16), L"\\"); > + StrCatS (TempBuffer, TotalSize / sizeof(CHAR16), Splitter + 1); > + > + FreePool(*FullPath); > + *FullPath =3D TempBuffer; > + } > + > + return EFI_SUCCESS; > +} > + > +/** > + function to determine if FullPath is under current filesystem. > + > + @param[in] FullPath The target location to determine. > + @param[in] Cwd Current directory. > + > + @retval TRUE The FullPath is in the current filesystem. > + @retval FALSE The FullPaht isn't in the current filesystem= . > +**/ > +BOOLEAN > +IsCurrentFileSystem( > + IN CONST CHAR16 *FullPath, > + IN CONST CHAR16 *Cwd > + ) > +{ > + CHAR16 *Splitter1; > + CHAR16 *Splitter2; > + > + Splitter1 =3D NULL; > + Splitter2 =3D NULL; > + > + ASSERT(FullPath !=3D NULL); > + > + Splitter1 =3D StrStr (FullPath, L":"); > + if (Splitter1 =3D=3D NULL) { > + return TRUE; > + } > + > + Splitter2 =3D StrStr (Cwd, L":"); > + > + if ((UINTN)(Splitter1 - FullPath) !=3D (UINTN)(Splitter2 - Cwd)) { > + return FALSE; > + } else { > + if (StrniCmp(FullPath, Cwd, (UINTN)(Splitter1 - FullPath)) =3D=3D NU= LL) { > + return TRUE; > + } else { > + return FALSE; > + } > + } > +} > + > +/** > + Extract drive string and path string from FullPath. > + > + The caller must be free Drive and Path. > + > + @param[in] FullPath A path to be extracted. > + @param[out] Drive Buffer to save drive identifier. > + @param[out] Path Buffer to save path. > + > + @retval EFI_SUCCESS Success. > + @retval EFI_OUT_OF_RESOUCES A memory allocation failed. > +**/ > +EFI_STATUS > +ExtractDriveAndPath( > + IN CONST CHAR16 *FullPath, > + OUT CHAR16 **Drive, > + OUT CHAR16 **Path > + ) > +{ > + CHAR16 *Splitter; > + > + ASSERT(FullPath !=3D NULL); > + > + Splitter =3D StrStr (FullPath, L":"); > + > + if (Splitter =3D=3D NULL) { > + *Drive =3D NULL; > + *Path =3D AllocateCopyPool (StrSize (FullPath), FullPath); > + if (*Path =3D=3D NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + } else { > + if (*(Splitter + 1) =3D=3D CHAR_NULL) { > + *Drive =3D AllocateCopyPool (StrSize (FullPath), FullPath); > + *Path =3D NULL; > + if (*Drive =3D=3D NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + } else { > + *Drive =3D AllocateCopyPool((Splitter - FullPath + 2) * sizeof(CHA= R16), > FullPath); > + if (*Drive =3D=3D NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + (*Drive)[Splitter - FullPath + 1] =3D CHAR_NULL; > + > + *Path =3D AllocateCopyPool (StrSize (Splitter + 1), Splitter + 1); > + if (*Path =3D=3D NULL) { > + FreePool(*Drive); > + return EFI_OUT_OF_RESOURCES; > + } > + } > + } > + > + return EFI_SUCCESS; > +} > + > +/** > Function for 'cd' command. > > @param[in] ImageHandle Handle to the Image (NULL if Internal). > @@ -31,23 +181,26 @@ ShellCommandRunCd ( > { > EFI_STATUS Status; > LIST_ENTRY *Package; > - CONST CHAR16 *Directory; > - CHAR16 *Cwd; > + CONST CHAR16 *Cwd; > CHAR16 *Path; > CHAR16 *Drive; > - UINTN CwdSize; > - UINTN DriveSize; > CHAR16 *ProblemParam; > SHELL_STATUS ShellStatus; > - SHELL_FILE_HANDLE Handle; > CONST CHAR16 *Param1; > CHAR16 *Param1Copy; > - CHAR16* Walker; > + CHAR16 *Walker; > + CHAR16 *Splitter; > + CHAR16 *TempBuffer; > + UINTN TotalSize; > > - ProblemParam =3D NULL; > - ShellStatus =3D SHELL_SUCCESS; > - Drive =3D NULL; > - DriveSize =3D 0; > + ProblemParam =3D NULL; > + ShellStatus =3D SHELL_SUCCESS; > + Cwd =3D NULL; > + Path =3D NULL; > + Drive =3D NULL; > + Splitter =3D NULL; > + TempBuffer =3D NULL; > + TotalSize =3D 0; > > Status =3D CommandInit(); > ASSERT_EFI_ERROR(Status); > @@ -87,194 +240,106 @@ ShellCommandRunCd ( > // else If there are 2 value parameters, then print the error messag= e > // else If there is 1 value paramerer , then change the directory > // > - Param1 =3D ShellCommandLineGetRawValue(Package, 1); > - if (Param1 =3D=3D NULL) { > - // > - // display the current directory > - // > - Directory =3D ShellGetCurrentDir(NULL); > - if (Directory !=3D NULL) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), > gShellLevel2HiiHandle, Directory); > - } else { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), > gShellLevel2HiiHandle, L"cd"); > - ShellStatus =3D SHELL_NOT_FOUND; > - } > + Cwd =3D ShellGetCurrentDir (NULL); > + if (Cwd =3D=3D NULL) { > + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_GEN_NO_CWD), > gShellLevel2HiiHandle, L"cd"); > + ShellStatus =3D SHELL_NOT_FOUND; > } else { > - Param1Copy =3D CatSPrint(NULL, L"%s", Param1, NULL); > - for (Walker =3D Param1Copy; Walker !=3D NULL && *Walker !=3D CHAR_= NULL ; > Walker++) { > - if (*Walker =3D=3D L'\"') { > - CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]))= ; > + Param1 =3D ShellCommandLineGetRawValue(Package, 1); > + if (Param1 =3D=3D NULL) { > + // > + // display the current directory > + // > + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_CD_PRINT), > gShellLevel2HiiHandle, Cwd); > + } else { > + Param1Copy =3D CatSPrint(NULL, L"%s", Param1, NULL); > + for (Walker =3D Param1Copy; Walker !=3D NULL && *Walker !=3D CHA= R_NULL; > Walker++) { > + if (*Walker =3D=3D L'\"') { > + CopyMem(Walker, Walker + 1, StrSize(Walker) - sizeof(Walker[= 0])); > + } > } > - } > - > - if (Param1Copy !=3D NULL) { > - Param1Copy =3D PathCleanUpDirectories(Param1Copy); > - } > - if (Param1Copy !=3D NULL) { > - if (StrCmp(Param1Copy, L".") =3D=3D 0) { > - // > - // nothing to do... change to current directory > - // > - } else if (StrCmp(Param1Copy, L"..") =3D=3D 0) { > + > + if (Param1Copy !=3D NULL && IsCurrentFileSystem (Param1Copy, Cwd= )) { > + Status =3D ReplaceDriveWithCwd (&Param1Copy,Cwd); > + if (!EFI_ERROR(Status)) { > + Param1Copy =3D PathCleanUpDirectories(Param1Copy); > + } > + } else { > // > - // Change up one directory... > + // Can't use cd command to change filesystem. > // > - Directory =3D ShellGetCurrentDir(NULL); > - if (Directory =3D=3D NULL) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), > gShellLevel2HiiHandle, L"cd"); > - ShellStatus =3D SHELL_NOT_FOUND; > - } else { > - CwdSize =3D StrSize(Directory) + sizeof(CHAR16); > - Cwd =3D AllocateZeroPool(CwdSize); > - if (Cwd =3D=3D NULL) { > - ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_M= EM), > gShellLevel2HiiHandle, L"cd"); > - ShellStatus =3D SHELL_OUT_OF_RESOURCES; > - } else { > - StrCpyS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, D= irectory); > - StrCatS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, L= "\\"); > - Drive =3D GetFullyQualifiedPath (Cwd); > - PathRemoveLastItem (Drive); > - FreePool (Cwd); > - } > - } > - if (ShellStatus =3D=3D SHELL_SUCCESS && Drive !=3D NULL) { > + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CD_NF), > gShellLevel2HiiHandle, L"cd"); > + Status =3D EFI_NOT_FOUND; > + } > + > + if (!EFI_ERROR(Status) && Param1Copy !=3D NULL) { > + Splitter =3D StrStr (Cwd, L":"); > + if (Param1Copy[0] =3D=3D L'\\') { > // > - // change directory on current drive letter > + // Absolute Path on current drive letter. > // > - Status =3D gEfiShellProtocol->SetCurDir(NULL, Drive); > - if (Status =3D=3D EFI_NOT_FOUND) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), > gShellLevel2HiiHandle, L"cd"); > - ShellStatus =3D SHELL_NOT_FOUND; > + TotalSize =3D ((Splitter - Cwd + 1) * sizeof(CHAR16)) + > StrSize(Param1Copy); > + TempBuffer =3D AllocateZeroPool(TotalSize); > + if (TempBuffer =3D=3D NULL) { > + Status =3D EFI_OUT_OF_RESOURCES; > + } else { > + StrnCpyS(TempBuffer, TotalSize / sizeof(CHAR16), Cwd, (Spl= itter - > Cwd + 1)); > + StrCatS (TempBuffer, TotalSize / sizeof(CHAR16), Param1Cop= y); > + > + FreePool(Param1Copy); > + Param1Copy =3D TempBuffer; > + TempBuffer =3D NULL; > } > - } > - } else if (StrCmp(Param1Copy, L"\\") =3D=3D 0) { > - // > - // Move to root of current drive > - // > - Directory =3D ShellGetCurrentDir(NULL); > - if (Directory =3D=3D NULL) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), > gShellLevel2HiiHandle, L"cd"); > - ShellStatus =3D SHELL_NOT_FOUND; > } else { > - CwdSize =3D StrSize(Directory) + sizeof(CHAR16); > - Cwd =3D AllocateZeroPool(CwdSize); > - if (Cwd =3D=3D NULL) { > - ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_M= EM), > gShellLevel2HiiHandle, L"cd"); > - ShellStatus =3D SHELL_OUT_OF_RESOURCES; > - } else { > - StrCpyS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, D= irectory); > - StrCatS (Cwd, StrSize (Directory) / sizeof (CHAR16) + 1, L= "\\"); > - Drive =3D GetFullyQualifiedPath (Cwd); > - while (PathRemoveLastItem (Drive)) { > - // > - // Check if Drive contains 'fsx:\' only or still points = to a sub-directory. > - // Don't remove trailing '\' from Drive if it points to = the root > directory. > - // > - Path =3D StrStr (Drive, L":\\"); > - if ((Path !=3D NULL) && (*(Path + 2) =3D=3D CHAR_NULL)) = { > - break; > - } > + if (StrStr (Param1Copy,L":") =3D=3D NULL) { > + TotalSize =3D StrSize(Cwd) + StrSize (Param1Copy); > + TempBuffer =3D AllocateZeroPool (TotalSize); > + if (TempBuffer =3D=3D NULL) { > + Status =3D EFI_OUT_OF_RESOURCES; > + } else { > + StrCpyS (TempBuffer, TotalSize / sizeof(CHAR16), Cwd); > + StrCatS (TempBuffer, TotalSize / sizeof(CHAR16), L"\\"); > + StrCatS (TempBuffer, TotalSize / sizeof(CHAR16), Param1C= opy); > + > + FreePool(Param1Copy); > + Param1Copy =3D PathCleanUpDirectories (TempBuffer); > } > - FreePool (Cwd); > } > } > - if (ShellStatus =3D=3D SHELL_SUCCESS && Drive !=3D NULL) { > - // > - // change directory on current drive letter > - // > - Status =3D gEfiShellProtocol->SetCurDir(NULL, Drive); > - if (Status =3D=3D EFI_NOT_FOUND) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), > gShellLevel2HiiHandle, L"cd"); > - ShellStatus =3D SHELL_NOT_FOUND; > - } > - } > - } else if (StrStr(Param1Copy, L":") =3D=3D NULL) { > - // > - // change directory without a drive identifier > - // > - if (ShellGetCurrentDir(NULL) =3D=3D NULL) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), > gShellLevel2HiiHandle, L"cd"); > + } > + > + if (!EFI_ERROR(Status)) { > + Status =3D ExtractDriveAndPath(Param1Copy, &Drive, &Path); > + } > + > + if (!EFI_ERROR(Status) && Drive !=3D NULL && Path !=3D NULL) { > + if (EFI_ERROR(ShellIsDirectory(Param1Copy))) { > + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_GEN_NOT_DIR), > gShellLevel2HiiHandle, L"cd", Param1Copy); > ShellStatus =3D SHELL_NOT_FOUND; > } else { > - ASSERT((Drive =3D=3D NULL && DriveSize =3D=3D 0) || (Drive != =3D NULL)); > - Drive =3D StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir= (NULL), > 0); > - Drive =3D StrnCatGrow(&Drive, &DriveSize, L"\\", 0); > - if (*Param1Copy =3D=3D L'\\') { > - while (PathRemoveLastItem(Drive)) ; > - Drive =3D StrnCatGrow(&Drive, &DriveSize, Param1Copy+1, 0)= ; > - } else { > - Drive =3D StrnCatGrow(&Drive, &DriveSize, Param1Copy, 0); > - } > - // > - // Verify that this is a valid directory > - // > - Status =3D gEfiShellProtocol->OpenFileByName(Drive, &Handle, > EFI_FILE_MODE_READ); > + Status =3D gEfiShellProtocol->SetCurDir(Drive, Path + 1); > if (EFI_ERROR(Status)) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF= ), > gShellLevel2HiiHandle, L"cd", Drive); > - ShellStatus =3D SHELL_NOT_FOUND; > - } else if (EFI_ERROR(FileHandleIsDirectory(Handle))) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DI= R), > gShellLevel2HiiHandle, L"cd", Drive); > - ShellStatus =3D SHELL_NOT_FOUND; > - } > - if (ShellStatus =3D=3D SHELL_SUCCESS && Drive !=3D NULL) { > - // > - // change directory on current drive letter > - // > - Status =3D gEfiShellProtocol->SetCurDir(NULL, Drive); > - if (Status =3D=3D EFI_NOT_FOUND) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), > gShellLevel2HiiHandle, L"cd"); > - ShellStatus =3D SHELL_NOT_FOUND; > - } > - } > - if (Handle !=3D NULL) { > - gEfiShellProtocol->CloseFile(Handle); > - DEBUG_CODE(Handle =3D NULL;); > - } > - } > - } else { > - // > - // change directory with a drive letter > - // > - Drive =3D AllocateCopyPool(StrSize(Param1Copy), Param1Copy); > - if (Drive =3D=3D NULL) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), > gShellLevel2HiiHandle, L"cd"); > - ShellStatus =3D SHELL_OUT_OF_RESOURCES; > - } else { > - Path =3D StrStr(Drive, L":"); > - ASSERT(Path !=3D NULL); > - if (EFI_ERROR(ShellIsDirectory(Param1Copy))) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DI= R), > gShellLevel2HiiHandle, L"cd", Param1Copy); > - ShellStatus =3D SHELL_NOT_FOUND; > - } else if (*(Path+1) =3D=3D CHAR_NULL) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), > gShellLevel2HiiHandle, L"cd"); > + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_GEN_DIR_NF)= , > gShellLevel2HiiHandle, L"cd", Param1Copy); > ShellStatus =3D SHELL_NOT_FOUND; > } else { > - *(Path+1) =3D CHAR_NULL; > - if (Path =3D=3D Drive + StrLen(Drive)) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), > gShellLevel2HiiHandle, L"cd"); > - ShellStatus =3D SHELL_NOT_FOUND; > - } else { > - Status =3D gEfiShellProtocol->SetCurDir(Drive, Path+2); > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT= ), > gShellLevel2HiiHandle, ShellGetCurrentDir(Drive)); > - } > - } > - if (Status =3D=3D EFI_NOT_FOUND) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), > gShellLevel2HiiHandle, L"cd"); > - Status =3D SHELL_NOT_FOUND; > - } else if (EFI_ERROR(Status)) { > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF= ), > gShellLevel2HiiHandle, L"cd", Param1Copy); > - Status =3D SHELL_NOT_FOUND; > + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_CD_PRINT), > gShellLevel2HiiHandle, ShellGetCurrentDir(Drive)); > } > } > } > + > + if (Drive !=3D NULL) { > + FreePool (Drive); > + } > + > + if (Path !=3D NULL) { > + FreePool (Path); > + } > + > + FreePool(Param1Copy); > } > - FreePool(Param1Copy); > } > } > > - if (Drive !=3D NULL) { > - FreePool(Drive); > - } > // > // free the command line package > // > -- > 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel