From: Ryan Gonzalez Date: Thu, 13 Apr 2017 15:31:00 +0000 (+0300) Subject: Fix crash in FirstDLOpenedLinkMap if app linked statically (Alpine Linux) X-Git-Tag: v7.4.6~103 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2acebe64013101e9e85c596b49bcdde0ecb05a82;p=gc 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. --- diff --git a/dyn_load.c b/dyn_load.c index 5a3d7087..f327cddf 100644 --- a/dyn_load.c +++ b/dyn_load.c @@ -188,13 +188,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; } } @@ -711,10 +714,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; } }