unsubmitted-dlopen-static-crash
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Sun, 14 Jan 2018 10:24:48 +0000 (10:24 +0000)
committerAurelien Jarno <aurel32@debian.org>
Sun, 14 Jan 2018 10:24:48 +0000 (10:24 +0000)
Gbp-Pq: Topic any
Gbp-Pq: Name unsubmitted-dlopen-static-crash.diff

elf/dl-open.c

index cec54db413cc47e5840ebf94d2d9881bf1f7bf34..b5baf3a9a8e68579c7b0ebd7e15ccfdbe366580f 100644 (file)
@@ -84,11 +84,22 @@ add_to_global (struct link_map *new)
      anymore.  Instead the malloc() implementation of the libc is
      used.  But this means the block from the main map cannot be used
      in an realloc() call.  Therefore we allocate a completely new
-     array the first time we have to add something to the locale scope.  */
+     array the first time we have to add something to the locale scope.
+
+     Also the list may be missing altogether if we are called via
+     dlopen() from a statically linked executable as in this case ld.so
+     has not been called and no dynamic symbols have been pulled yet.
+     Start a new list in this case.  */
 
   struct link_namespaces *ns = &GL(dl_ns)[new->l_ns];
   if (ns->_ns_global_scope_alloc == 0)
     {
+      /* See if we've got a list at all.  */
+      if (ns->_ns_main_searchlist == NULL)
+       ns->_ns_main_searchlist = calloc (1, sizeof (struct r_scope_elem));
+      if (ns->_ns_main_searchlist == NULL)
+       goto nomem;
+
       /* This is the first dynamic object given global scope.  */
       ns->_ns_global_scope_alloc
        = ns->_ns_main_searchlist->r_nlist + to_add + 8;