[PATCH] dix: die if we can't activate or init the VCP/VCK.

Peter Hutterer peter.hutterer at who-t.net
Tue Feb 3 16:51:21 PST 2009


On Tue, Feb 03, 2009 at 04:46:05PM -0800, Dan Nicholson wrote:
> On Tue, Feb 3, 2009 at 4:30 PM, Peter Hutterer <peter.hutterer at who-t.net> wrote:
> > If we have a busted xkb setup, the XKB initialization on the core devices
> > fails and leaves us with dev->key->xkbInfo == NULL. This in turn causes
> > segfaults lateron.
> >
> > Return BadValue when the XKB configuration for a master device failed, and if
> > that happens for the VCP/VCK, die semi-gracefully.
> 
> Seems reasonable to me. I'd much rather die early than scratch my head
> on some later crash. Would it also be a good idea to return BadValue
> from CorePointerProc when InitPointerDeviceStruct fails? I don't know
> what you'd put in the log in that situation, though.

IPDS seems to only fail if we run out of memory. What about adding hunk 2?

Cheers,
  Peter

>From 29b2848cecf1ccde8fba7d7b1bfafa03873753d8 Mon Sep 17 00:00:00 2001
From: Peter Hutterer <peter.hutterer at who-t.net>
Date: Wed, 4 Feb 2009 10:11:13 +1000
Subject: [PATCH] dix: die if we can't activate or init the VCP/VCK.

If we have a busted xkb setup, the XKB initialization on the core devices
fails and leaves us with dev->key->xkbInfo == NULL. This in turn causes
segfaults lateron.

Return BadValue when the XKB configuration for a master device failed, and if
that happens for the VCP/VCK, die semi-gracefully.
The VCP init can only fail on OOM.

Reported by Aaron Plattner.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 dix/devices.c |   28 +++++++++++++++++++---------
 1 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/dix/devices.c b/dix/devices.c
index 6578229..f301d98 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -488,8 +488,13 @@ CoreKeyboardProc(DeviceIntPtr pDev, int what)
     switch (what) {
     case DEVICE_INIT:
         XkbGetRulesDflts(&rmlvo);
-        InitKeyboardDeviceStruct(pDev, &rmlvo, CoreKeyboardBell,
-                                 CoreKeyboardCtl);
+        if (!InitKeyboardDeviceStruct(pDev, &rmlvo, CoreKeyboardBell,
+                                      CoreKeyboardCtl))
+        {
+            ErrorF("Keyboard initialization failed. This could be a missing "
+                   "or incorrect setup of xkeyboard-config.\n");
+            return BadValue;
+        }
         return Success;
 
     case DEVICE_ON:
@@ -519,9 +524,13 @@ CorePointerProc(DeviceIntPtr pDev, int what)
     case DEVICE_INIT:
         for (i = 1; i <= 32; i++)
             map[i] = i;
-        InitPointerDeviceStruct((DevicePtr)pDev, map, 32,
+        if (!InitPointerDeviceStruct((DevicePtr)pDev, map, 32,
                                 (PtrCtrlProcPtr)NoopDDA,
-                                GetMotionHistorySize(), 2);
+                                GetMotionHistorySize(), 2))
+        {
+            ErrorF("Could not initialize device '%s'. OOM\n", pDev->name);
+            return BadAlloc; /* IPDS only fails on allocs */
+        }
         pDev->valuator->axisVal[0] = screenInfo.screens[0]->width / 2;
         pDev->last.valuators[0] = pDev->valuator->axisVal[0];
         pDev->valuator->axisVal[1] = screenInfo.screens[0]->height / 2;
@@ -554,11 +563,12 @@ InitCoreDevices(void)
                           &inputInfo.keyboard) != Success)
         FatalError("Failed to allocate core devices");
 
-    ActivateDevice(inputInfo.pointer);
-    ActivateDevice(inputInfo.keyboard);
-    EnableDevice(inputInfo.pointer);
-    EnableDevice(inputInfo.keyboard);
-
+    if (ActivateDevice(inputInfo.pointer) != Success ||
+        ActivateDevice(inputInfo.keyboard) != Success)
+        FatalError("Failed to activate core devices.");
+    if (!EnableDevice(inputInfo.pointer) ||
+        !EnableDevice(inputInfo.keyboard))
+        FatalError("Failed to enable core devices.");
 }
 
 /**
-- 
1.6.0.6





More information about the xorg mailing list