From e6b4714d0b87a0fcefe1994fcc34fc88001c2486 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Wed, 29 Jul 2015 15:25:10 +0000 Subject: [PATCH] HADOOP-10945. 4-digit octal umask permissions throws a parse error. Contributed by Chang Li (cherry picked from commit 6f0a35724f0da80146dbae4b6f6c341e1d3101f5) --- .../hadoop-common/CHANGES.txt | 3 +++ .../hadoop/fs/permission/UmaskParser.java | 2 +- .../hadoop/security/TestPermission.java | 26 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index e2f79a825ff..d3293196dfc 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -529,6 +529,9 @@ Release 2.8.0 - UNRELEASED HADOOP-12175. FsShell must load SpanReceierHost to support tracing (Masatake Iwasaki via Colin P. McCabe) + HADOOP-10945. 4-digit octal umask permissions throws a parse error (Chang + Li via jlowe) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/permission/UmaskParser.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/permission/UmaskParser.java index 79956c593cd..0cf26c51a7c 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/permission/UmaskParser.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/permission/UmaskParser.java @@ -33,7 +33,7 @@ import org.apache.hadoop.classification.InterfaceStability; @InterfaceStability.Unstable class UmaskParser extends PermissionParser { private static Pattern chmodOctalPattern = - Pattern.compile("^\\s*[+]?()([0-7]{3})\\s*$"); // no leading 1 for sticky bit + Pattern.compile("^\\s*[+]?(0*)([0-7]{3})\\s*$"); // no leading 1 for sticky bit private static Pattern umaskSymbolicPattern = /* not allow X or t */ Pattern.compile("\\G\\s*([ugoa]*)([+=-]+)([rwx]*)([,\\s]*)\\s*"); final short umaskMode; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestPermission.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestPermission.java index 06150d7739e..01398a0e003 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestPermission.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestPermission.java @@ -20,6 +20,7 @@ package org.apache.hadoop.security; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.IOException; import java.util.Random; @@ -100,6 +101,31 @@ public class TestPermission { conf = new Configuration(); conf.set(FsPermission.UMASK_LABEL, "022"); assertEquals(18, FsPermission.getUMask(conf).toShort()); + + // Test 5 - equivalent valid umask + conf = new Configuration(); + conf.set(FsPermission.UMASK_LABEL, "0022"); + assertEquals(18, FsPermission.getUMask(conf).toShort()); + + // Test 6 - invalid umask + conf = new Configuration(); + conf.set(FsPermission.UMASK_LABEL, "1222"); + try { + FsPermission.getUMask(conf); + fail("expect IllegalArgumentException happen"); + } catch (IllegalArgumentException e) { + //pass, exception successfully trigger + } + + // Test 7 - invalid umask + conf = new Configuration(); + conf.set(FsPermission.UMASK_LABEL, "01222"); + try { + FsPermission.getUMask(conf); + fail("expect IllegalArgumentException happen"); + } catch (IllegalArgumentException e) { + //pass, exception successfully trigger + } } @Test