You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/06/30 08:58:12 UTC

svn commit: r789588 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/io/File.java main/native/include/acr_error.h main/native/os/unix/file.c main/native/test/testcase.c test/org/apache/commons/runtime/TestFile.java

Author: mturk
Date: Tue Jun 30 06:58:12 2009
New Revision: 789588

URL: http://svn.apache.org/viewvc?rev=789588&view=rev
Log:
Make sure we throw exception after string cleanup

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
    commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=789588&r1=789587&r2=789588&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Tue Jun 30 06:58:12 2009
@@ -39,6 +39,8 @@
                                         throws IOException, SecurityException;
     private static native int       fprot0(String pathname)
                                         throws IOException, SecurityException;
+    private static native long      inode0(String pathname)
+                                        throws IOException, SecurityException;
     private static native boolean   fprot1(String pathname, int prot)
                                         throws IOException, SecurityException;
     private static native boolean   fprot2(String pathname,
@@ -447,9 +449,19 @@
         return new File(getTargetPath());
     }
 
+    /**
+     * Return this abstract {@code File} system id.
+     *
+     * @return Existing {@code File} system id.
+     * @throws IOException if this {@code File} is not symbolic or hard link
+     *         or an I/O error occured.
+     * @throws SecurityException if search permission is denied for a
+     *         component of this abstract {@code File} pathname prefix.
+     */
     public long fileId()
+        throws IOException, SecurityException
     {
-        return 0L;
+        return inode0(getPath());
     }
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h?rev=789588&r1=789587&r2=789588&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Tue Jun 30 06:58:12 2009
@@ -123,9 +123,8 @@
 
 #endif
 #else
-static int _seh_error = 0;
 #define ACR_TRY
-#define ACR_CATCH() if (_seh_error)
+#define ACR_CATCH() if (0)
 
 #endif /* HAVE_MEMPROTECT */
 

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c?rev=789588&r1=789587&r2=789588&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Tue Jun 30 06:58:12 2009
@@ -123,29 +123,61 @@
     return type;
 }
 
+ACR_IO_EXPORT_DECLARE(jlong, File, inode0)(ACR_JNISTDARGS, jstring pathname)
+{
+    jlong rv = 0;
+    int   ex = EINVAL;
+
+    UNREFERENCED_O;
+    WITH_CSTR(pathname) {
+        struct_stat info;
+
+        if ((ex = stat(J2S(pathname), &info)) == 0) {
+            rv = (jlong)info.st_ino;
+        }
+        else
+            ex = ACR_GET_OS_ERROR();
+    } END_WITH_CSTR(pathname);
+
+    if (ex) {
+        if (ACR_STATUS_IS_EACCES(ex)) {
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+        }
+        else if (!ACR_STATUS_IS_EEXIST(ex)) {
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ex);
+        }
+    }
+    return rv;
+}
+
 ACR_IO_EXPORT_DECLARE(jboolean, File, mkslink0)(ACR_JNISTDARGS,
                                                 jstring target,
                                                 jstring lnkname)
 {
     jboolean rc = JNI_FALSE;
+    int ex = EINVAL;
 
     UNREFERENCED_O;
     WITH_CSTR(target) {
     WITH_CSTR(lnkname) {
         if (symlink(J2S(target), J2S(lnkname))) {
-            int err = ACR_GET_OS_ERROR();
-            if (ACR_STATUS_IS_EACCES(err)) {
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
-            }
-            else if (!ACR_STATUS_IS_EEXIST(err)) {
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, err);
-            }
+            ex = ACR_GET_OS_ERROR();
         }
-        else
+        else {
+            ex = 0;
             rc = JNI_TRUE;
+        }
     } END_WITH_CSTR(lnkname);
     } END_WITH_CSTR(target);
 
+    if (ex) {
+        if (ACR_STATUS_IS_EACCES(ex)) {
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+        }
+        else if (!ACR_STATUS_IS_EEXIST(ex)) {
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ex);
+        }
+    }
     return rc;
 }
 
