Mercurial > pub > dyncall > dyncall
comparison 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 |
comparison
equal
deleted
inserted
replaced
311:5b1ff4c73194 | 312:18de5758980e |
---|---|
86 | 86 |
87 #include <link.h> | 87 #include <link.h> |
88 | 88 |
89 int dlGetLibraryPath(DLLib* pLib, char* sOut, int bufSize) | 89 int dlGetLibraryPath(DLLib* pLib, char* sOut, int bufSize) |
90 { | 90 { |
91 struct link_map* p; | 91 struct link_map* p = NULL; |
92 int l = -1; | 92 int l = -1; |
93 if(dlinfo(pLib, RTLD_DI_LINKMAP, &p) == 0) { | 93 /* on some platforms dlinfo() "succeeds" for any handle, returning a */ |
94 /* legit pointer to a struct w/o any fields set; fail if unset */ | |
95 if(dlinfo(pLib, RTLD_DI_LINKMAP, &p) == 0 && p && p->l_name) { | |
94 l = strlen(p->l_name); | 96 l = strlen(p->l_name); |
95 if(l < bufSize) /* l+'\0' <= bufSize */ | 97 if(l < bufSize) /* l+'\0' <= bufSize */ |
96 strcpy(sOut, p->l_name); | 98 strcpy(sOut, p->l_name); |
97 } | 99 } |
98 return l+1; /* strlen + '\0' */ | 100 return l+1; /* strlen + '\0' */ |