Date: Mon, 23 Jul 2001 22:11:33 -0700 From: Kris Kennaway <kris@obsecurity.org> To: audit@FreeBSD.org Subject: top signal handling Message-ID: <20010723221133.A814@xor.obsecurity.org>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
This patch is from OpenBSD and fixes the unsafe signal handlers in
top(1). Reviews please :)
Kris
Index: top.c
===================================================================
RCS file: /mnt/ncvs/src/contrib/top/top.c,v
retrieving revision 1.6
diff -u -r1.6 top.c
--- top.c 2000/11/03 22:00:10 1.6
+++ top.c 2001/07/24 05:10:25
@@ -73,6 +73,10 @@
sigret_t winch();
#endif
+sig_atomic_t leaveflag;
+sig_atomic_t tstopflag;
+sig_atomic_t winchflag;
+
/* internal routines */
void quit();
@@ -517,12 +521,7 @@
fputc('\n', stderr);
}
- /* setup the jump buffer for stops */
- if (setjmp(jmp_int) != 0)
- {
- /* control ends up here after an interrupt */
- reset_display();
- }
+restart:
/*
* main loop -- repeat while display count is positive or while it
@@ -665,6 +664,52 @@
timeout.tv_sec = delay;
timeout.tv_usec = 0;
+ if (leaveflag) {
+ end_screen();
+ exit(0);
+ }
+
+ if (tstopflag) {
+ /* move to the lower left */
+ end_screen();
+ fflush(stdout);
+
+ /* default the signal handler action */
+ (void) signal(SIGTSTP, SIG_DFL);
+
+ /* unblock the signal and send ourselves one */
+#ifdef SIGRELSE
+ sigrelse(SIGTSTP);
+#else
+ (void) sigsetmask(sigblock(0) & ~(1 << (SIGTSTP - 1)));
+#endif
+ (void) kill(0, SIGTSTP);
+
+ /* reset the signal handler */
+ (void) signal(SIGTSTP, tstop);
+
+ /* reinit screen */
+ reinit_screen();
+ reset_display();
+ tstopflag = 0;
+ goto restart;
+ }
+
+ if (winchflag) {
+ /* reascertain the screen dimensions */
+ get_screensize();
+
+ /* tell display to resize */
+ max_topn = display_resize();
+
+ /* reset the signal handler */
+ (void) signal(SIGWINCH, winch);
+
+ reset_display();
+ winchflag = 0;
+ goto restart;
+ }
+
/* wait for either input or the end of the delay period */
if (select(32, &readfds, (fd_set *)NULL, (fd_set *)NULL, &timeout) > 0)
{
@@ -949,8 +994,7 @@
sigret_t leave() /* exit under normal conditions -- INT handler */
{
- end_screen();
- exit(0);
+ leaveflag = 1;
}
sigret_t tstop(i) /* SIGTSTP handler */
@@ -958,31 +1002,7 @@
int i;
{
- /* move to the lower left */
- end_screen();
- fflush(stdout);
-
- /* default the signal handler action */
- (void) signal(SIGTSTP, SIG_DFL);
-
- /* unblock the signal and send ourselves one */
-#ifdef SIGRELSE
- sigrelse(SIGTSTP);
-#else
- (void) sigsetmask(sigblock(0) & ~(1 << (SIGTSTP - 1)));
-#endif
- (void) kill(0, SIGTSTP);
-
- /* reset the signal handler */
- (void) signal(SIGTSTP, tstop);
-
- /* reinit screen */
- reinit_screen();
-
- /* jump to appropriate place */
- longjmp(jmp_int, 1);
-
- /*NOTREACHED*/
+ tstopflag = 1;
}
#ifdef SIGWINCH
@@ -991,17 +1011,7 @@
int i;
{
- /* reascertain the screen dimensions */
- get_screensize();
-
- /* tell display to resize */
- max_topn = display_resize();
-
- /* reset the signal handler */
- (void) signal(SIGWINCH, winch);
-
- /* jump to appropriate place */
- longjmp(jmp_int, 1);
+ winchflag = 1;
}
#endif
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (FreeBSD)
Comment: For info see http://www.gnupg.org
iD8DBQE7XQOFWry0BWjoQKURAqNaAKDfT3Sv+Lzi9aA0UgY6oGoQorJjJgCg66Vn
7TfytUwV4CuiHOuOlnwhJQs=
=oXIe
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010723221133.A814>
