1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
From: Antonio Ospite <ao2@ao2.it>
Date: Fri, 10 Nov 2017 12:45:25 +0100
Subject: Fix a regression after commit 5f260b2b73a3 (Handle XkbGetKeyboard()
failing)
Passing names with invalid values to
gkbd_keyboard_drawing_set_keyboard() makes the library crash with
a segmentation fault.
This can be reproduced with gkbd-keyboard-display:
-----------------------------------------------------------------------
$ gdb --eval-comman=run --args gkbd-keyboard-display -l "INVALID"
...
Thread 1 "gkbd-keyboard-d" received signal SIGSEGV, Segmentation fault.
0x00007ffff54dec2e in get_preferred_height_for_width (...)
at gkbd-keyboard-drawing.c:2147
2147 drawing->xkb->geom->width_mm;
-----------------------------------------------------------------------
The same issue could be reproduced also with the test programs:
$ ./test/gkbd-keyboard-drawing-test --geometry="INVALID"
$ ./test/python_test.py "INVALID"
The spirit of commit 5f260b2b73a3 seems to be: let's not fail
prematurely in gkbd_keyboard_drawing_init() because it could still be
possible to get the XKeyboard in gkbd_keyboard_drawing_set_keyboard().
However in the implementation gkbd_keyboard_drawing_set_keyboard() ends
up returning always TRUE, unconditionally, even when calling
XkbGetKeyboard() fails there too.
Fix the issue by returning FALSE in gkbd_keyboard_drawing_set_keyboard()
when no keyboard was found, at that point there should really not be any
chances anymore to get the keyboard the user asked for.
While at it also remove the initalization of drawing->xkb in
gkbd_keyboard_drawing_set_keyboard() which is not needed and might hide
future bugs.
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=780151
---
libgnomekbd/gkbd-keyboard-drawing.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/libgnomekbd/gkbd-keyboard-drawing.c b/libgnomekbd/gkbd-keyboard-drawing.c
index 043b61b..425445e 100644
--- a/libgnomekbd/gkbd-keyboard-drawing.c
+++ b/libgnomekbd/gkbd-keyboard-drawing.c
@@ -2266,7 +2266,6 @@ gkbd_keyboard_drawing_set_keyboard (GkbdKeyboardDrawing * drawing,
free_cdik (drawing);
if (drawing->xkb)
XkbFreeKeyboard (drawing->xkb, 0, TRUE); /* free_all = TRUE */
- drawing->xkb = NULL;
if (names) {
drawing->xkb =
@@ -2291,12 +2290,13 @@ gkbd_keyboard_drawing_set_keyboard (GkbdKeyboardDrawing * drawing,
drawing->xkbOnDisplay = TRUE;
}
- if (drawing->xkb) {
- XkbSelectEventDetails (drawing->display, XkbUseCoreKbd,
- XkbIndicatorStateNotify,
- drawing->xkb->indicators->phys_indicators,
- drawing->xkb->indicators->phys_indicators);
- }
+ if (!drawing->xkb)
+ return FALSE;
+
+ XkbSelectEventDetails (drawing->display, XkbUseCoreKbd,
+ XkbIndicatorStateNotify,
+ drawing->xkb->indicators->phys_indicators,
+ drawing->xkb->indicators->phys_indicators);
alloc_cdik (drawing);
|