Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jul 2001 01:17:10 -0700
From:      Kris Kennaway <kris@obsecurity.org>
To:        audit@FreeBSD.org
Subject:   comsat signal/string fixes
Message-ID:  <20010724011710.A4926@xor.obsecurity.org>

next in thread | raw e-mail | index | archive | help

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

Another one for review.

Kris

Index: comsat.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/libexec/comsat/comsat.c,v
retrieving revision 1.13
diff -u -r1.13 comsat.c
--- comsat.c	1999/08/28 00:09:27	1.13
+++ comsat.c	2001/07/24 08:15:53
@@ -78,12 +78,15 @@
 time_t	lastmsgtime;
 int	nutmp, uf;
=20
+void doreadutmp __P((void));
 void jkfprintf __P((FILE *, char[], char[], off_t));
 void mailfor __P((char *));
 void notify __P((struct utmp *, char[], off_t, int));
-void onalrm __P((int));
+void readutmp __P((int));
 void reapchildren __P((int));
=20
+sig_atomic_t wantreadutmp;
+
 int
 main(argc, argv)
 	int argc;
@@ -111,16 +114,20 @@
 	}
 	(void)time(&lastmsgtime);
 	(void)gethostname(hostname, sizeof(hostname));
-	onalrm(0);
-	(void)signal(SIGALRM, onalrm);
+	doreadutmp();
+	(void)signal(SIGALRM, readutmp);
 	(void)signal(SIGTTOU, SIG_IGN);
 	(void)signal(SIGCHLD, reapchildren);
 	for (;;) {
+		if (wantreadutmp) {
+			doreadutmp();
+			wantreadutmp =3D 0;
+		}
+
 		cc =3D recv(0, msgbuf, sizeof(msgbuf) - 1, 0);
 		if (cc <=3D 0) {
 			if (errno !=3D EINTR)
 				sleep(1);
-			errno =3D 0;
 			continue;
 		}
 		if (!nutmp)		/* no one has logged in yet */
@@ -141,9 +148,15 @@
 }
=20
 void
-onalrm(signo)
+readutmp(signo)
 	int signo;
 {
+	wantreadutmp =3D 1;
+}
+
+void
+doreadutmp(void)
+{
 	static u_int utmpsize;		/* last malloced size for utmp */
 	static u_int utmpmtime;		/* last modification time for utmp */
 	struct stat statbf;
@@ -235,8 +248,7 @@
 	}
 	(void)tcgetattr(fileno(tp), &tio);
 	cr =3D ((tio.c_oflag & (OPOST|ONLCR)) =3D=3D (OPOST|ONLCR)) ?  "\n" : "\n=
\r";
-	(void)strncpy(name, utp->ut_name, sizeof(utp->ut_name));
-	name[sizeof(name) - 1] =3D '\0';
+	(void)strlcpy(name, utp->ut_name, sizeof(name));
 	(void)fprintf(tp, "%s\007New mail for %s@%.*s\007 has arrived%s%s%s:%s---=
-%s",
 	    cr, name, (int)sizeof(hostname), hostname,
 	    folder ? cr : "", folder ? "to " : "", folder ? file : "",

--BOKacYhQ+x31HxR3
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

iD8DBQE7XS8GWry0BWjoQKURAggdAKDcG7Z5jWu+kje3TP2kd4cLlXiW0wCgl9YS
KgO58RqXLq4sueDSr3rLitE=
=USIC
-----END PGP SIGNATURE-----

--BOKacYhQ+x31HxR3--

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?20010724011710.A4926>