2727N/A/*
2727N/A * Copyright 2010 Google Inc. All Rights Reserved.
2727N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2727N/A *
2727N/A * This code is free software; you can redistribute it and/or modify it
2727N/A * under the terms of the GNU General Public License version 2 only, as
2727N/A * published by the Free Software Foundation.
2727N/A *
2727N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2727N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2727N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2727N/A * version 2 for more details (a copy is included in the LICENSE file that
2727N/A * accompanied this code).
2727N/A *
2727N/A * You should have received a copy of the GNU General Public License version
2727N/A * 2 along with this work; if not, write to the Free Software Foundation,
2727N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2727N/A *
2727N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2727N/A * or visit www.oracle.com if you need additional information or have any
2727N/A * questions.
2727N/A */
2727N/A
2727N/A/*
2727N/A * @test
2727N/A * @bug 6980747
2727N/A * @summary Check that Process-related classes have the proper
2727N/A * doPrivileged blocks, and can be initialized with an adversarial
2727N/A * security manager.
2727N/A * @run main/othervm SecurityManagerClinit
2727N/A * @author Martin Buchholz
2727N/A */
2727N/A
2727N/Aimport java.io.*;
2727N/Aimport java.security.*;
2727N/A
2727N/Apublic class SecurityManagerClinit {
2727N/A private static class Policy extends java.security.Policy {
2727N/A private Permissions perms;
2727N/A
2727N/A public Policy(Permission... permissions) {
2727N/A perms = new Permissions();
2727N/A for (Permission permission : permissions)
2727N/A perms.add(permission);
2727N/A }
2727N/A
2727N/A public boolean implies(ProtectionDomain pd, Permission p) {
2727N/A return perms.implies(p);
2727N/A }
2727N/A }
2727N/A
2727N/A public static void main(String[] args) throws Throwable {
2727N/A String javaExe =
2727N/A System.getProperty("java.home") +
2727N/A File.separator + "bin" + File.separator + "java";
2727N/A
2727N/A // A funky contrived security setup, just for bug repro purposes.
2727N/A java.security.Security.setProperty("package.access", "java.util");
2727N/A
2727N/A final Policy policy =
2727N/A new Policy
2727N/A (new FilePermission("<<ALL FILES>>", "execute"),
2727N/A new RuntimePermission("setSecurityManager"));
2727N/A Policy.setPolicy(policy);
2727N/A
2727N/A System.setSecurityManager(new SecurityManager());
2727N/A
2727N/A try {
2727N/A String[] cmd = { javaExe, "-version" };
2727N/A Process p = Runtime.getRuntime().exec(cmd);
2727N/A p.getOutputStream().close();
2727N/A p.getInputStream().close();
2727N/A p.getErrorStream().close();
2727N/A p.waitFor();
2727N/A } finally {
2727N/A System.setSecurityManager(null);
2727N/A }
2727N/A }
2727N/A}