[libxml2] Fix potentially-uninitialized critical section in Win32 DLL builds
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] Fix potentially-uninitialized critical section in Win32 DLL builds
- Date: Tue, 11 Feb 2020 11:10:27 +0000 (UTC)
commit 453bdfb95edd725fac1ca1c42634e8c9739b03fa
Author: Kevin Puetz <PuetzKevinA JohnDeere com>
Date: Mon Jan 13 18:28:34 2020 -0600
Fix potentially-uninitialized critical section in Win32 DLL builds
If non-parser parts of libxml (e.g. xmlwriter) are used before a parser,
xmlOnceInit may have run (e.g. via the many paths to xmlGetGlobalState),
but not xmlInitThreads (which is called only by xmlInitParser)
Once globalkey != TLS_OUT_OF_INDEXES (which can happen in many ways),
DLLMAIN(DLL_THREAD_DETACH) may attempt to lock cleanup_helpers_cs
before it is valid. This may happen even if the thread whose exit
is triggering DllMain is from code which is not linked to libxml.
globalkey and cleanup_helpers_cs should be initialized together,
with cleanup_helpers_cs initialized first and deleted last.
threads.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/threads.c b/threads.c
index 72df9ba9..503d2bfb 100644
--- a/threads.c
+++ b/threads.c
@@ -885,8 +885,6 @@ xmlInitThreads(void)
}
}
#endif /* XML_PTHREAD_WEAK */
-#elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) ||
defined(LIBXML_STATIC_FOR_DLL))
- InitializeCriticalSection(&cleanup_helpers_cs);
#endif
}
@@ -958,6 +956,9 @@ xmlOnceInit(void)
if (!run_once.done) {
if (InterlockedIncrement(&run_once.control) == 1) {
#if !defined(HAVE_COMPILER_TLS)
+#if !defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)
+ InitializeCriticalSection(&cleanup_helpers_cs);
+#endif
globalkey = TlsAlloc();
#endif
mainthread = GetCurrentThreadId();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]