Skip site navigation (1)Skip section navigation (2)
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

--huq684BweRXVnRxX
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

This patch is from OpenBSD and fixes the unsafe signal handlers in
top(1).  Reviews please :)

Kris

Index: top.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
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
=20
+sig_atomic_t leaveflag;
+sig_atomic_t tstopflag;
+sig_atomic_t winchflag;
+
 /* internal routines */
 void quit();
=20
@@ -517,12 +521,7 @@
 	fputc('\n', stderr);
     }
=20
-    /* setup the jump buffer for stops */
-    if (setjmp(jmp_int) !=3D 0)
-    {
-	/* control ends up here after an interrupt */
-	reset_display();
-    }
+restart:
=20
     /*
      *  main loop -- repeat while display count is positive or while it
@@ -665,6 +664,52 @@
 		timeout.tv_sec  =3D delay;
 		timeout.tv_usec =3D 0;
=20
+		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 =3D 0;
+		    goto restart;
+		}
+
+		if (winchflag) {
+		    /* reascertain the screen dimensions */
+		    get_screensize();
+
+		    /* tell display to resize */
+		    max_topn =3D display_resize();
+
+		    /* reset the signal handler */
+		    (void) signal(SIGWINCH, winch);
+
+		    reset_display();
+		    winchflag =3D 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 */
=20
 {
-    end_screen();
-    exit(0);
+    leaveflag =3D 1;
 }
=20
 sigret_t tstop(i)	/* SIGTSTP handler */
@@ -958,31 +1002,7 @@
 int i;
=20
 {
-    /* 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 =3D 1;
 }
=20
 #ifdef SIGWINCH
@@ -991,17 +1011,7 @@
 int i;
=20
 {
-    /* reascertain the screen dimensions */
-    get_screensize();
-
-    /* tell display to resize */
-    max_topn =3D display_resize();
-
-    /* reset the signal handler */
-    (void) signal(SIGWINCH, winch);
-
-    /* jump to appropriate place */
-    longjmp(jmp_int, 1);
+    winchflag =3D 1;
 }
 #endif
=20


--huq684BweRXVnRxX
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (FreeBSD)
Comment: For info see http://www.gnupg.org

iD8DBQE7XQOFWry0BWjoQKURAqNaAKDfT3Sv+Lzi9aA0UgY6oGoQorJjJgCg66Vn
7TfytUwV4CuiHOuOlnwhJQs=
=oXIe
-----END PGP SIGNATURE-----

--huq684BweRXVnRxX--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010723221133.A814>