From 9bc825c4bac44e0c7eabb39727c4741b6b1a9255 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 31 Jan 2003 22:50:48 +0000 Subject: [PATCH] jni.cc (_Jv_JNI_NewObjectArray): Check that initializer can be cast to element type. * jni.cc (_Jv_JNI_NewObjectArray): Check that initializer can be cast to element type. (_Jv_JNI_SetObjectArrayElement): Check array bounds. (_Jv_JNI_GetObjectArrayElement): Likewise. From-SVN: r62210 --- libjava/ChangeLog | 5 +++++ libjava/jni.cc | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 028f1ae2f80..c060e1c2604 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,10 @@ 2003-01-31 Tom Tromey + * jni.cc (_Jv_JNI_NewObjectArray): Check that initializer can be + cast to element type. + (_Jv_JNI_SetObjectArrayElement): Check array bounds. + (_Jv_JNI_GetObjectArrayElement): Likewise. + * Makefile.in: Rebuilt. * Makefile.am (cond_x_ltlibrary): Renamed library to lib-gnu-awt-xlib.la. diff --git a/libjava/jni.cc b/libjava/jni.cc index b841b4fc481..c1a2880156d 100644 --- a/libjava/jni.cc +++ b/libjava/jni.cc @@ -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 @@ static jarray 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 @@ static jobject (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 @@ static void value = unwrap (value); _Jv_CheckArrayStore (array, value); + if ((unsigned) index >= (unsigned) array->length) + _Jv_ThrowBadArrayIndex (index); jobject *elts = elements (array); elts[index] = value; }