diff options
| author | dhartmei <> | 2002-09-14 22:03:14 +0000 | 
|---|---|---|
| committer | dhartmei <> | 2002-09-14 22:03:14 +0000 | 
| commit | 99933708b28d8f1a889e6109eb237499bf59eba2 (patch) | |
| tree | 95adbcf0e9cc0d976e8e7b18bd1836b0faa0ecbf /src/lib/libc/stdlib/abort.c | |
| parent | 3a3a489a756f2852d798376f20cc0d4ab609c866 (diff) | |
| download | openbsd-99933708b28d8f1a889e6109eb237499bf59eba2.tar.gz openbsd-99933708b28d8f1a889e6109eb237499bf59eba2.tar.bz2 openbsd-99933708b28d8f1a889e6109eb237499bf59eba2.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 'src/lib/libc/stdlib/abort.c')
| -rw-r--r-- | src/lib/libc/stdlib/abort.c | 16 | 
1 files changed, 10 insertions, 6 deletions
diff --git a/src/lib/libc/stdlib/abort.c b/src/lib/libc/stdlib/abort.c index 41a9f0f48b..7057f9b1ad 100644 --- a/src/lib/libc/stdlib/abort.c +++ b/src/lib/libc/stdlib/abort.c  | |||
| @@ -32,19 +32,19 @@ | |||
| 32 | */ | 32 | */ | 
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) | 
| 35 | static char *rcsid = "$OpenBSD: abort.c,v 1.7 2001/08/12 12:03:01 heko Exp $"; | 35 | static char *rcsid = "$OpenBSD: abort.c,v 1.8 2002/09/14 22:03:14 dhartmei Exp $"; | 
| 36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ | 
| 37 | 37 | ||
| 38 | #include <signal.h> | 38 | #include <signal.h> | 
| 39 | #include <stdlib.h> | 39 | #include <stdlib.h> | 
| 40 | #include <unistd.h> | 40 | #include <unistd.h> | 
| 41 | #include "thread_private.h" | 41 | #include "thread_private.h" | 
| 42 | 42 | #include "atexit.h" | |
| 43 | void (*__cleanup)(); | ||
| 44 | 43 | ||
| 45 | void | 44 | void | 
| 46 | abort() | 45 | abort() | 
| 47 | { | 46 | { | 
| 47 | struct atexit *p = __atexit; | ||
| 48 | static int cleanup_called = 0; | 48 | static int cleanup_called = 0; | 
| 49 | sigset_t mask; | 49 | sigset_t mask; | 
| 50 | 50 | ||
| @@ -64,9 +64,13 @@ abort() | |||
| 64 | /* | 64 | /* | 
| 65 | * POSIX requires we flush stdio buffers on abort | 65 | * POSIX requires we flush stdio buffers on abort | 
| 66 | */ | 66 | */ | 
| 67 | if (cleanup_called == 0 && __cleanup != NULL) { | 67 | if (cleanup_called == 0) { | 
| 68 | cleanup_called = 1; | 68 | while (p != NULL && p->next != NULL) | 
| 69 | (*__cleanup)(); | 69 | p = p->next; | 
| 70 | if (p != NULL && p->fns[0] != NULL) { | ||
| 71 | cleanup_called = 1; | ||
| 72 | (*p->fns[0])(); | ||
| 73 | } | ||
| 70 | } | 74 | } | 
| 71 | 75 | ||
| 72 | (void)kill(getpid(), SIGABRT); | 76 | (void)kill(getpid(), SIGABRT); | 
