Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20171110205829.18319-1-koorogi@koorogi.info>
Date: Fri, 10 Nov 2017 14:58:29 -0600
From: Bobby Bingham <koorogi@...rogi.info>
To: musl@...ts.openwall.com
Subject: [PATCH] save/restore errno around pthread_atfork handlers

If the syscall fails, errno must be preserved for the caller. There's no
guarantee that the handlers registered with pthread_atfork won't clobber
errno.
---
 src/process/fork.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/process/fork.c b/src/process/fork.c
index b96f0024..6602eafc 100644
--- a/src/process/fork.c
+++ b/src/process/fork.c
@@ -15,6 +15,7 @@ pid_t fork(void)
 {
 	pid_t ret;
 	sigset_t set;
+	int olderr;
 	__fork_handler(-1);
 	__block_all_sigs(&set);
 #ifdef SYS_fork
@@ -30,6 +31,10 @@ pid_t fork(void)
 		libc.threads_minus_1 = 0;
 	}
 	__restore_sigs(&set);
+
+	olderr = errno;
 	__fork_handler(!ret);
+	errno = olderr;
+
 	return ret;
 }
-- 
2.15.0

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.