File: bugzilla_invalid_layout_segfault_fix.patch

package info (click to toggle)
libgnomekbd 3.28.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,696 kB
  • sloc: ansic: 5,919; makefile: 172; sh: 26; python: 14; javascript: 5
file content (79 lines) | stat: -rw-r--r-- 2,975 bytes parent folder | download | duplicates (2)
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
79
From 3ec4bc6648c447a28bac0fe3cbdbacf887f2a762 Mon Sep 17 00:00:00 2001
From: Antonio Ospite <ao2@ao2.it>
Date: Fri, 10 Nov 2017 12:45:25 +0100
Subject: [PATCH] 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.

https://bugzilla.gnome.org/show_bug.cgi?id=780151
---
 libgnomekbd/gkbd-keyboard-drawing.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Index: libgnomekbd-3.26.0/libgnomekbd/gkbd-keyboard-drawing.c
===================================================================
--- libgnomekbd-3.26.0.orig/libgnomekbd/gkbd-keyboard-drawing.c
+++ libgnomekbd-3.26.0/libgnomekbd/gkbd-keyboard-drawing.c
@@ -2280,7 +2280,6 @@ gkbd_keyboard_drawing_set_keyboard (Gkbd
 	free_cdik (drawing);
 	if (drawing->xkb)
 		XkbFreeKeyboard (drawing->xkb, 0, TRUE);	/* free_all = TRUE */
-	drawing->xkb = NULL;
 
 	if (names) {
 		drawing->xkb =
@@ -2305,12 +2304,13 @@ gkbd_keyboard_drawing_set_keyboard (Gkbd
 		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);