mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-28 00:21:52 +03:00
dlfcn: dlerror needs to call free from the base namespace [BZ #24773]
Calling free directly may end up freeing a pointer allocated by the dynamic loader using malloc from libc.so in the base namespace using the allocator from libc.so in a secondary namespace, which results in crashes. This commit redirects the free call through GLRO and the dynamic linker, to reach the correct namespace. It also cleans up the dlerror handling along the way, so that pthread_setspecific is no longer needed (which avoids triggering bug 24774).
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
#include <set-hooks.h>
|
||||
#include <libc-internal.h>
|
||||
#include <unwind-link.h>
|
||||
#include <dlfcn/dlerror.h>
|
||||
|
||||
#include "../nss/nsswitch.h"
|
||||
#include "../libio/libioP.h"
|
||||
@ -28,8 +29,6 @@ DEFINE_HOOK (__libc_subfreeres, (void));
|
||||
|
||||
symbol_set_define (__libc_freeres_ptrs);
|
||||
|
||||
extern __attribute__ ((weak)) void __libdl_freeres (void);
|
||||
|
||||
extern __attribute__ ((weak)) void __libpthread_freeres (void);
|
||||
|
||||
void __libc_freeres_fn_section
|
||||
@ -52,11 +51,6 @@ __libc_freeres (void)
|
||||
/* We run the resource freeing after IO cleanup. */
|
||||
RUN_HOOK (__libc_subfreeres, ());
|
||||
|
||||
/* Call the libdl list of cleanup functions
|
||||
(weak-ref-and-check). */
|
||||
if (&__libdl_freeres != NULL)
|
||||
__libdl_freeres ();
|
||||
|
||||
/* Call the libpthread list of cleanup functions
|
||||
(weak-ref-and-check). */
|
||||
if (&__libpthread_freeres != NULL)
|
||||
@ -66,6 +60,8 @@ __libc_freeres (void)
|
||||
__libc_unwind_link_freeres ();
|
||||
#endif
|
||||
|
||||
call_function_static_weak (__libc_dlerror_result_free);
|
||||
|
||||
for (p = symbol_set_first_element (__libc_freeres_ptrs);
|
||||
!symbol_set_end_p (__libc_freeres_ptrs, p); ++p)
|
||||
free (*p);
|
||||
|
@ -16,6 +16,7 @@
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <dlfcn/dlerror.h>
|
||||
#include <libc-internal.h>
|
||||
#include <malloc-internal.h>
|
||||
#include <resolv/resolv-internal.h>
|
||||
@ -36,6 +37,7 @@ __libc_thread_freeres (void)
|
||||
#endif
|
||||
call_function_static_weak (__res_thread_freeres);
|
||||
__glibc_tls_internal_free ();
|
||||
call_function_static_weak (__libc_dlerror_result_free);
|
||||
|
||||
/* This should come last because it shuts down malloc for this
|
||||
thread and the other shutdown functions might well call free. */
|
||||
|
Reference in New Issue
Block a user