Hi again,
This commit merges security checks for File.listRoots from libgcj.
Cheers,
Gary
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.7966
diff -u -r1.7966 ChangeLog
--- ChangeLog 29 Jun 2006 09:02:49 -0000 1.7966
+++ ChangeLog 29 Jun 2006 09:59:31 -0000
@@ -1,3 +1,7 @@
+2006-06-29 Gary Benson <[EMAIL PROTECTED]>
+
+ * java/io/File.java (listRoots): Merge security checks from libgcj.
+
2006-06-29 Gary Benson <[EMAIL PROTECTED]>
* java/io/FilePermission.java (implies): Work when path is "/".
Index: java/io/File.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/File.java,v
retrieving revision 1.64
diff -u -r1.64 File.java
--- java/io/File.java 14 Jun 2006 14:47:46 -0000 1.64
+++ java/io/File.java 29 Jun 2006 09:59:31 -0000
@@ -1200,7 +1200,38 @@
*/
public static File[] listRoots()
{
- return VMFile.listRoots();
+ File[] roots = VMFile.listRoots();
+
+ SecurityManager s = System.getSecurityManager();
+ if (s != null)
+ {
+ // Only return roots to which the security manager permits read access.
+ int count = roots.length;
+ for (int i = 0; i < roots.length; i++)
+ {
+ try
+ {
+ s.checkRead (roots[i].path);
+ }
+ catch (SecurityException sx)
+ {
+ roots[i] = null;
+ count--;
+ }
+ }
+ if (count != roots.length)
+ {
+ File[] newRoots = new File[count];
+ int k = 0;
+ for (int i = 0; i < roots.length; i++)
+ {
+ if (roots[i] != null)
+ newRoots[k++] = roots[i];
+ }
+ roots = newRoots;
+ }
+ }
+ return roots;
}
/**