From 99933708b28d8f1a889e6109eb237499bf59eba2 Mon Sep 17 00:00:00 2001 From: dhartmei <> Date: Sat, 14 Sep 2002 22:03:14 +0000 Subject: Move __cleanup into mprotect'ed page to prevent unintentional modifications similar to the atexit handlers. Idea and help deraadt@, ok deraadt@ --- src/lib/libc/stdlib/exit.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/lib/libc/stdlib/exit.c') diff --git a/src/lib/libc/stdlib/exit.c b/src/lib/libc/stdlib/exit.c index c69639125e..e22bd5178e 100644 --- a/src/lib/libc/stdlib/exit.c +++ b/src/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 @@ -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); } -- cgit v1.2.3-55-g6feb