[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: SecurityManager fixes for package handling

Kaffe CVS cvs-commits at kaffe.org
Thu Oct 14 06:23:22 PDT 2004


PatchSet 5284 
Date: 2004/10/14 09:35:59
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: SecurityManager fixes for package handling

2004-10-12  Dalibor Topic <robilad at kaffe.org>

        *  libraries/javalib/java/lang/SecurityManager.java:
        Resynced with GNU Classpath.

        2004-10-12  Jeroen Frijters  <jeroen at frijters.net>

        * java/lang/SecurityManager.java
        (checkPackageAccess, checkPackageDefinition): Pass complete
        restriction.
        (checkPackageList): Simplified and corrected the code.

Members: 
	ChangeLog:1.2836->1.2837 
	libraries/javalib/java/lang/SecurityManager.java:1.22->1.23 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2836 kaffe/ChangeLog:1.2837
--- kaffe/ChangeLog:1.2836	Thu Oct 14 07:48:34 2004
+++ kaffe/ChangeLog	Thu Oct 14 09:35:59 2004
@@ -1,5 +1,17 @@
 2004-10-12  Dalibor Topic <robilad at kaffe.org>
 
+	*  libraries/javalib/java/lang/SecurityManager.java:
+        Resynced with GNU Classpath.
+
+	2004-10-12  Jeroen Frijters  <jeroen at frijters.net>
+
+        * java/lang/SecurityManager.java
+        (checkPackageAccess, checkPackageDefinition): Pass complete
+        restriction.
+        (checkPackageList): Simplified and corrected the code.
+
+2004-10-12  Dalibor Topic <robilad at kaffe.org>
+
 	* libraries/javalib/java/util/Date.java:
 	Resynced with GNU Classpath.
 
Index: kaffe/libraries/javalib/java/lang/SecurityManager.java
diff -u kaffe/libraries/javalib/java/lang/SecurityManager.java:1.22 kaffe/libraries/javalib/java/lang/SecurityManager.java:1.23
--- kaffe/libraries/javalib/java/lang/SecurityManager.java:1.22	Tue Oct 12 00:50:17 2004
+++ kaffe/libraries/javalib/java/lang/SecurityManager.java	Thu Oct 14 09:36:04 2004
@@ -53,6 +53,7 @@
 import java.security.Security;
 import java.security.SecurityPermission;
 import java.util.PropertyPermission;
+import java.util.StringTokenizer;
 
 /**
  * SecurityManager is a class you can extend to create your own Java
@@ -889,7 +890,7 @@
    */
   public void checkPackageAccess(String packageName)
   {
-    checkPackageList(packageName, "access", "accessClassInPackage.");
+    checkPackageList(packageName, "package.access", "accessClassInPackage.");
   }
 
   /**
@@ -911,7 +912,7 @@
    */
   public void checkPackageDefinition(String packageName)
   {
-    checkPackageList(packageName, "definition", "defineClassInPackage.");
+    checkPackageList(packageName, "package.definition", "defineClassInPackage.");
   }
 
   /**
@@ -1007,7 +1008,7 @@
    * <code>RuntimePermission(permission + packageName)</code>.
    *
    * @param packageName the package name to check access to
-   * @param restriction the list of restrictions, after "package."
+   * @param restriction "package.access" or "package.definition"
    * @param permission the base permission, including the '.'
    * @throws SecurityException if permission is denied
    * @throws NullPointerException if packageName is null
@@ -1017,31 +1018,29 @@
   void checkPackageList(String packageName, final String restriction,
                         String permission)
   {
-    // Use the toString() hack to do the null check.
-    Permission p = new RuntimePermission(permission + packageName.toString());
+    if (packageName == null)
+	throw new NullPointerException();
+
     String list = (String)AccessController.doPrivileged(new PrivilegedAction() {
 	public Object run() {
-	    return Security.getProperty("package." + restriction);
+	    return Security.getProperty(restriction);
 	}
     });
-    if (list == null)
+
+    if (list == null || list.equals(""))
       return;
-    while (! "".equals(packageName))
+
+    String packageNamePlusDot = packageName + ".";
+
+    StringTokenizer st = new StringTokenizer(list, ",");
+    while (st.hasMoreTokens())
       {
-        for (int index = list.indexOf(packageName);
-             index != -1; index = list.indexOf(packageName, index + 1))
-          {
-            // Exploit package visibility for speed.
-	    int packageNameCount = packageName.length();
-            if (index + packageNameCount == list.length()
-                || list.charAt(index + packageNameCount) == ',')
-              {
-                checkPermission(p);
-                return;
-              }
-          }
-        int index = packageName.lastIndexOf('.');
-        packageName = index < 0 ? "" : packageName.substring(0, index);
+	if (packageNamePlusDot.startsWith(st.nextToken()))
+	  {
+	    Permission p = new RuntimePermission(permission + packageName);
+	    checkPermission(p);
+	    return;
+	  }
       }
   }
 } // class SecurityManager




More information about the kaffe mailing list