summaryrefslogtreecommitdiff
path: root/dyn_load.c
diff options
context:
space:
mode:
authorRyan Gonzalez <rymg19@gmail.com>2017-04-13 18:31:00 +0300
committerIvan Maidanski <ivmai@mail.ru>2017-04-13 18:31:00 +0300
commit733ec752f6f8f1d6e43f2f4751fe1bddfeecb8ee (patch)
treebb961c0b2f6ad6c72f5caaa45a3a719261d8ada1 /dyn_load.c
parentee34ddf97f7725bd9e4f8fbb8ec7cc86a6b31957 (diff)
downloadbdwgc-733ec752f6f8f1d6e43f2f4751fe1bddfeecb8ee.tar.gz
Fix crash in FirstDLOpenedLinkMap if app linked statically (Alpine Linux)
Issue #154 (bdwgc). * dyn_load.c [SOLARISDL && !USE_PROC_FOR_LIBRARIES] (GC_FirstDLOpenedLinkMap): Do not dereference d_un.d_ptr if it is null. * dyn_load.c [(SCO_ELF || DGUX || HURD || LINUX || FREEBSD || NACL || NETBSD || OPENBSD) && !USE_PROC_FOR_LIBRARIES] (GC_FirstDLOpenedLinkMap): Likewise.
Diffstat (limited to 'dyn_load.c')
-rw-r--r--dyn_load.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/dyn_load.c b/dyn_load.c
index 69f637c5..1c50f902 100644
--- a/dyn_load.c
+++ b/dyn_load.c
@@ -185,13 +185,16 @@ GC_FirstDLOpenedLinkMap(void)
/* _DYNAMIC symbol not resolved. */
return(0);
}
- if( cachedResult == 0 ) {
+ if (cachedResult == 0) {
int tag;
for( dp = ((ElfW(Dyn) *)(&_DYNAMIC)); (tag = dp->d_tag) != 0; dp++ ) {
- if( tag == DT_DEBUG ) {
- struct link_map *lm
- = ((struct r_debug *)(dp->d_un.d_ptr))->r_map;
- if( lm != 0 ) cachedResult = lm->l_next; /* might be NULL */
+ if (tag == DT_DEBUG) {
+ struct r_debug *rd = (struct r_debug *)dp->d_un.d_ptr;
+ if (rd != NULL) {
+ struct link_map *lm = rd->r_map;
+ if (lm != NULL)
+ cachedResult = lm->l_next; /* might be NULL */
+ }
break;
}
}
@@ -713,10 +716,14 @@ GC_FirstDLOpenedLinkMap(void)
int tag;
for( dp = _DYNAMIC; (tag = dp->d_tag) != 0; dp++ ) {
- if( tag == DT_DEBUG ) {
- struct link_map *lm
- = ((struct r_debug *)(dp->d_un.d_ptr))->r_map;
- if( lm != 0 ) cachedResult = lm->l_next; /* might be NULL */
+ if (tag == DT_DEBUG) {
+ struct r_debug *rd = (struct r_debug *)dp->d_un.d_ptr;
+ /* d_ptr could be null if libs are linked statically. */
+ if (rd != NULL) {
+ struct link_map *lm = rd->r_map;
+ if (lm != NULL)
+ cachedResult = lm->l_next; /* might be NULL */
+ }
break;
}
}