xfree86: duplicate xorg.conf device information before xf86NewInputDevice

xf86ConfigLayout.inputs contains the information from the xorg.conf
file. Passing this into xf86NewInputDevice means the device will get
cleaned up on exit and the pointers in xf86ConfigLayout.inputs are left
dangling. In the second server generation, this results in a server
crash.

Also, rename pDev to pInfo. pDev is pretty much reserved for DeviceIntPtr
types.

Reproducible: AutoAddDevices off and xorg.conf input sections, trigger
server regeneration.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
Peter Hutterer 2011-07-04 14:14:39 +10:00
parent 8ffddbcf72
commit f0d7e9db28

View File

@ -791,6 +791,21 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
NULL);
}
static InputInfoPtr
duplicateDevice(InputInfoPtr pInfo)
{
InputInfoPtr dup = calloc(1, sizeof(InputInfoRec));
if (dup) {
dup->name = strdup(pInfo->name);
dup->driver = strdup(pInfo->driver);
dup->options = xf86OptionListDuplicate(pInfo->options);
/* type_name is a const string */
dup->type_name = pInfo->type_name;
dup->fd = -1;
}
return dup;
}
/*
* InitInput --
* Initialize all supported input devices.
@ -799,7 +814,7 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
void
InitInput(int argc, char **argv)
{
InputInfoPtr* pDev;
InputInfoPtr* pInfo;
DeviceIntPtr dev;
xf86Info.vtRequestsPending = FALSE;
@ -807,14 +822,21 @@ InitInput(int argc, char **argv)
mieqInit();
/* Initialize all configured input devices */
for (pDev = xf86ConfigLayout.inputs; pDev && *pDev; pDev++) {
for (pInfo = xf86ConfigLayout.inputs; pInfo && *pInfo; pInfo++) {
InputInfoPtr dup;
/* Replace obsolete keyboard driver with kbd */
if (!xf86NameCmp((*pDev)->driver, "keyboard")) {
strcpy((*pDev)->driver, "kbd");
if (!xf86NameCmp((*pInfo)->driver, "keyboard")) {
strcpy((*pInfo)->driver, "kbd");
}
/* Data passed into xf86NewInputDevice will be freed on shutdown.
* Duplicate from xf86ConfigLayout.inputs, otherwise we don't have any
* xorg.conf input devices in the second generation
*/
dup = duplicateDevice(*pInfo);
/* If one fails, the others will too */
if (xf86NewInputDevice(*pDev, &dev, TRUE) == BadAlloc)
if (xf86NewInputDevice(dup, &dev, TRUE) == BadAlloc)
break;
}