diff dynload/dynload_unix.c @ 312:18de5758980e

- stability fix: avoid sigsegv in dynload's dlGetLibraryPath() in some cases (e.g. wrong handle given or OS specific quirk)
author Tassilo Philipp
date Tue, 29 Oct 2019 16:09:58 +0100
parents f5577f6bf97a
children b2e4e23d9953
line wrap: on
line diff
--- a/dynload/dynload_unix.c	Sat Oct 26 22:02:32 2019 +0200
+++ b/dynload/dynload_unix.c	Tue Oct 29 16:09:58 2019 +0100
@@ -88,9 +88,11 @@
 
 int dlGetLibraryPath(DLLib* pLib, char* sOut, int bufSize)
 {
-  struct link_map* p;
+  struct link_map* p = NULL;
   int l = -1;
-  if(dlinfo(pLib, RTLD_DI_LINKMAP, &p) == 0) {
+  /* on some platforms dlinfo() "succeeds" for any handle, returning a */
+  /* legit pointer to a struct w/o any fields set; fail if unset */
+  if(dlinfo(pLib, RTLD_DI_LINKMAP, &p) == 0 && p && p->l_name) {
     l = strlen(p->l_name);
     if(l < bufSize) /* l+'\0' <= bufSize */
       strcpy(sOut, p->l_name);