changeset 12467:c1dc1321df35

8132475: The commands in the modular images are executable by the owner only (once again) Reviewed-by: rriggs, alanb
author simonis
date Wed, 29 Jul 2015 11:47:19 +0200
parents 5469978f2cef
children cee5f23f6074 db7ebac0bc7a
files src/java.base/share/classes/jdk/internal/jimage/ExternalFilesWriter.java test/jdk/internal/jimage/ExecutableTest.java
diffstat 2 files changed, 66 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/jdk/internal/jimage/ExternalFilesWriter.java	Wed Jul 29 11:43:44 2015 +0200
+++ b/src/java.base/share/classes/jdk/internal/jimage/ExternalFilesWriter.java	Wed Jul 29 11:47:19 2015 +0200
@@ -58,7 +58,7 @@
                     case NATIVE_CMD:
                         Path path = destFile("bin", filename);
                         writeEntry(in, path);
-                        path.toFile().setExecutable(true);
+                        path.toFile().setExecutable(true, false);
                         break;
                     case CONFIG:
                         writeEntry(in, destFile("conf", filename));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/internal/jimage/ExecutableTest.java	Wed Jul 29 11:47:19 2015 +0200
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2015 SAP SE.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.PosixFilePermission;
+import static java.nio.file.attribute.PosixFilePermission.*;
+import java.util.EnumSet;
+import java.util.Set;
+
+/*
+ * @test
+ * @bug 8132475
+ * @summary Check that the executables in the current JDK image
+ *          are executable by all users.
+ * @run main ExecutableTest
+ * @author Volker Simonis
+ */
+
+public class ExecutableTest {
+
+    public static void main(String args[]) throws Throwable {
+        String JAVA_HOME = System.getProperty("java.home");
+        Path binPath = Paths.get(JAVA_HOME, "bin");
+        DirectoryStream<Path> stream = Files.newDirectoryStream(binPath);
+        EnumSet<PosixFilePermission> execPerms =
+            EnumSet.of(GROUP_EXECUTE, OTHERS_EXECUTE, OWNER_EXECUTE);
+        for (Path entry : stream) {
+            if (Files.isRegularFile(entry)) {
+                if (!Files.isExecutable(entry)) {
+                    throw new Error(entry + " is not executable!");
+                }
+                try {
+                    Set<PosixFilePermission> perm = Files.getPosixFilePermissions(entry);
+                    if (!perm.containsAll(execPerms)) {
+                        throw new Error(entry + " has not all executable permissions!\n" +
+                                        "Should have: " + execPerms + "\nbut has: " + perm);
+                    }
+                } catch (UnsupportedOperationException e) {}
+            }
+        }
+    }
+}