changeset 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 5b1ff4c73194
children 73b5b9e224e2
files dynload/dynload_unix.c test/dynload_plain/dynload_plain.c
diffstat 2 files changed, 5 insertions(+), 3 deletions(-) [+]
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);
--- a/test/dynload_plain/dynload_plain.c	Sat Oct 26 22:02:32 2019 +0200
+++ b/test/dynload_plain/dynload_plain.c	Tue Oct 29 16:09:58 2019 +0100
@@ -132,7 +132,7 @@
       dlFreeLibrary(pLib);
 
       /* check if dlGetLibraryPath returns 0 when trying to lookup dummy */
-      bs = dlGetLibraryPath((DLLib*)&r/*dummy addr in own addr space to avoid segv*/, queriedPath, 200);
+      bs = dlGetLibraryPath((DLLib*)&r/*dummy addr*/, queriedPath, 200);
       printf("path lookup failed as expected with bad lib handle: %d\n", bs == 0);
       r += (bs == 0);