瀏覽代碼

libdl: first execute all destructors, then munmap library

Fix problem which might exist since 2011. We need to execute
the destructors for all dependant libraries, before munmap the
shared libraries, otherwise running destructor of a dependent library
might cause a segfault, trying to access an already unmapped memory.

This fixes for example segfaults while running php -m with ldap
module.

Reported-By: Dave Flogeras <dflogeras2@gmail.com>
Tested-By: Dave Flogeras <dflogeras2@gmail.com>
Waldemar Brodkorb 7 年之前
父節點
當前提交
14be0795f4
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      ldso/libdl/libdl.c

+ 5 - 0
ldso/libdl/libdl.c

@@ -849,7 +849,12 @@ static int do_dlclose(void *vhandle, int need_fini)
 					DL_CALL_FUNC_AT_ADDR (dl_elf_fini, tpnt->loadaddr, (int (*)(void)));
 				}
 			}
+		}
+	}
 
+	for (j = 0; j < handle->init_fini.nlist; ++j) {
+		tpnt = handle->init_fini.init_fini[j];
+		if (tpnt->usage_count == 0) {
 			_dl_if_debug_print("unmapping: %s\n", tpnt->libname);
 			end = 0;
 			for (i = 0, ppnt = tpnt->ppnt;