Author: jhb
Date: Mon Apr 16 20:45:21 2018
New Revision: 332633
URL: https://svnweb.freebsd.org/changeset/base/332633

Log:
  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

Modified:
  stable/10/lib/libthr/thread/thr_cancel.c
Directory Properties:
  stable/10/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/lib/libthr/thread/thr_cancel.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/10/lib/libthr/thread/thr_cancel.c
==============================================================================
--- stable/10/lib/libthr/thread/thr_cancel.c    Mon Apr 16 19:33:04 2018        
(r332632)
+++ stable/10/lib/libthr/thread/thr_cancel.c    Mon Apr 16 20:45:21 2018        
(r332633)
@@ -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);
 }
 
_______________________________________________
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"

Reply via email to