summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2017-05-30 06:38:11 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2017-05-30 06:38:11 +0000
commit024403aa7c5fc50c1a0404469c388fe313c79bfc (patch)
treece571efe04e302f79c773c965624ac82394b1414
parent1ab5ee0015e61e36e2dcd0f364dd0bcb7af1ec80 (diff)
Fix a race by always modifying the 'counter' variable while holding the
mutex. ok tedu@
-rw-r--r--regress/lib/libpthread/socket/1/socket1.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/regress/lib/libpthread/socket/1/socket1.c b/regress/lib/libpthread/socket/1/socket1.c
index 1752820b1fd..af751cdb8d2 100644
--- a/regress/lib/libpthread/socket/1/socket1.c
+++ b/regress/lib/libpthread/socket/1/socket1.c
@@ -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 */