From b7dca610d1814659749106e97812beb2a795bace Mon Sep 17 00:00:00 2001
From: Enrico Horn <farmboy0+winehq@googlemail.com>
Date: Sat, 21 Apr 2018 02:40:37 +0200
Subject: [PATCH resend] winex11.drv: handle missing thread data in X11DRV_get_ic
To: wine-devel@winehq.org

Hi,
This patch fixes a crash in winex11.drv when loading IME.

This happens in Final Fantasy XI when using Ashita or Windower
3rd party applications.

There has been no bug reported I just fixed the bug for myself.

Here is the crash record:

Unhandled exception: page fault on write access to 0x00000014 in 32-bit code (0x7d85a94b).
Register dump:
 CS:0023 SS:002b DS:002b ES:002b FS:0063 GS:006b
 EIP:7d85a94b ESP:0836fd10 EBP:0836fd38 EFLAGS:00010212(  R- --  I   -A- - )
 EAX:00000000 EBX:0015abe8 ECX:00010050 EDX:00000000
 ESI:00000000 EDI:7d894000
Stack dump:
0x0836fd10:  001e60c8 00000158 0836fdb8 00010050
0x0836fd20:  00000000 7d894000 7d85a90b 7d894000
0x0836fd30:  001e60cc 001e60c8 0836fd58 7d86560b
0x0836fd40:  00010050 00000035 7d827a09 7d8655fa
0x0836fd50:  7d894000 001e60cc 0836fd98 7d83c0ef
0x0836fd60:  00010050 7d894000 0836fd98 7d83bfb0
Backtrace:
=>0 0x7d85a94b X11DRV_get_ic+0x4b(hwnd=0x10050) [/mnt/work/Repositories/wine/dlls/winex11.drv/window.c:2040] in winex11 (0x0836fd38)
  1 0x7d86560b X11DRV_ForceXIMReset+0x1a(hwnd=0x10050) [/mnt/work/Repositories/wine/dlls/winex11.drv/xim.c:255] in winex11 (0x0836fd58)
  2 0x7d83c0ef NotifyIME+0x17e(hIMC=<couldn't compute location>, dwAction=<couldn't compute location>, dwIndex=<couldn't compute location>, dwValue=<couldn't compute location>) [/mnt/work/Repositories/wine/dlls/winex11.drv/ime.c:764] in winex11 (0x0836fd98)
  3 0x7dc80793 ImmNotifyIME+0x62(hIMC=<couldn't compute location>, dwAction=<couldn't compute location>, dwIndex=<couldn't compute location>, dwValue=<couldn't compute location>) [/mnt/work/Repositories/wine/dlls/imm32/imm.c:2189] in imm32 (0x0836fde8)
0x7d85a94b X11DRV_get_ic+0x4b [/mnt/work/Repositories/wine/dlls/winex11.drv/window.c:2040] in winex11: movl     %ecx,0x14(%eax)
2040            x11drv_thread_data()->last_xic_hwnd = hwnd;

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46263
Signed-off-by: Enrico Horn <farmboy0+winehq@googlemail.com>
---
 dlls/winex11.drv/window.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/dlls/winex11.drv/window.c b/dlls/winex11.drv/window.c
index 7a3b340e19a..7dce6816ad7 100644
--- a/dlls/winex11.drv/window.c
+++ b/dlls/winex11.drv/window.c
@@ -2034,6 +2034,11 @@ XIC X11DRV_get_ic( HWND hwnd )
     XIM xim;
     XIC ret = 0;
 
+    if (!x11drv_thread_data())
+    {
+        release_win_data( data );
+        return NULL;
+    }
     if (data)
     {
         x11drv_thread_data()->last_xic_hwnd = hwnd;
-- 
2.19.1

