summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2020-10-26 18:06:18 -0400
committerRich Felker <dalias@aerifal.cx>2020-10-26 18:12:25 -0400
commit3437e478ba932edbab18a90638c20be1f0141156 (patch)
tree8da34b267c3980cd633be6387b7dc1a2ec73f4f3
parent2d0bbe6c788938d1332609c014eeebc1dff966ac (diff)
downloadmusl-3437e478ba932edbab18a90638c20be1f0141156.tar.gz
fix reintroduction of errno clobbering by atfork handlers
commit bd153422f28634bb6e53f13f80beb8289d405267 reintroduced the bug fixed in c21051e90cd27a0b26be0ac66950b7396a156ba1 by refactoring the __syscall_ret into _Fork where it once again runs before the atfork handlers are called. since _Fork is a public interface that sets errno, this can't be fixed the way it was fixed last time without making new internal interfaces. instead, just save errno, and restore it only on error to ensure that a value of 0 is never restored.
-rw-r--r--src/process/fork.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/process/fork.c b/src/process/fork.c
index a12da01a..8d34a9c4 100644
--- a/src/process/fork.c
+++ b/src/process/fork.c
@@ -1,4 +1,5 @@
#include <unistd.h>
+#include <errno.h>
#include "libc.h"
static void dummy(int x) { }
@@ -8,6 +9,8 @@ pid_t fork(void)
{
__fork_handler(-1);
pid_t ret = _Fork();
+ int errno_save = errno;
__fork_handler(!ret);
+ if (ret<0) errno = errno_save;
return ret;
}