Skip to content

Commit b7841fc

Browse files
heroin-moosearthurdejong
authored andcommitted
Do not pass invalid file descriptor to FD_ISSET()
Currently there is a race condition between the main thread and the workers threads. The main thread sets nslcd_serversocket to -1 without ensuring that all worker threads are stopped, giving them the window of opportunity to pass the now invalid fd to FD_ISSET(). This results in SIGBUS on musl libc. Closing the file descriptor is enough. I've also dropped close() in exithandler() to prevent misleading logs. The OS will close the socket anyway.
1 parent ed4041c commit b7841fc

File tree

1 file changed

+0
-8
lines changed

1 file changed

+0
-8
lines changed

nslcd/nslcd.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,6 @@ static void sig_handler(int signum)
221221
/* do some cleaning up before terminating */
222222
static void exithandler(void)
223223
{
224-
/* close socket if it's still in use */
225-
if (nslcd_serversocket >= 0)
226-
{
227-
if (close(nslcd_serversocket))
228-
log_log(LOG_WARNING, "problem closing server socket (ignored): %s",
229-
strerror(errno));
230-
}
231224
/* remove existing named socket */
232225
if (unlink(NSLCD_SOCKET) < 0)
233226
{
@@ -918,7 +911,6 @@ int main(int argc, char *argv[])
918911
i, strerror(errno));
919912
/* close server socket to trigger failures in threads waiting on accept() */
920913
close(nslcd_serversocket);
921-
nslcd_serversocket = -1;
922914
/* if we can, wait a few seconds for the threads to finish */
923915
#ifdef HAVE_PTHREAD_TIMEDJOIN_NP
924916
ts.tv_sec = time(NULL) + 3;

0 commit comments

Comments
 (0)