From 0e15697b53c9448ce9911aa6499b2ea0bda92af6 Mon Sep 17 00:00:00 2001 From: Peter Hutterer 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 Acked-by: Daniel Stone Acked-by: Dan Nicholson Signed-off-by: Aaron Plattner --- dix/devices.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/dix/devices.c b/dix/devices.c index 4f85c6d7c..934e6952f 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,14 @@ 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'. Out of memory.\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 +564,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."); } /**