Browse Source

HDFS-181. Validate src path in FSNamesystem.getFileInfo(..). Contributed by Todd Lipcon

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hdfs/trunk@788549 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 16 years ago
parent
commit
2355efaee1

+ 3 - 0
CHANGES.txt

@@ -35,6 +35,9 @@ Trunk (unreleased changes)
     HDFS-195. Handle expired tokens when write pipeline is restablished.
     (Kan Zhang via rangadi)
 
+    HDFS-181. Validate src path in FSNamesystem.getFileInfo(..).  (Todd
+    Lipcon via szetszwo)
+
 Release 0.20.1 - Unreleased
 
   IMPROVEMENTS

+ 3 - 0
src/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

@@ -1442,6 +1442,9 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean {
    *         or null if file not found
    */
   FileStatus getFileInfo(String src) throws IOException {
+    if (!DFSUtil.isValidName(src)) {
+      throw new IOException("Invalid file name: " + src);
+    }
     if (isPermissionEnabled) {
       checkTraverse(src);
     }

+ 10 - 0
src/test/hdfs/org/apache/hadoop/hdfs/TestFileStatus.java

@@ -26,6 +26,7 @@ import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.ipc.RemoteException;
 
 /**
  * This class tests the FileStatus API.
@@ -79,6 +80,15 @@ public class TestFileStatus extends TestCase {
       FileStatus fileInfo = dfsClient.getFileInfo("/noSuchFile");
       assertTrue(fileInfo == null);
 
+      // make sure getFileInfo throws the appropriate exception for non-relative
+      // filenames
+      try {
+        FileStatus foo = dfsClient.getFileInfo("non-relative");
+        fail("getFileInfo for a non-relative path did not thro IOException");
+      } catch (RemoteException re) {
+        assertTrue(re.toString().contains("Invalid file name"));
+      }
+
       // create a file in home directory
       //
       Path file1 = new Path("filestatus.dat");