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: v8.0.0~789 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=733ec752f6f8f1d6e43f2f4751fe1bddfeecb8ee;p=platform%2Fupstream%2Flibgc.git 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 69f637c..1c50f90 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; } }