diff options
author | Daniel Hartmeier <dhartmei@cvs.openbsd.org> | 2002-09-14 22:03:15 +0000 |
---|---|---|
committer | Daniel Hartmeier <dhartmei@cvs.openbsd.org> | 2002-09-14 22:03:15 +0000 |
commit | 0f8b771bc5b37f8328c7d00f66edb60002dc1c7e (patch) | |
tree | 0e6fe0364f56bfc9037e9d707b31d4cc0c50c885 /regress/lib/libc | |
parent | 51b15bb2670f7264663b02295482a347f6529717 (diff) |
Move __cleanup into mprotect'ed page to prevent unintentional modifications
similar to the atexit handlers. Idea and help deraadt@, ok deraadt@
Diffstat (limited to 'regress/lib/libc')
-rw-r--r-- | regress/lib/libc/atexit/Makefile | 6 | ||||
-rw-r--r-- | regress/lib/libc/atexit/atexit_test.c | 24 |
2 files changed, 20 insertions, 10 deletions
diff --git a/regress/lib/libc/atexit/Makefile b/regress/lib/libc/atexit/Makefile index 89625e2a7b4..55c3f3981e6 100644 --- a/regress/lib/libc/atexit/Makefile +++ b/regress/lib/libc/atexit/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.2 2002/09/02 19:59:51 avsm Exp $ +# $OpenBSD: Makefile,v 1.3 2002/09/14 22:03:14 dhartmei Exp $ NOMAN= PROG=atexit_test @@ -6,7 +6,9 @@ PROG=atexit_test run-regress-atexit_test: ${PROG} ./${PROG} -valid 2>${.OBJDIR}/valid.out cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok - ./${PROG} -invalid 2>${.OBJDIR}/invalid.out + ./${PROG} -invalid-atexit 2>${.OBJDIR}/invalid.out + cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok + ./${PROG} -invalid-cleanup 2>${.OBJDIR}/invalid.out cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok .include <bsd.regress.mk> diff --git a/regress/lib/libc/atexit/atexit_test.c b/regress/lib/libc/atexit/atexit_test.c index fcfe95cb020..fea95832ab5 100644 --- a/regress/lib/libc/atexit/atexit_test.c +++ b/regress/lib/libc/atexit/atexit_test.c @@ -1,4 +1,4 @@ -/* $OpenBSD: atexit_test.c,v 1.1 2002/07/29 19:51:41 dhartmei Exp $ */ +/* $OpenBSD: atexit_test.c,v 1.2 2002/09/14 22:03:14 dhartmei Exp $ */ /* * Copyright (c) 2002 Daniel Hartmeier @@ -39,9 +39,6 @@ #include <signal.h> #include "/usr/src/lib/libc/stdlib/atexit.h" -extern struct atexit *__atexit; -extern void (*__cleanup)(); - void handle_first(); void handle_middle(); void handle_last(); @@ -57,8 +54,10 @@ main(int argc, char *argv[]) int i; if (argc != 2 || (strcmp(argv[1], "-valid") && - strcmp(argv[1], "-invalid"))) { - fprintf(stderr, "%s -valid/-invalid\n", argv[0]); + strcmp(argv[1], "-invalid-atexit") && + strcmp(argv[1], "-invalid-cleanup"))) { + fprintf(stderr, "%s -valid/-invalid-atexit/-invalid-cleanup\n", + argv[0]); return (1); } fprintf(stderr, "main()\n"); @@ -77,11 +76,20 @@ main(int argc, char *argv[]) return (1); } /* this is supposed to segfault */ - if (strcmp(argv[1], "-valid")) { + if (!strcmp(argv[1], "-invalid-atexit")) { signal(SIGSEGV, handle_signal); __atexit->fns[0] = handle_invalid; + } else if (!strcmp(argv[1], "-invalid-cleanup")) { + struct atexit *p = __atexit; + + signal(SIGSEGV, handle_signal); + while (p != NULL && p->next != NULL) + p = p->next; + if (p == NULL) + fprintf(stderr, "p == NULL, no page found\n"); + p->fns[0] = handle_invalid; } - __cleanup = handle_cleanup; + __atexit_register_cleanup(handle_cleanup); counter = 0; fprintf(stderr, "main() returns\n"); return (0); |