From eb360eca6e023243b5b629ad6a1aa68ebeba8c4c Mon Sep 17 00:00:00 2001 From: jhb Date: Mon, 16 Apr 2018 20:45:21 +0000 Subject: [PATCH] MFC 331324: Ensure thread library is initialized in pthread_testcancel(). Call _thr_check_init() before reading curthread in pthread_testcancel(). If a constructor in a library creates a semaphore via sem_init() and then waits for it via sem_wait(), the program can core dump in _pthread_testcancel() called from sem_wait(). This is because the semaphore implementation lives in libc, so the library's constructors can be run before libthr's constructors. Sponsored by: DARPA / AFRL git-svn-id: svn://svn.freebsd.org/base/stable/10@332633 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- lib/libthr/thread/thr_cancel.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/libthr/thread/thr_cancel.c b/lib/libthr/thread/thr_cancel.c index beae707ca..f5af1aefe 100644 --- a/lib/libthr/thread/thr_cancel.c +++ b/lib/libthr/thread/thr_cancel.c @@ -130,8 +130,10 @@ _pthread_setcanceltype(int type, int *oldtype) void _pthread_testcancel(void) { - struct pthread *curthread = _get_curthread(); + struct pthread *curthread; + _thr_check_init(); + curthread = _get_curthread(); testcancel(curthread); } -- 2.45.0