Bladeren bron

HADOOP-3108. Fix NPE in setPermission and setOwner. Contributed by Konstantin Shvachko.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.16@642336 13f79535-47bb-0310-9956-ffa450edef68
Konstantin Shvachko 17 jaren geleden
bovenliggende
commit
1c5f917a4b

+ 2 - 0
CHANGES.txt

@@ -849,6 +849,8 @@ Release 0.16.0 - 2008-02-07
     HADOOP-2768. Fix performance regression caused by HADOOP-1707.
     (dhruba borthakur via nigel)
 
+    HADOOP-3108. Fix NPE in setPermission and setOwner. (shv)
+
 Release 0.15.3 - 2008-01-18
 
   BUG FIXES

+ 8 - 3
src/java/org/apache/hadoop/dfs/FSDirectory.java

@@ -406,9 +406,12 @@ class FSDirectory implements FSConstants {
     fsImage.getEditLog().logSetPermissions(src, permission);
   }
 
-  void unprotectedSetPermission(String src, FsPermission permissions) {
+  void unprotectedSetPermission(String src, FsPermission permissions) throws FileNotFoundException {
     synchronized(rootDir) {
-      rootDir.getNode(src).setPermission(permissions);
+        INode inode = rootDir.getNode(src);
+        if(inode == null)
+            throw new FileNotFoundException("File does not exist: " + src);
+        inode.setPermission(permissions);
     }
   }
 
@@ -418,9 +421,11 @@ class FSDirectory implements FSConstants {
     fsImage.getEditLog().logSetOwner(src, username, groupname);
   }
 
-  void unprotectedSetOwner(String src, String username, String groupname) {
+  void unprotectedSetOwner(String src, String username, String groupname) throws FileNotFoundException {
     synchronized(rootDir) {
       INode inode = rootDir.getNode(src);
+      if(inode == null)
+          throw new FileNotFoundException("File does not exist: " + src);
       if (username != null) {
         inode.setUser(username);
       }

+ 16 - 0
src/test/org/apache/hadoop/security/TestPermission.java

@@ -119,6 +119,22 @@ public class TestPermission extends TestCase {
     FileSystem fs = FileSystem.get(conf);
 
     try {
+        // test permissions on files that do not exist
+        assertFalse(fs.exists(CHILD_FILE1));
+        try {
+          fs.setOwner(CHILD_FILE1, "foo", "bar");
+          assertTrue(false);
+        }
+        catch(java.io.FileNotFoundException e) {
+          LOG.info("GOOD: got " + e);
+        }
+        try {
+          fs.setPermission(CHILD_FILE1, new FsPermission((short)0777));
+          assertTrue(false);
+        }
+        catch(java.io.FileNotFoundException e) {
+          LOG.info("GOOD: got " + e);
+        }
       // following dir/file creations are legal
       fs.mkdirs(CHILD_DIR1);
       FSDataOutputStream out = fs.create(CHILD_FILE1);