@@ -154,24 +186,29 @@
                                                 jstring lnkname)
 {
     jboolean rc = JNI_FALSE;
+    int ex = EINVAL;
 
     UNREFERENCED_O;
     WITH_CSTR(target) {
     WITH_CSTR(lnkname) {
         if (link(J2S(target), J2S(lnkname))) {
-            int err = ACR_GET_OS_ERROR();
-            if (ACR_STATUS_IS_EACCES(err)) {
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
-            }
-            else if (!ACR_STATUS_IS_EEXIST(err)) {
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, err);
-            }
+            ex = ACR_GET_OS_ERROR();
         }
-        else
+        else {
+            ex = 0;
             rc = JNI_TRUE;
+        }
     } END_WITH_CSTR(lnkname);
     } END_WITH_CSTR(target);
 
+    if (ex) {
+        if (ACR_STATUS_IS_EACCES(ex)) {
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+        }
+        else if (!ACR_STATUS_IS_EEXIST(ex)) {
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ex);
+        }
+    }
     return rc;
 }
 
@@ -179,6 +216,7 @@
                                               jstring lnkname)
 {
     jstring rv = NULL;
+    int ex = EINVAL;
 
     UNREFERENCED_O;
     WITH_CSTR(lnkname) {
@@ -187,17 +225,23 @@
 
         rd = readlink(J2S(lnkname), buf, PATH_MAX - 1);
         if (rd < 0) {
-            if (errno == EACCES)
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
-            else
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, errno);
+            ex = ACR_GET_OS_ERROR();
         }
         else {
+            ex = 0;
             buf[rd] = '\0';
             rv = ACR_NewJavaStringA(_E, buf);
         }
     } END_WITH_CSTR(lnkname);
 
+    if (ex) {
+        if (ACR_STATUS_IS_EACCES(ex)) {
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+        }
+        else if (!ACR_STATUS_IS_EEXIST(ex)) {
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ex);
+        }
+    }
     return rv;
 }
 
@@ -340,7 +384,7 @@
 ACR_IO_EXPORT_DECLARE(jboolean, File, fprot2)(ACR_JNISTDARGS, jstring pathname,
                                               jobject usr, jobject grp)
 {
-    int rc = EINVAL;
+    int ex = EINVAL;
 
     UNREFERENCED_O;
     WITH_CSTR(pathname) {
@@ -348,17 +392,16 @@
         gid_t sgrp = ACR_DescriptorGetInt(_E, grp);
 
         if (chown(J2S(pathname), susr, sgrp))
-            rc = errno;
+            ex = ACR_GET_OS_ERROR();
         else
-            rc = 0;
+            ex = 0;
     } END_WITH_CSTR(pathname);
 
-    if (rc) {
-        rc = ACR_FROM_OS_ERROR(rc);
-        if  (ACR_STATUS_IS_EACCES(rc))
+    if (ex) {
+        if  (ACR_STATUS_IS_EACCES(ex))
             ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
         else
-            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, rc);
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, ex);
         return JNI_FALSE;
     }
     else

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=789588&r1=789587&r2=789588&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Tue Jun 30 06:58:12 2009
@@ -154,7 +154,7 @@
 
 ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test010)(ACR_JNISTDARGS, jstring s)
 {
-    jint l;
+    jint l = 0;
 
     WITH_USTR(s) {
        l = (jint)strlen(J2S(s));

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java?rev=789588&r1=789587&r2=789588&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java Tue Jun 30 06:58:12 2009
@@ -272,5 +272,21 @@
         f.delete();
     }
 
+    public void testFileId()
+        throws Exception
+    {
+        File f1 = new File("ffoo1");
+        f1.createNewFile();
+        File f2 = new File("ffoo2");
+        f2.createNewFile();
+        long i1 = f1.fileId();
+        long i2 = f2.fileId();
+        assertTrue("Zero",  i1 != 0L);
+        assertTrue("Eqaul", i1 != i2);
+
+        f1.delete();
+        f2.delete();
+    }
+
 }