diff options
author | 2002-09-14 22:03:14 +0000 | |
---|---|---|
committer | 2002-09-14 22:03:14 +0000 | |
commit | 8d62ee40dc28d335867f292dd8aab66f53e20b5b (patch) | |
tree | ad54f039e1d7d49a8f9d2f8fe09f8b447e2e743f /lib/libc/stdio | |
parent | recognize AppleKiwi (diff) | |
download | wireguard-openbsd-8d62ee40dc28d335867f292dd8aab66f53e20b5b.tar.xz wireguard-openbsd-8d62ee40dc28d335867f292dd8aab66f53e20b5b.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 'lib/libc/stdio')
-rw-r--r-- | lib/libc/stdio/findfp.c | 11 | ||||
-rw-r--r-- | lib/libc/stdio/local.h | 4 | ||||
-rw-r--r-- | lib/libc/stdio/makebuf.c | 4 | ||||
-rw-r--r-- | lib/libc/stdio/setvbuf.c | 4 |
4 files changed, 12 insertions, 11 deletions
diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c index 0702efad985..3aa66965367 100644 --- a/lib/libc/stdio/findfp.c +++ b/lib/libc/stdio/findfp.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: findfp.c,v 1.2 1996/08/19 08:32:36 tholo Exp $"; +static char rcsid[] = "$OpenBSD: findfp.c,v 1.3 2002/09/14 22:03:14 dhartmei Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -141,9 +141,10 @@ f_prealloc() } /* - * exit() calls _cleanup() through *__cleanup, set whenever we - * open or buffer a file. This chicanery is done so that programs - * that do not use stdio need not link it all in. + * exit() and abort() call _cleanup() through the callback registered + * with __atexit_register_cleanup(), set whenever we open or buffer a + * file. This chicanery is done so that programs that do not use stdio + * need not link it all in. * * The name `_cleanup' is, alas, fairly well known outside stdio. */ @@ -161,6 +162,6 @@ void __sinit() { /* make sure we clean up on exit */ - __cleanup = _cleanup; /* conservative */ + __atexit_register_cleanup(_cleanup); /* conservative */ __sdidinit = 1; } diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h index 70d5c564471..05060408f82 100644 --- a/lib/libc/stdio/local.h +++ b/lib/libc/stdio/local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: local.h,v 1.4 2002/02/17 19:42:23 millert Exp $ */ +/* $OpenBSD: local.h,v 1.5 2002/09/14 22:03:14 dhartmei Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -50,13 +50,13 @@ fpos_t __sseek(void *, fpos_t, int); int __sclose(void *); void __sinit(void); void _cleanup(void); -void (*__cleanup)(void); void __smakebuf(FILE *); int __swhatbuf(FILE *, size_t *, int *); int _fwalk(int (*)(FILE *)); int __swsetup(FILE *); int __sflags(const char *, int *); +extern void __atexit_register_cleanup(void (*)()); extern int __sdidinit; /* diff --git a/lib/libc/stdio/makebuf.c b/lib/libc/stdio/makebuf.c index 4ebc3e93362..da9b86ca4ce 100644 --- a/lib/libc/stdio/makebuf.c +++ b/lib/libc/stdio/makebuf.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: makebuf.c,v 1.3 1998/11/25 05:18:49 millert Exp $"; +static char rcsid[] = "$OpenBSD: makebuf.c,v 1.4 2002/09/14 22:03:14 dhartmei Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -73,7 +73,7 @@ __smakebuf(fp) fp->_bf._size = 1; return; } - __cleanup = _cleanup; + __atexit_register_cleanup(_cleanup); flags |= __SMBF; fp->_bf._base = fp->_p = p; fp->_bf._size = size; diff --git a/lib/libc/stdio/setvbuf.c b/lib/libc/stdio/setvbuf.c index 65501fce9d9..0c6fd8d1623 100644 --- a/lib/libc/stdio/setvbuf.c +++ b/lib/libc/stdio/setvbuf.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: setvbuf.c,v 1.3 2001/07/09 06:57:44 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: setvbuf.c,v 1.4 2002/09/14 22:03:14 dhartmei Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> @@ -155,7 +155,7 @@ nbf: /* begin/continue reading, or stay in intermediate state */ fp->_w = 0; } - __cleanup = _cleanup; + __atexit_register_cleanup(_cleanup); return (ret); } |