From: mpi Date: Tue, 30 May 2017 06:38:10 +0000 (+0000) Subject: Fix a race by always modifying the 'counter' variable while holding the X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=13739c113ef54cbb80484ba689bb28841a995e92;p=openbsd Fix a race by always modifying the 'counter' variable while holding the mutex. ok tedu@ --- 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 */