From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 DD67D81D5D for ; Thu, 1 Dec 2016 08:12:57 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 01 Dec 2016 08:12:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,282,1477983600"; d="scan'208";a="793102039" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by FMSMGA003.fm.intel.com with ESMTP; 01 Dec 2016 08:12:57 -0800 Received: from fmsmsx152.amr.corp.intel.com (10.18.125.5) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 1 Dec 2016 08:12:56 -0800 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.12]) by FMSMSX152.amr.corp.intel.com ([169.254.6.84]) with mapi id 14.03.0248.002; Thu, 1 Dec 2016 08:12:56 -0800 From: "Carsey, Jaben" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" CC: "Chen, Chen A" , "Carsey, Jaben" Thread-Topic: [edk2] [PATCH] ShellPkg/MV: Fix MV to deny moving parent of current directory Thread-Index: AQHSRTV/Thci+paqF0ixOCQacd3vfqDzUIYA Date: Thu, 1 Dec 2016 16:12:56 +0000 Message-ID: References: <20161123025828.508396-1-ruiyu.ni@intel.com> In-Reply-To: <20161123025828.508396-1-ruiyu.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYzYwNDZhYzAtYjFmZi00YzQyLTg4MWEtZDNhMjJiYzY5YWUzIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6Imh6aW8rWGowM1dsMFNrelp2WVNMT3QrUmx5ZFM5TnNZc1hscFFoTmd0ZzA9In0= x-ctpclassification: CTP_IC x-originating-ip: [10.1.200.107] MIME-Version: 1.0 Subject: Re: [PATCH] ShellPkg/MV: Fix MV to deny moving parent of current directory 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: Thu, 01 Dec 2016 16:12:58 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jaben Carsey > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Ruiyu Ni > Sent: Tuesday, November 22, 2016 6:58 PM > To: edk2-devel@lists.01.org > Cc: Carsey, Jaben ; Chen, Chen A > > Subject: [edk2] [PATCH] ShellPkg/MV: Fix MV to deny moving parent of > current directory > Importance: High >=20 > From: Chen A Chen >=20 > When user types "mv -r fs0:\A\ fs1:\" under directory > "fs0:\A\B\", MV command should deny such movement. >=20 > The patch fixes the above issue. > It also denies moving current directory. >=20 > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Chen A Chen > Cc: Jaben Carsey > --- > ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c | 81 > ++++++++++++++++++++++-- > 1 file changed, 75 insertions(+), 6 deletions(-) >=20 > diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c > b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c > index efaaeb2..71e4336 100644 > --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c > +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c > @@ -58,6 +58,73 @@ IsBetweenFileSystem( > } >=20 > /** > + function to determine if SrcPath is valid to mv. > + > + if SrcPath equal CWD then it's invalid. > + if SrcPath is the parent path of CWD then it's invalid. > + is SrcPath is NULL return FALSE. > + > + if CwdPath is NULL then ASSERT() > + > + @param SrcPath [in] The source path. > + @param CwdPath [in] The current working directory. > + > + @retval TRUE The source path is valid. > + @retval FALSE The source path is invalid. > +**/ > +BOOLEAN > +IsSoucePathValid( > + IN CONST CHAR16* SrcPath, > + IN CONST CHAR16* CwdPath > + ) > +{ > + CHAR16* SrcPathBuffer; > + CHAR16* CwdPathBuffer; > + BOOLEAN Ret; > + > + ASSERT (CwdPath !=3D NULL); > + if (SrcPath =3D=3D NULL) { > + return FALSE; > + } > + > + Ret =3D TRUE; > + > + SrcPathBuffer =3D AllocateCopyPool (StrSize (SrcPath), SrcPath); > + if (SrcPathBuffer =3D=3D NULL) { > + return FALSE; > + } > + > + CwdPathBuffer =3D AllocateCopyPool (StrSize (CwdPath), CwdPath); > + if (CwdPathBuffer =3D=3D NULL) { > + FreePool(SrcPathBuffer); > + return FALSE; > + } > + > + gUnicodeCollation->StrUpr (gUnicodeCollation, SrcPathBuffer); > + gUnicodeCollation->StrUpr (gUnicodeCollation, CwdPathBuffer); > + > + if (SrcPathBuffer[StrLen (SrcPathBuffer) -1 ] =3D=3D L'\\') { > + SrcPathBuffer[StrLen (SrcPathBuffer) - 1] =3D CHAR_NULL; > + } > + > + if (CwdPathBuffer[StrLen (CwdPathBuffer) - 1] =3D=3D L'\\') { > + CwdPathBuffer[StrLen (CwdPathBuffer) - 1] =3D CHAR_NULL; > + } > + > + if (StrCmp (CwdPathBuffer, SrcPathBuffer) =3D=3D 0 || > + ((StrStr (CwdPathBuffer, SrcPathBuffer) =3D=3D CwdPathBuffer) && > + (CwdPathBuffer[StrLen (SrcPathBuffer)] =3D=3D L'\\')) > + ) { > + Ret =3D FALSE; > + } > + > + FreePool (SrcPathBuffer); > + FreePool (CwdPathBuffer); > + > + return Ret; > +} > + > +/** > Function to validate that moving a specific file (FileName) to a speci= fic > location (DestPath) is valid. >=20 > @@ -90,12 +157,14 @@ IsValidMove( > CHAR16 *DestPathCopy; > CHAR16 *DestPathWalker; >=20 > - if (Cwd !=3D NULL && StrCmp(SourcePath, Cwd) =3D=3D 0) { > - // > - // Invalid move > - // > - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_CWD), > gShellLevel2HiiHandle); > - return (FALSE); > + if ((Cwd !=3D NULL) && ((Attribute & EFI_FILE_DIRECTORY) =3D=3D > EFI_FILE_DIRECTORY)) { > + if (!IsSoucePathValid (SourcePath, Cwd)) { > + // > + // Invalid move > + // > + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_MV_INV_CWD), > gShellLevel2HiiHandle); > + return FALSE; > + } > } >=20 > // > -- > 2.9.0.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel