Author: mturk
Date: Wed Jun 17 07:49:23 2009
New Revision: 785500

URL: http://svn.apache.org/viewvc?rev=785500&view=rev
Log:
Protect critical memory access

Modified:
    commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c?rev=785500&r1=785499&r2=785500&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c Wed Jun 17 
07:49:23 2009
@@ -408,8 +408,14 @@
     if ((mem = (*_E)->GetDirectBufferAddress(_E, bb)) != NULL) {
         /* This can cause core dump if address was
          * allocated using different method.
+         * Make sure you call Native.enableExceptionHandler() to
+         * throw an exception instead.
          */
-        free(mem);
+        ACR_TRY {
+            free(mem);
+        } ACR_CATCH() {
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ERUNTIME, EFAULT);
+        }
     }
     else {
         ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL,
@@ -452,7 +458,11 @@
         return;
     }
     if ((m = (*_E)->GetDirectBufferAddress(_E, bb))) {
-        memset(m, c, (size_t)count);
+        ACR_TRY {
+            memset(m, c, (size_t)count);
+        } ACR_CATCH() {
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ERUNTIME, EFAULT);
+        }
     }
     else {
         ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL,
@@ -497,7 +507,12 @@
     }
     if ((s = (*_E)->GetDirectBufferAddress(_E, srcb))) {
         if ((d = (*_E)->GetDirectBufferAddress(_E, dstb))) {
-            memcpy((char *)d + (size_t)dsto, (char *)s + (size_t)srco, 
(size_t)count);
+            ACR_TRY {
+                memcpy((char *)d + (size_t)dsto, (char *)s + (size_t)srco,
+                       (size_t)count);
+            } ACR_CATCH() {
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ERUNTIME, EFAULT);
+            }
         }
         else {
             ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ENULL,


Reply via email to