diff options
author | Karel Zak | 2006-12-07 00:25:35 +0100 |
---|---|---|
committer | Karel Zak | 2006-12-07 00:25:35 +0100 |
commit | 2b6fc908bc368b540845a313c3b8a867c5ad9a42 (patch) | |
tree | 6fad48a239bc90515a5dc4084d6e3c3ee1f41e29 /login-utils/wall.c | |
parent | Imported from util-linux-2.7.1 tarball. (diff) | |
download | kernel-qcow2-util-linux-2b6fc908bc368b540845a313c3b8a867c5ad9a42.tar.gz kernel-qcow2-util-linux-2b6fc908bc368b540845a313c3b8a867c5ad9a42.tar.xz kernel-qcow2-util-linux-2b6fc908bc368b540845a313c3b8a867c5ad9a42.zip |
Imported from util-linux-2.8 tarball.
Diffstat (limited to 'login-utils/wall.c')
-rw-r--r-- | login-utils/wall.c | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/login-utils/wall.c b/login-utils/wall.c index 7957ae299..eda7e611d 100644 --- a/login-utils/wall.c +++ b/login-utils/wall.c @@ -33,16 +33,6 @@ * Modified Sun Mar 12 10:34:34 1995, faith@cs.unc.edu, for Linux */ -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1988, 1990, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)wall.c 8.2 (Berkeley) 11/16/93"; -#endif /* not lint */ - /* * This program is not related to David Wall, whose Stanford Ph.D. thesis * is entitled "Mechanisms for Broadcast and Selective Broadcast". @@ -145,11 +135,12 @@ makemsg(fname) time_t now, time(); FILE *fp; int fd; - char *p, *whom, hostname[MAXHOSTNAMELEN], lbuf[100], tmpname[64]; + char *p, *whom, *where, hostname[MAXHOSTNAMELEN], + lbuf[MAXHOSTNAMELEN + 320], + tmpname[sizeof(_PATH_TMP) + 20]; char *getlogin(), *strcpy(), *ttyname(); - (void)snprintf(tmpname, sizeof(tmpname), - "%s/wall.XXXXXX", _PATH_TMP); + (void)sprintf(tmpname, "%s/wall.XXXXXX", _PATH_TMP); if (!(fd = mkstemp(tmpname)) || !(fp = fdopen(fd, "r+"))) { (void)fprintf(stderr, "wall: can't open temporary file.\n"); exit(1); @@ -159,6 +150,11 @@ makemsg(fname) if (!nobanner) { if (!(whom = getlogin())) whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???"; + if (!whom || strlen(whom) > 100) + whom = "someone"; + where = ttyname(2); + if (!where || strlen(where) > 100) + where = "somewhere"; (void)gethostname(hostname, sizeof(hostname)); (void)time(&now); lt = localtime(&now); @@ -170,14 +166,14 @@ makemsg(fname) * Which means that we may leave a non-blank character * in column 80, but that can't be helped. */ + /* snprintf is not always available, but the sprintf's here + will not overflow as long as %d takes at most 100 chars */ (void)fprintf(fp, "\r%79s\r\n", " "); - (void)snprintf(lbuf, sizeof(lbuf), - "Broadcast Message from %s@%s", - whom, hostname); + (void)sprintf(lbuf, "Broadcast Message from %s@%s", + whom, hostname); (void)fprintf(fp, "%-79.79s\007\007\r\n", lbuf); - (void)snprintf(lbuf, sizeof(lbuf), - " (%s) at %d:%02d ...", ttyname(2), - lt->tm_hour, lt->tm_min); + (void)sprintf(lbuf, " (%s) at %d:%02d ...", + where, lt->tm_hour, lt->tm_min); (void)fprintf(fp, "%-79.79s\r\n", lbuf); } (void)fprintf(fp, "%79s\r\n", " "); |