Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 432C417B4C for ; Fri, 25 Sep 2015 04:40:37 +0000 (UTC) Received: (qmail 68731 invoked by uid 500); 25 Sep 2015 04:40:36 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 68661 invoked by uid 500); 25 Sep 2015 04:40:36 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 68651 invoked by uid 99); 25 Sep 2015 04:40:36 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Sep 2015 04:40:36 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1BDFEDFA96; Fri, 25 Sep 2015 04:40:36 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: yjzhangal@apache.org To: common-commits@hadoop.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HDFS-9123. Copying from the root to a subdirectory should be forbidden. (Wei-Chiu Chuang via Yongjun Zhang) Date: Fri, 25 Sep 2015 04:40:36 +0000 (UTC) Repository: hadoop Updated Branches: refs/heads/trunk 692b1a45c -> 3187dbd7a HDFS-9123. Copying from the root to a subdirectory should be forbidden. (Wei-Chiu Chuang via Yongjun Zhang) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/3187dbd7 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/3187dbd7 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/3187dbd7 Branch: refs/heads/trunk Commit: 3187dbd7a8b6376134a00e5c9c4693d8eb762c9d Parents: 692b1a4 Author: Yongjun Zhang Authored: Thu Sep 24 21:36:38 2015 -0700 Committer: Yongjun Zhang Committed: Thu Sep 24 21:36:38 2015 -0700 ---------------------------------------------------------------------- .../apache/hadoop/fs/shell/CommandWithDestination.java | 8 +++++++- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../test/java/org/apache/hadoop/hdfs/TestDFSShell.java | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/3187dbd7/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java index 2fdde3f..4b8d3bc 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java @@ -238,7 +238,13 @@ abstract class CommandWithDestination extends FsCommand { e.setTargetPath(dstPath.toString()); throw e; } - if (dstPath.startsWith(srcPath+Path.SEPARATOR)) { + // When a path is normalized, all trailing slashes are removed + // except for the root + if(!srcPath.endsWith(Path.SEPARATOR)) { + srcPath += Path.SEPARATOR; + } + + if(dstPath.startsWith(srcPath)) { PathIOException e = new PathIOException(src.toString(), "is a subdirectory of itself"); e.setTargetPath(target.toString()); http://git-wip-us.apache.org/repos/asf/hadoop/blob/3187dbd7/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index ed2aa8f..afe677e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -1409,6 +1409,9 @@ Release 2.8.0 - UNRELEASED HDFS-9076. Log full path instead of inodeId in DFSClient #closeAllFilesBeingWritten() (Surendra Singh Lilhore via vinayakumarb) + HDFS-9123. Copying from the root to a subdirectory should be forbidden. + (Wei-Chiu Chuang via Yongjun Zhang) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES http://git-wip-us.apache.org/repos/asf/hadoop/blob/3187dbd7/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java index dda2051..22ae09b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java @@ -1384,6 +1384,19 @@ public class TestDFSShell { e.getLocalizedMessage()); } assertEquals(0, val); + + // this should fail + args1[0] = "-cp"; + args1[1] = "/"; + args1[2] = "/test"; + val = 0; + try { + val = shell.run(args1); + } catch (Exception e) { + System.err.println("Exception raised from DFSShell.run " + + e.getLocalizedMessage()); + } + assertEquals(1, val); } // Verify -test -f negative case (missing file)