<AWT Dev> Small fix for crasher in AWT
Artem Ananiev
artem.ananiev at oracle.com
Mon Dec 3 02:43:21 PST 2012
Hi, Andrew,
JNU_GetEnv will crash, if "jvm" parameter is NULL. I don't know if this
is a possible case, but I see (jvm != NULL) check, which makes be
believe it's possible.
The rest of the fix looks fine.
Thanks,
Artem
On 11/30/2012 2:55 PM, Andrew Haley wrote:
> This one was reported by the LibreOffice folks.
>
> We don't check the return argument of JNU_GetEnv() in ToolkitErrorHandler:
>
>
> static int ToolkitErrorHandler(Display * dpy, XErrorEvent * event) {
> if (jvm != NULL) {
> JNIEnv * env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
> return JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit", "globalErrorHandler", "(JJ)I",
> ptr_to_jlong(dpy), ptr_to_jlong(event)).i;
> } else {
> return 0;
> }
> }
>
>
> JNU_GetEnv() will return NULL if this thread is not a Java thread, so
> we crash. This will happen if SWT is loaded in an application that
> uses X itself in some threads.
>
> The patch is pretty trivial, we just have to check env before using it:
>
>
> --- jdk/src/solaris/native/sun/xawt/XlibWrapper.c~ 2012-10-11 17:20:54.000000000 +0100
> +++ jdk/src/solaris/native/sun/xawt/XlibWrapper.c 2012-11-30 10:52:19.980613972 +0000
> @@ -1260,13 +1260,15 @@
>
> JavaVM* jvm = NULL;
> static int ToolkitErrorHandler(Display * dpy, XErrorEvent * event) {
> + JNIEnv * env;
> if (jvm != NULL) {
> - JNIEnv * env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
> - return JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit", "globalErrorHandler", "(JJ)I",
> - ptr_to_jlong(dpy), ptr_to_jlong(event)).i;
> - } else {
> - return 0;
> + env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
> + if (env) {
> + return JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit", "globalErrorHandler", "(JJ)I",
> + ptr_to_jlong(dpy), ptr_to_jlong(event)).i;
> + }
> }
> + return 0;
> }
>
> /*
>
>
> Andrew.
>
More information about the awt-dev
mailing list