Merge lp:~stolowski/unity-2d/check-xlistinputdevices-ptr into lp:unity-2d

Proposed by Paweł Stołowski on 2012-04-10
Status: Merged
Approved by: Albert Astals Cid on 2012-04-10
Approved revision: 1056
Merged at revision: 1055
Proposed branch: lp:~stolowski/unity-2d/check-xlistinputdevices-ptr
Merge into: lp:unity-2d
Diff against target: 54 lines (+20/-18)
1 file modified
libunity-2d-private/src/keymonitor.cpp (+20/-18)
To merge this branch: bzr merge lp:~stolowski/unity-2d/check-xlistinputdevices-ptr
Reviewer Review Type Date Requested Status
Albert Astals Cid (community) 2012-04-10 Approve on 2012-04-10
Review via email: mp+101403@code.launchpad.net

Commit message

Check list pointer returned by XListInputDevices, as it may be null in VNC session, while XListInputDevices indicates positive number of devices. This would crash unity-2d-shell.

Description of the change

Check list pointer returned by XListInputDevices, as it may be null in VNC session, while XListInputDevices indicates positive number of devices. This would crash unity-2d-shell.
UNBLOCK

To post a comment you must log in.
1056. By Paweł Stołowski on 2012-04-10

Changed NULL pointer condition.

Albert Astals Cid (aacid) wrote :

Makes sense

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/keymonitor.cpp'
2--- libunity-2d-private/src/keymonitor.cpp 2011-10-28 22:18:46 +0000
3+++ libunity-2d-private/src/keymonitor.cpp 2012-04-10 16:10:28 +0000
4@@ -98,30 +98,32 @@
5
6 devices = XListInputDevices(m_display, &num_devices);
7
8- for(i=0; i<num_devices; i++) {
9- device = XOpenDevice(m_display, devices[i].id);
10- if (device == NULL) {
11- /* That's not critical since "Virtual core..." devices don't
12- allow opening. */
13- UQ_DEBUG << "Could not open device: " << devices[i].name;
14- continue;
15- }
16+ /* Check returned list pointer as XListInputDevices may return NULL with num_devices>0, see LP: #965464 */
17+ if (devices != NULL) {
18+ for(i=0; i<num_devices; i++) {
19+ device = XOpenDevice(m_display, devices[i].id);
20+ if (device == NULL) {
21+ /* That's not critical since "Virtual core..." devices don't
22+ allow opening. */
23+ UQ_DEBUG << "Could not open device: " << devices[i].name;
24+ continue;
25+ }
26
27- if (devices[i].use == IsXExtensionKeyboard) {
28- for (info=device->classes, j=0; j < device->num_classes; j++, info++) {
29- if (info->input_class == KeyClass) {
30- DeviceKeyPress(device, key_press_type, event_class);
31- m_eventList.append(event_class);
32- DeviceMappingNotify(device, notify_type, event_class);
33- m_eventList.append(event_class);
34+ if (devices[i].use == IsXExtensionKeyboard) {
35+ for (info=device->classes, j=0; j < device->num_classes; j++, info++) {
36+ if (info->input_class == KeyClass) {
37+ DeviceKeyPress(device, key_press_type, event_class);
38+ m_eventList.append(event_class);
39+ DeviceMappingNotify(device, notify_type, event_class);
40+ m_eventList.append(event_class);
41+ }
42 }
43 }
44+ XCloseDevice(m_display, device);
45 }
46- XCloseDevice(m_display, device);
47+ XFreeDeviceList(devices);
48 }
49
50- XFreeDeviceList(devices);
51-
52 if (m_eventList.size() == 0) {
53 UQ_WARNING << "No input devices found.";
54 return false;

Subscribers

People subscribed via source and target branches