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/regress/lib | |
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/regress/lib')
-rw-r--r-- | src/regress/lib/libc/atexit/Makefile | 6 | ||||
-rw-r--r-- | src/regress/lib/libc/atexit/atexit_test.c | 24 |
2 files changed, 20 insertions, 10 deletions
diff --git a/src/regress/lib/libc/atexit/Makefile b/src/regress/lib/libc/atexit/Makefile index 89625e2a7b..55c3f3981e 100644 --- a/src/regress/lib/libc/atexit/Makefile +++ b/src/regress/lib/libc/atexit/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2002/09/02 19:59:51 avsm Exp $ | 1 | # $OpenBSD: Makefile,v 1.3 2002/09/14 22:03:14 dhartmei Exp $ |
2 | 2 | ||
3 | NOMAN= | 3 | NOMAN= |
4 | PROG=atexit_test | 4 | PROG=atexit_test |
@@ -6,7 +6,9 @@ PROG=atexit_test | |||
6 | run-regress-atexit_test: ${PROG} | 6 | run-regress-atexit_test: ${PROG} |
7 | ./${PROG} -valid 2>${.OBJDIR}/valid.out | 7 | ./${PROG} -valid 2>${.OBJDIR}/valid.out |
8 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | 8 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok |
9 | ./${PROG} -invalid 2>${.OBJDIR}/invalid.out | 9 | ./${PROG} -invalid-atexit 2>${.OBJDIR}/invalid.out |
10 | cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok | ||
11 | ./${PROG} -invalid-cleanup 2>${.OBJDIR}/invalid.out | ||
10 | cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok | 12 | cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok |
11 | 13 | ||
12 | .include <bsd.regress.mk> | 14 | .include <bsd.regress.mk> |
diff --git a/src/regress/lib/libc/atexit/atexit_test.c b/src/regress/lib/libc/atexit/atexit_test.c index fcfe95cb02..fea95832ab 100644 --- a/src/regress/lib/libc/atexit/atexit_test.c +++ b/src/regress/lib/libc/atexit/atexit_test.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: atexit_test.c,v 1.1 2002/07/29 19:51:41 dhartmei Exp $ */ | 1 | /* $OpenBSD: atexit_test.c,v 1.2 2002/09/14 22:03:14 dhartmei Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2002 Daniel Hartmeier | 4 | * Copyright (c) 2002 Daniel Hartmeier |
@@ -39,9 +39,6 @@ | |||
39 | #include <signal.h> | 39 | #include <signal.h> |
40 | #include "/usr/src/lib/libc/stdlib/atexit.h" | 40 | #include "/usr/src/lib/libc/stdlib/atexit.h" |
41 | 41 | ||
42 | extern struct atexit *__atexit; | ||
43 | extern void (*__cleanup)(); | ||
44 | |||
45 | void handle_first(); | 42 | void handle_first(); |
46 | void handle_middle(); | 43 | void handle_middle(); |
47 | void handle_last(); | 44 | void handle_last(); |
@@ -57,8 +54,10 @@ main(int argc, char *argv[]) | |||
57 | int i; | 54 | int i; |
58 | 55 | ||
59 | if (argc != 2 || (strcmp(argv[1], "-valid") && | 56 | if (argc != 2 || (strcmp(argv[1], "-valid") && |
60 | strcmp(argv[1], "-invalid"))) { | 57 | strcmp(argv[1], "-invalid-atexit") && |
61 | fprintf(stderr, "%s -valid/-invalid\n", argv[0]); | 58 | strcmp(argv[1], "-invalid-cleanup"))) { |
59 | fprintf(stderr, "%s -valid/-invalid-atexit/-invalid-cleanup\n", | ||
60 | argv[0]); | ||
62 | return (1); | 61 | return (1); |
63 | } | 62 | } |
64 | fprintf(stderr, "main()\n"); | 63 | fprintf(stderr, "main()\n"); |
@@ -77,11 +76,20 @@ main(int argc, char *argv[]) | |||
77 | return (1); | 76 | return (1); |
78 | } | 77 | } |
79 | /* this is supposed to segfault */ | 78 | /* this is supposed to segfault */ |
80 | if (strcmp(argv[1], "-valid")) { | 79 | if (!strcmp(argv[1], "-invalid-atexit")) { |
81 | signal(SIGSEGV, handle_signal); | 80 | signal(SIGSEGV, handle_signal); |
82 | __atexit->fns[0] = handle_invalid; | 81 | __atexit->fns[0] = handle_invalid; |
82 | } else if (!strcmp(argv[1], "-invalid-cleanup")) { | ||
83 | struct atexit *p = __atexit; | ||
84 | |||
85 | signal(SIGSEGV, handle_signal); | ||
86 | while (p != NULL && p->next != NULL) | ||
87 | p = p->next; | ||
88 | if (p == NULL) | ||
89 | fprintf(stderr, "p == NULL, no page found\n"); | ||
90 | p->fns[0] = handle_invalid; | ||
83 | } | 91 | } |
84 | __cleanup = handle_cleanup; | 92 | __atexit_register_cleanup(handle_cleanup); |
85 | counter = 0; | 93 | counter = 0; |
86 | fprintf(stderr, "main() returns\n"); | 94 | fprintf(stderr, "main() returns\n"); |
87 | return (0); | 95 | return (0); |