summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Benson <gbenson@redhat.com>2006-06-29 09:59:57 +0000
committerGary Benson <gbenson@redhat.com>2006-06-29 09:59:57 +0000
commit74bba6beb290ec7809ac1f53163710453f3322f4 (patch)
treeca9853a3a49c6f9205458139a674301c57feb5b7
parentd8210adf6349ca16ba79d0969ddb55f0b828decb (diff)
downloadclasspath-74bba6beb290ec7809ac1f53163710453f3322f4.tar.gz
2006-06-29 Gary Benson <gbenson@redhat.com>
* java/io/File.java (listRoots): Merge security checks from libgcj.
-rw-r--r--ChangeLog4
-rw-r--r--java/io/File.java33
2 files changed, 36 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 1361aa763..7ef8bb529 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2006-06-29 Gary Benson <gbenson@redhat.com>
+ * java/io/File.java (listRoots): Merge security checks from libgcj.
+
+2006-06-29 Gary Benson <gbenson@redhat.com>
+
* java/io/FilePermission.java (implies): Work when path is "/".
2006-06-28 Andrew John Hughes <gnu_andrew@member.fsf.org>
diff --git a/java/io/File.java b/java/io/File.java
index 68b6a85fe..ce56876cc 100644
--- a/java/io/File.java
+++ b/java/io/File.java
@@ -1200,7 +1200,38 @@ public class File implements Serializable, Comparable
*/
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;
}
/**