JBR-3948 Linux: SIGSEGV at [libawt_xawt] Java_sun_awt_X11_XInputMethod_createXICNative

The problem: the crashes occur in createStatusWindow() when calls like
adata->AwtColorMatch() end up going to 0x0 pc or some random inaccessible
memory. The only reason for that seems to be the
getDefaultConfig(screen) returning either NULL or garbage. That, in turn, probably
happens because of the wrong screen number provided. Before JBR-3623 was
fixed, awt_numScreens could've changed between the time the screen
number was chosen and the getDefaultConfig() call. After JBR-3623 was
fixed, this change is protected with the AWT lock, which this code
holds.
The fix: obtain the screen number via the Xlib API rather than the
ad-hoc loop though the root windows and return NULL if
getDefaultConfig() doesn't return useable data.

(cherry picked from commit 3d23e8d6a5)
This commit is contained in:
Maxim Kartashev
2021-12-22 13:37:27 +03:00
parent c9944f2428
commit 60eb17210c

View File

@@ -599,7 +599,6 @@ static StatusWindow *createStatusWindow(Window parent) {
int screen = 0;
int i;
AwtGraphicsConfigDataPtr adata;
extern int awt_numScreens;
/*hardcode the size right now, should get the size base on font*/
int width=80, height=22;
Window rootWindow;
@@ -610,21 +609,21 @@ static StatusWindow *createStatusWindow(Window parent) {
attrib.override_redirect = True;
attribmask = CWOverrideRedirect;
for (i = 0; i < awt_numScreens; i++) {
if (RootWindow(dpy, i) == rootWindow) {
screen = i;
break;
}
XGetWindowAttributes(dpy, parent, &xwa);
bw = 2; /*xwa.border_width does not have the correct value*/
if (xwa.screen != NULL) {
screen = XScreenNumberOfScreen(xwa.screen);
}
adata = getDefaultConfig(screen);
if (NULL == adata || NULL == adata->AwtColorMatch) {
return NULL;
}
bg = adata->AwtColorMatch(255, 255, 255, adata);
fg = adata->AwtColorMatch(0, 0, 0, adata);
light = adata->AwtColorMatch(195, 195, 195, adata);
dim = adata->AwtColorMatch(128, 128, 128, adata);
XGetWindowAttributes(dpy, parent, &xwa);
bw = 2; /*xwa.border_width does not have the correct value*/
/*compare the size difference between parent container
and shell widget, the diff should be the border frame
and title bar height (?)*/