8211826: StringIndexOutOfBoundsException happens via GetStringUTFRegion()
Reviewed-by: serb
This commit is contained in:
parent
1d922fee0e
commit
0ea35e9bb9
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -113,6 +113,7 @@ Java_sun_awt_UNIXToolkit_load_1gtk_1icon(JNIEnv *env, jobject this,
|
||||
{
|
||||
#ifndef HEADLESS
|
||||
int len;
|
||||
jsize jlen;
|
||||
char *filename_str = NULL;
|
||||
GError **error = NULL;
|
||||
|
||||
@ -122,6 +123,7 @@ Java_sun_awt_UNIXToolkit_load_1gtk_1icon(JNIEnv *env, jobject this,
|
||||
}
|
||||
|
||||
len = (*env)->GetStringUTFLength(env, filename);
|
||||
jlen = (*env)->GetStringLength(env, filename);
|
||||
filename_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
|
||||
sizeof(char), len + 1);
|
||||
if (filename_str == NULL) {
|
||||
@ -132,7 +134,7 @@ Java_sun_awt_UNIXToolkit_load_1gtk_1icon(JNIEnv *env, jobject this,
|
||||
free(filename_str);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
(*env)->GetStringUTFRegion(env, filename, 0, len, filename_str);
|
||||
(*env)->GetStringUTFRegion(env, filename, 0, jlen, filename_str);
|
||||
jboolean result = gtk->get_file_icon_data(env, filename_str, error,
|
||||
icon_upcall_method, this);
|
||||
|
||||
@ -159,6 +161,7 @@ Java_sun_awt_UNIXToolkit_load_1stock_1icon(JNIEnv *env, jobject this,
|
||||
{
|
||||
#ifndef HEADLESS
|
||||
int len;
|
||||
jsize jlen;
|
||||
char *stock_id_str = NULL;
|
||||
char *detail_str = NULL;
|
||||
jboolean result = JNI_FALSE;
|
||||
@ -169,18 +172,20 @@ Java_sun_awt_UNIXToolkit_load_1stock_1icon(JNIEnv *env, jobject this,
|
||||
}
|
||||
|
||||
len = (*env)->GetStringUTFLength(env, stock_id);
|
||||
jlen = (*env)->GetStringLength(env, stock_id);
|
||||
stock_id_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
|
||||
sizeof(char), len + 1);
|
||||
if (stock_id_str == NULL) {
|
||||
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
(*env)->GetStringUTFRegion(env, stock_id, 0, len, stock_id_str);
|
||||
(*env)->GetStringUTFRegion(env, stock_id, 0, jlen, stock_id_str);
|
||||
|
||||
/* Detail isn't required so check for NULL. */
|
||||
if (detail != NULL)
|
||||
{
|
||||
len = (*env)->GetStringUTFLength(env, detail);
|
||||
jlen = (*env)->GetStringLength(env, detail);
|
||||
detail_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc,
|
||||
sizeof(char), len + 1);
|
||||
if (detail_str == NULL) {
|
||||
@ -188,7 +193,7 @@ Java_sun_awt_UNIXToolkit_load_1stock_1icon(JNIEnv *env, jobject this,
|
||||
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
(*env)->GetStringUTFRegion(env, detail, 0, len, detail_str);
|
||||
(*env)->GetStringUTFRegion(env, detail, 0, jlen, detail_str);
|
||||
}
|
||||
|
||||
if (init_method(env, this)) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -24,11 +24,12 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "gtk_interface.h"
|
||||
#include "com_sun_java_swing_plaf_gtk_GTKEngine.h"
|
||||
|
||||
/* Static buffer for conversion from java.lang.String to UTF-8 */
|
||||
static char conversionBuffer[CONV_BUFFER_SIZE];
|
||||
static char conversionBuffer[(CONV_BUFFER_SIZE - 1) * 3 + 1];
|
||||
|
||||
const char *getStrFor(JNIEnv *env, jstring val)
|
||||
{
|
||||
@ -38,6 +39,7 @@ const char *getStrFor(JNIEnv *env, jstring val)
|
||||
length = CONV_BUFFER_SIZE-1;
|
||||
}
|
||||
|
||||
memset(conversionBuffer, 0, sizeof(conversionBuffer));
|
||||
(*env)->GetStringUTFRegion(env, val, 0, length, conversionBuffer);
|
||||
return conversionBuffer;
|
||||
}
|
||||
|
45
test/jdk/java/awt/Gtk/GtkJNITest/GtkIconTest.java
Normal file
45
test/jdk/java/awt/Gtk/GtkJNITest/GtkIconTest.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @key headful
|
||||
* @bug 8211826
|
||||
* @summary StringIndexOutOfBoundsException happens via GetStringUTFRegion()
|
||||
* @modules java.desktop/sun.awt
|
||||
* @requires (os.family == "linux")
|
||||
* @run main GtkIconTest
|
||||
*/
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import sun.awt.UNIXToolkit;
|
||||
|
||||
public class GtkIconTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
UNIXToolkit utk = (UNIXToolkit)Toolkit.getDefaultToolkit();
|
||||
if (utk.loadGTK()) {
|
||||
for (String s : new String[]{ "abc", "\u3042" }) {
|
||||
Object obj = utk.getGTKIcon(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user