Patch: FYI: a few JNI fixes

Tom Tromey tromey@redhat.com
Fri Jan 31 22:49:00 GMT 2003


For the trunk and the 3.3 branch.

Today I happened to run across a few missing JNI checks.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* jni.cc (_Jv_JNI_NewObjectArray): Check that initializer can be
	cast to element type.
	(_Jv_JNI_SetObjectArrayElement): Check array bounds.
	(_Jv_JNI_GetObjectArrayElement): Likewise.

Index: jni.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni.cc,v
retrieving revision 1.68
diff -u -r1.68 jni.cc
--- jni.cc 3 Dec 2002 03:54:05 -0000 1.68
+++ jni.cc 31 Jan 2003 22:34:47 -0000
@@ -1,6 +1,6 @@
 // jni.cc - JNI implementation, including the jump table.
 
-/* Copyright (C) 1998, 1999, 2000, 2001, 2002  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -1388,6 +1388,7 @@
       elementClass = unwrap (elementClass);
       init = unwrap (init);
 
+      _Jv_CheckCast (elementClass, init);
       jarray result = JvNewObjectArray (length, elementClass, init);
       return (jarray) wrap_value (env, result);
     }
@@ -1402,6 +1403,8 @@
 (JNICALL _Jv_JNI_GetObjectArrayElement) (JNIEnv *env, jobjectArray array, 
                                          jsize index)
 {
+  if ((unsigned) index >= (unsigned) array->length)
+    _Jv_ThrowBadArrayIndex (index);
   jobject *elts = elements (unwrap (array));
   return wrap_value (env, elts[index]);
 }
@@ -1416,6 +1419,8 @@
       value = unwrap (value);
 
       _Jv_CheckArrayStore (array, value);
+      if ((unsigned) index >= (unsigned) array->length)
+	_Jv_ThrowBadArrayIndex (index);
       jobject *elts = elements (array);
       elts[index] = value;
     }



More information about the Java-patches mailing list