diff options
author | Gary Benson <gbenson@redhat.com> | 2006-06-29 09:59:57 +0000 |
---|---|---|
committer | Gary Benson <gbenson@redhat.com> | 2006-06-29 09:59:57 +0000 |
commit | 74bba6beb290ec7809ac1f53163710453f3322f4 (patch) | |
tree | ca9853a3a49c6f9205458139a674301c57feb5b7 | |
parent | d8210adf6349ca16ba79d0969ddb55f0b828decb (diff) | |
download | classpath-74bba6beb290ec7809ac1f53163710453f3322f4.tar.gz |
2006-06-29 Gary Benson <gbenson@redhat.com>
* java/io/File.java (listRoots): Merge security checks from libgcj.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | java/io/File.java | 33 |
2 files changed, 36 insertions, 1 deletions
@@ -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; } /** |