HDFS-15252. HttpFS: setWorkingDirectory should not accept invalid paths. Contributed by hemanthboyina.

This commit is contained in:
Takanobu Asanuma 2020-04-02 19:21:02 +09:00
parent 4a3eb10972
commit 736659e0e1
2 changed files with 17 additions and 1 deletions

View File

@ -47,6 +47,7 @@
import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSUtilClient;
import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy;
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
import org.apache.hadoop.hdfs.protocol.FsPermissionExtension;
@ -801,6 +802,11 @@ public DirectoryEntries listStatusBatch(Path f, byte[] token) throws
*/
@Override
public void setWorkingDirectory(Path newDir) {
String result = newDir.toUri().getPath();
if (!DFSUtilClient.isValidName(result)) {
throw new IllegalArgumentException(
"Invalid DFS directory name " + result);
}
workingDir = newDir;
}

View File

@ -59,6 +59,7 @@
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.test.HFSTestCase;
import org.apache.hadoop.test.HadoopUsersConfTestHelper;
import org.apache.hadoop.test.LambdaTestUtils;
import org.apache.hadoop.test.TestDir;
import org.apache.hadoop.test.TestDirHelper;
import org.apache.hadoop.test.TestHdfs;
@ -521,9 +522,18 @@ private void testWorkingdirectory() throws Exception {
fs = getHttpFSFileSystem();
fs.setWorkingDirectory(new Path("/tmp"));
workingDir = fs.getWorkingDirectory();
fs.close();
assertEquals(workingDir.toUri().getPath(),
new Path("/tmp").toUri().getPath());
final FileSystem httpFs = getHttpFSFileSystem();
LambdaTestUtils.intercept(IllegalArgumentException.class,
"Invalid DFS directory name /foo:bar",
() -> httpFs.setWorkingDirectory(new Path("/foo:bar")));
fs.setWorkingDirectory(new Path("/bar"));
workingDir = fs.getWorkingDirectory();
httpFs.close();
fs.close();
assertEquals(workingDir.toUri().getPath(),
new Path("/bar").toUri().getPath());
}
private void testTrashRoot() throws Exception {