From 45e0eb4b156f2155687cce268b07f10540fc507b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Thu, 26 Jan 2017 16:24:03 +0900 Subject: [PATCH] loader: Handle mod->VersionInfo == NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This can happen when a module fails to load: Program received signal SIGSEGV, Segmentation fault. UnloadModule (_mod=0x5555559d9280) at ../../../../hw/xfree86/loader/loadmod.c:848 848 name = mod->VersionInfo->modname; (gdb) bt #0 UnloadModule (_mod=0x5555559d9280) at ../../../../hw/xfree86/loader/loadmod.c:848 #1 0x00005555555ddd1b in LoadModule (module=module@entry=0x5555559c7ce0 "fbdev", options=0x0, modreq=modreq@entry=0x0, errmaj=errmaj@entry=0x7fffffffe8ec) at ../../../../hw/xfree86/loader/loadmod.c:824 #2 0x00005555555edfe9 in xf86LoadModules (list=list@entry=0x5555559dcf50, optlist=optlist@entry=0x0) at ../../../../hw/xfree86/common/xf86Init.c:1506 #3 0x00005555555ee7bc in InitOutput (pScreenInfo=pScreenInfo@entry=0x5555559abf80 , argc=argc@entry=4, argv=argv@entry=0x7fffffffeb18) at ../../../../hw/xfree86/common/xf86Init.c:484 #4 0x00005555555a885c in dix_main (argc=4, argv=0x7fffffffeb18, envp=) at ../../dix/main.c:197 #5 0x00007ffff5d582b1 in __libc_start_main (main=0x555555593130
, argc=4, argv=0x7fffffffeb18, init=, fini=, rtld_fini=, stack_end=0x7fffffffeb08) at ../csu/libc-start.c:291 #6 0x000055555559316a in _start () Fixes: 8e83eacb9e2d ("loader: Remove unused path and name from ModuleDescPtr") Signed-off-by: Michel Dänzer Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- hw/xfree86/loader/loadmod.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c index ca77c7a9d..09aae0ea2 100644 --- a/hw/xfree86/loader/loadmod.c +++ b/hw/xfree86/loader/loadmod.c @@ -837,7 +837,6 @@ void UnloadModule(void *_mod) { ModuleDescPtr mod = _mod; - const char *name; if (mod == (ModuleDescPtr) 1) return; @@ -845,17 +844,19 @@ UnloadModule(void *_mod) if (mod == NULL) return; - name = mod->VersionInfo->modname; + if (mod->VersionInfo) { + const char *name = mod->VersionInfo->modname; - if (mod->parent) - LogMessageVerbSigSafe(X_INFO, 3, "UnloadSubModule: \"%s\"\n", name); - else - LogMessageVerbSigSafe(X_INFO, 3, "UnloadModule: \"%s\"\n", name); + if (mod->parent) + LogMessageVerbSigSafe(X_INFO, 3, "UnloadSubModule: \"%s\"\n", name); + else + LogMessageVerbSigSafe(X_INFO, 3, "UnloadModule: \"%s\"\n", name); - if (mod->TearDownData != ModuleDuplicated) { - if ((mod->TearDownProc) && (mod->TearDownData)) - mod->TearDownProc(mod->TearDownData); - LoaderUnload(name, mod->handle); + if (mod->TearDownData != ModuleDuplicated) { + if ((mod->TearDownProc) && (mod->TearDownData)) + mod->TearDownProc(mod->TearDownData); + LoaderUnload(name, mod->handle); + } } if (mod->child)