提交 b91af85b 编写于 作者: R rkennke

6904882: java.awt.Font.createFont() causes AccessControlException if executed...

6904882: java.awt.Font.createFont() causes AccessControlException if executed with "-Djava.security.manager"
Summary: Perform FontUtilities initialization in privileged block
Reviewed-by: igor, prr
上级 fb633161
...@@ -32,9 +32,9 @@ import java.io.FileInputStream; ...@@ -32,9 +32,9 @@ import java.io.FileInputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.swing.plaf.FontUIResource; import javax.swing.plaf.FontUIResource;
import sun.security.action.GetPropertyAction;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
/** /**
...@@ -42,43 +42,42 @@ import sun.util.logging.PlatformLogger; ...@@ -42,43 +42,42 @@ import sun.util.logging.PlatformLogger;
*/ */
public final class FontUtilities { public final class FontUtilities {
public static final boolean isSolaris; public static boolean isSolaris;
public static final boolean isLinux; public static boolean isLinux;
public static final boolean isSolaris8; public static boolean isSolaris8;
public static final boolean isSolaris9; public static boolean isSolaris9;
public static final boolean isOpenSolaris; public static boolean isOpenSolaris;
public static final boolean useT2K; public static boolean useT2K;
public static final boolean isWindows; public static boolean isWindows;
public static final boolean isOpenJDK; public static boolean isOpenJDK;
static final String LUCIDA_FILE_NAME = "LucidaSansRegular.ttf"; static final String LUCIDA_FILE_NAME = "LucidaSansRegular.ttf";
// This static initializer block figures out the OS constants. // This static initializer block figures out the OS constants.
static { static {
String osName = AccessController.doPrivileged( AccessController.doPrivileged(new PrivilegedAction () {
new GetPropertyAction("os.name", "unknownOS")); public Object run() {
String osName = System.getProperty("os.name", "unknownOS");
isSolaris = osName.startsWith("SunOS"); isSolaris = osName.startsWith("SunOS");
isLinux = osName.startsWith("Linux"); isLinux = osName.startsWith("Linux");
String t2kStr = AccessController.doPrivileged( String t2kStr = System.getProperty("sun.java2d.font.scaler");
new GetPropertyAction("sun.java2d.font.scaler"));
if (t2kStr != null) { if (t2kStr != null) {
useT2K = "t2k".equals(t2kStr); useT2K = "t2k".equals(t2kStr);
} else { } else {
useT2K = false; useT2K = false;
} }
if (isSolaris) { if (isSolaris) {
String version = AccessController.doPrivileged( String version = System.getProperty("os.version", "0.0");
new GetPropertyAction("os.version", "0.0"));
isSolaris8 = version.startsWith("5.8"); isSolaris8 = version.startsWith("5.8");
isSolaris9 = version.startsWith("5.9"); isSolaris9 = version.startsWith("5.9");
float ver = Float.parseFloat(version); float ver = Float.parseFloat(version);
...@@ -101,7 +100,7 @@ public final class FontUtilities { ...@@ -101,7 +100,7 @@ public final class FontUtilities {
isOpenSolaris = false; isOpenSolaris = false;
} }
} else { } else {
isOpenSolaris= false; isOpenSolaris = false;
} }
} else { } else {
isSolaris8 = false; isSolaris8 = false;
...@@ -109,12 +108,16 @@ public final class FontUtilities { ...@@ -109,12 +108,16 @@ public final class FontUtilities {
isOpenSolaris = false; isOpenSolaris = false;
} }
isWindows = osName.startsWith("Windows"); isWindows = osName.startsWith("Windows");
String jreLibDirName = AccessController.doPrivileged( String jreLibDirName = System.getProperty("java.home", "")
new GetPropertyAction("java.home","")) + File.separator + "lib"; + File.separator + "lib";
String jreFontDirName = jreLibDirName + File.separator + "fonts"; String jreFontDirName =
File lucidaFile = jreLibDirName + File.separator + "fonts";
new File(jreFontDirName + File.separator + LUCIDA_FILE_NAME); File lucidaFile = new File(jreFontDirName + File.separator
+ LUCIDA_FILE_NAME);
isOpenJDK = !lucidaFile.exists(); isOpenJDK = !lucidaFile.exists();
return null;
}
});
} }
/** /**
......
/*
* Copyright (c) 2010 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 5010310 6319835 6904882
* @summary test fonts can be created in the presence of a security manager
* @run main/othervm/secure=java.lang.SecurityManager FontPrivilege
*/
import java.awt.Font;
public class FontPrivilege {
public static void main(String[] args) throws Exception {
new Font("Helvetica", Font.PLAIN, 12).getFamily();
new Font("foo bar", Font.PLAIN, 12).getFamily();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册