mirror of
				https://github.com/jart/cosmopolitan.git
				synced 2025-10-26 11:10:58 +00:00 
			
		
		
		
	Fix --strace use-after-free in pthread_join()
This commit is contained in:
		
							parent
							
								
									d1d4388201
								
							
						
					
					
						commit
						f2c8ddbbe3
					
				
					 2 changed files with 5 additions and 5 deletions
				
			
		|  | @ -22,11 +22,8 @@ | ||||||
| #include "libc/thread/thread.h" | #include "libc/thread/thread.h" | ||||||
| 
 | 
 | ||||||
| int _pthread_tid(struct PosixThread *pt) { | int _pthread_tid(struct PosixThread *pt) { | ||||||
|   if (IsWindows())  // xxx: fixme
 |  | ||||||
|     return pt->ptid; |  | ||||||
|   int tid = 0; |   int tid = 0; | ||||||
|   while (pt && !(tid = atomic_load_explicit(&pt->ptid, memory_order_acquire))) { |   while (pt && !(tid = atomic_load_explicit(&pt->ptid, memory_order_acquire))) | ||||||
|     pthread_pause_np(); |     pthread_pause_np(); | ||||||
|   } |  | ||||||
|   return tid; |   return tid; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -103,10 +103,13 @@ static errno_t _pthread_wait(atomic_int *ctid, struct timespec *abstime) { | ||||||
|  */ |  */ | ||||||
| errno_t pthread_timedjoin_np(pthread_t thread, void **value_ptr, | errno_t pthread_timedjoin_np(pthread_t thread, void **value_ptr, | ||||||
|                              struct timespec *abstime) { |                              struct timespec *abstime) { | ||||||
|  |   int tid; | ||||||
|   errno_t err; |   errno_t err; | ||||||
|   struct PosixThread *pt; |   struct PosixThread *pt; | ||||||
|   enum PosixThreadStatus status; |   enum PosixThreadStatus status; | ||||||
|   pt = (struct PosixThread *)thread; |   pt = (struct PosixThread *)thread; | ||||||
|  |   tid = _pthread_tid(pt); | ||||||
|  |   unassert(_pthread_tid(pt)); | ||||||
|   status = atomic_load_explicit(&pt->pt_status, memory_order_acquire); |   status = atomic_load_explicit(&pt->pt_status, memory_order_acquire); | ||||||
|   // "The behavior is undefined if the value specified by the thread
 |   // "The behavior is undefined if the value specified by the thread
 | ||||||
|   //  argument to pthread_join() does not refer to a joinable thread."
 |   //  argument to pthread_join() does not refer to a joinable thread."
 | ||||||
|  | @ -121,7 +124,7 @@ errno_t pthread_timedjoin_np(pthread_t thread, void **value_ptr, | ||||||
|     } |     } | ||||||
|     _pthread_unref(pt); |     _pthread_unref(pt); | ||||||
|   } |   } | ||||||
|   STRACE("pthread_timedjoin_np(%d, %s, %s) → %s", _pthread_tid(pt), |   STRACE("pthread_timedjoin_np(%d, %s, %s) → %s", tid, | ||||||
|          DescribeReturnValue(alloca(30), err, value_ptr), |          DescribeReturnValue(alloca(30), err, value_ptr), | ||||||
|          DescribeTimespec(err ? -1 : 0, abstime), DescribeErrno(err)); |          DescribeTimespec(err ? -1 : 0, abstime), DescribeErrno(err)); | ||||||
|   return err; |   return err; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue