Fix a race by always modifying the 'counter' variable while holding the
authormpi <mpi@openbsd.org>
Tue, 30 May 2017 06:38:10 +0000 (06:38 +0000)
committermpi <mpi@openbsd.org>
Tue, 30 May 2017 06:38:10 +0000 (06:38 +0000)
mutex.

ok tedu@

regress/lib/libpthread/socket/1/socket1.c

index 1752820..af751cd 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: socket1.c,v 1.5 2015/11/19 18:37:49 deraadt Exp $     */
+/*     $OpenBSD: socket1.c,v 1.6 2017/05/30 06:38:10 mpi Exp $ */
 /*
  * Copyright (c) 1993, 1994, 1995, 1996 by Chris Provenzano and contributors, 
  * proven@mit.edu All rights reserved.
@@ -78,10 +78,10 @@ sock_connect(void *arg)
        CHECKe(connect(fd, (struct sockaddr *) &a_sout, sizeof(a_sout)));
        CHECKe(close(fd));
 
-       CHECKr(pthread_mutex_unlock(&mutex));
-
        CHECKe(fd = socket(AF_INET, SOCK_STREAM, 0));
        ASSERT(++counter == 3);
+
+       CHECKr(pthread_mutex_unlock(&mutex));
        CHECKe(connect(fd, (struct sockaddr *) &a_sout, sizeof(a_sout)));
 
        /* Ensure sock_read runs again */