6985453: Font.createFont may expose some system properties in exception text
authorbae
Fri Oct 29 23:55:34 2010 +0400 (2 years ago)
changeset 4805e70dbac6a7d
parent 479f3dff5c1b9c2
child 481db9f076b2aed
6985453: Font.createFont may expose some system properties in exception text
Reviewed-by: prr, hawtin
src/share/classes/sun/font/FileFont.java
src/share/classes/sun/font/TrueTypeFont.java
src/share/classes/sun/font/Type1Font.java
--- a/src/share/classes/sun/font/FileFont.java Wed Oct 27 13:03:30 2010 -0700
+++ b/src/share/classes/sun/font/FileFont.java Fri Oct 29 23:55:34 2010 +0400
@@ -48,6 +48,9 @@ import java.util.HashSet;
import java.util.HashSet;
import java.util.HashMap;
import java.awt.Font;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
public abstract class FileFont extends PhysicalFont {
@@ -284,4 +287,49 @@ public abstract class FileFont extends P
});
}
}
+
+ protected String getPublicFileName() {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null) {
+ return platName;
+ }
+ boolean canReadProperty = true;
+
+ try {
+ sm.checkPropertyAccess("java.io.tmpdir");
+ } catch (SecurityException e) {
+ canReadProperty = false;
+ }
+
+ if (canReadProperty) {
+ return platName;
+ }
+
+ final File f = new File(platName);
+
+ Boolean isTmpFile = Boolean.FALSE;
+ try {
+ isTmpFile = AccessController.doPrivileged(
+ new PrivilegedExceptionAction<Boolean>() {
+ public Boolean run() {
+ File tmp = new File(System.getProperty("java.io.tmpdir"));
+ try {
+ String tpath = tmp.getCanonicalPath();
+ String fpath = f.getCanonicalPath();
+
+ return (fpath == null) || fpath.startsWith(tpath);
+ } catch (IOException e) {
+ return Boolean.TRUE;
+ }
+ }
+ }
+ );
+ } catch (PrivilegedActionException e) {
+ // unable to verify whether value of java.io.tempdir will be
+ // exposed, so return only a name of the font file.
+ isTmpFile = Boolean.TRUE;
+ }
+
+ return isTmpFile ? "temp file" : platName;
+ }
}
--- a/src/share/classes/sun/font/TrueTypeFont.java Wed Oct 27 13:03:30 2010 -0700
+++ b/src/share/classes/sun/font/TrueTypeFont.java Fri Oct 29 23:55:34 2010 +0400
@@ -504,7 +504,8 @@ public class TrueTypeFont extends FileFo
break;
default:
- throw new FontFormatException("Unsupported sfnt " + platName);
+ throw new FontFormatException("Unsupported sfnt " +
+ getPublicFileName());
}
/* Now have the offset of this TT font (possibly within a TTC)
@@ -1369,6 +1370,6 @@ public class TrueTypeFont extends FileFo
public String toString() {
return "** TrueType Font: Family="+familyName+ " Name="+fullName+
- " style="+style+" fileName="+platName;
+ " style="+style+" fileName="+getPublicFileName();
}
}
--- a/src/share/classes/sun/font/Type1Font.java Wed Oct 27 13:03:30 2010 -0700
+++ b/src/share/classes/sun/font/Type1Font.java Fri Oct 29 23:55:34 2010 +0400
@@ -677,7 +677,7 @@ public class Type1Font extends FileFont
public String toString() {
return "** Type1 Font: Family="+familyName+ " Name="+fullName+
- " style="+style+" fileName="+platName;
+ " style="+style+" fileName="+getPublicFileName();
}
}