summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/exit.c
diff options
context:
space:
mode:
authordhartmei <dhartmei@openbsd.org>2002-09-14 22:03:14 +0000
committerdhartmei <dhartmei@openbsd.org>2002-09-14 22:03:14 +0000
commit8d62ee40dc28d335867f292dd8aab66f53e20b5b (patch)
treead54f039e1d7d49a8f9d2f8fe09f8b447e2e743f /lib/libc/stdlib/exit.c
parentrecognize AppleKiwi (diff)
downloadwireguard-openbsd-8d62ee40dc28d335867f292dd8aab66f53e20b5b.tar.xz
wireguard-openbsd-8d62ee40dc28d335867f292dd8aab66f53e20b5b.zip
Move __cleanup into mprotect'ed page to prevent unintentional modifications
similar to the atexit handlers. Idea and help deraadt@, ok deraadt@
Diffstat (limited to 'lib/libc/stdlib/exit.c')
-rw-r--r--lib/libc/stdlib/exit.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/libc/stdlib/exit.c b/lib/libc/stdlib/exit.c
index c69639125ef..e22bd5178e6 100644
--- a/lib/libc/stdlib/exit.c
+++ b/lib/libc/stdlib/exit.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: exit.c,v 1.7 2002/08/30 07:58:07 dhartmei Exp $";
+static char *rcsid = "$OpenBSD: exit.c,v 1.8 2002/09/14 22:03:14 dhartmei Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -42,8 +42,6 @@ static char *rcsid = "$OpenBSD: exit.c,v 1.7 2002/08/30 07:58:07 dhartmei Exp $"
#include "atexit.h"
#include "thread_private.h"
-void (*__cleanup)();
-
/*
* This variable is zero until a process has created a thread.
* It is used to avoid calling locking functions in libc when they
@@ -67,13 +65,13 @@ exit(status)
p = __atexit;
while (p != NULL) {
for (n = p->ind; --n >= 0;)
- (*p->fns[n])();
+ if (p->fns[n] != NULL)
+ (*p->fns[n])();
q = p;
p = p->next;
munmap(q, pgsize);
}
}
- if (__cleanup)
- (*__cleanup)();
+ /* cleanup, if registered, was called through fns[0] in the last page */
_exit(status);
}