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
[-- Attachment #1 --]
Another one for review.
Kris
Index: comsat.c
===================================================================
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;
+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));
+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 = 0;
+ }
+
cc = recv(0, msgbuf, sizeof(msgbuf) - 1, 0);
if (cc <= 0) {
if (errno != EINTR)
sleep(1);
- errno = 0;
continue;
}
if (!nutmp) /* no one has logged in yet */
@@ -141,9 +148,15 @@
}
void
-onalrm(signo)
+readutmp(signo)
int signo;
{
+ wantreadutmp = 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 = ((tio.c_oflag & (OPOST|ONLCR)) == (OPOST|ONLCR)) ? "\n" : "\n\r";
- (void)strncpy(name, utp->ut_name, sizeof(utp->ut_name));
- name[sizeof(name) - 1] = '\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 : "",
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (FreeBSD)
Comment: For info see http://www.gnupg.org
iD8DBQE7XS8GWry0BWjoQKURAggdAKDcG7Z5jWu+kje3TP2kd4cLlXiW0wCgl9YS
KgO58RqXLq4sueDSr3rLitE=
=USIC
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010724011710.A4926>
