classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] Patch: Opening RandomAccessFiles requires excessive per


From: David Daney
Subject: Re: [cp-patches] Patch: Opening RandomAccessFiles requires excessive permission
Date: Mon, 05 Dec 2005 08:51:57 -0800
User-agent: Mozilla Thunderbird 1.0.7-1.1.fc3 (X11/20050929)

Gary Benson wrote:
Hi all,

Opening a java.io.RandomAccessFile in read-only mode with a security
manager in force requires the permission to write file descriptors.
The attached patch fixes.  Anyone mind if I commit?

Cheers,
Gary


------------------------------------------------------------------------

Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.5764
diff -u -r1.5764 ChangeLog
--- ChangeLog   5 Dec 2005 13:25:00 -0000       1.5764
+++ ChangeLog   5 Dec 2005 14:36:19 -0000
@@ -1,3 +1,9 @@
+2005-11-18  Gary Benson  <address@hidden>
+
+       * java/io/RandomAccessFile.java (RandomAccessFile): Don't create
+       DataOutputStream for read-only files to avoid unnecessary security
+       manager check.
+
 2005-12-05  Mark Wielaard  <address@hidden>
Fixes bug classpath/25257
Index: java/io/RandomAccessFile.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/RandomAccessFile.java,v
retrieving revision 1.47
diff -u -r1.47 RandomAccessFile.java
--- java/io/RandomAccessFile.java       2 Jul 2005 20:32:38 -0000       1.47
+++ java/io/RandomAccessFile.java       5 Dec 2005 14:36:19 -0000
@@ -124,7 +124,10 @@
ch = FileChannelImpl.create(file, fdmode);
     fd = new FileDescriptor(ch);
-    out = new DataOutputStream (new FileOutputStream (fd));
+    if ((fdmode & FileChannelImpl.WRITE) != 0)
+      out = new DataOutputStream (new FileOutputStream (fd));
+    else
+      out = null;
     in = new DataInputStream (new FileInputStream (fd));
   }
@@ -766,6 +769,9 @@
    */
   public void write (int oneByte) throws IOException
   {
+    if (out == null)
+      throw new IOException("Bad file descriptor");
+

The real error is that the file was opened read-only. A message saying "Bad file descriptor" does not convey that information. If the only reason that out can be null is that it was opened read-only, then I think all the exception messages should reflect that.

David Daney.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]