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/regress/lib/libc/atexit/Makefile | 6 ++++-- src/regress/lib/libc/atexit/atexit_test.c | 24 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) (limited to 'src/regress/lib/libc') 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 @@ -# $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 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 @@ -/* $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 #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); -- cgit v1.2.3-55-g6feb