diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-04-05 16:25:00 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-04-05 16:25:00 +0000 |
commit | e116a1bd1d081f3d159e3e8b120f05f54c231fb7 (patch) | |
tree | 681f1f74f8e318244cc852d7f3b889786dcae2b3 /usr.bin/last/last.c | |
parent | 7a7d941e09fe1020cecfef3a5fb2ea5c833934f1 (diff) |
simple snprintf and strlcpy; henning ok
Diffstat (limited to 'usr.bin/last/last.c')
-rw-r--r-- | usr.bin/last/last.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/usr.bin/last/last.c b/usr.bin/last/last.c index 125618b8512..5e3978be2c5 100644 --- a/usr.bin/last/last.c +++ b/usr.bin/last/last.c @@ -1,4 +1,4 @@ -/* $OpenBSD: last.c,v 1.20 2002/09/23 04:10:14 millert Exp $ */ +/* $OpenBSD: last.c,v 1.21 2003/04/05 16:24:59 deraadt Exp $ */ /* $NetBSD: last.c,v 1.6 1994/12/24 16:49:02 cgd Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)last.c 8.2 (Berkeley) 4/2/94"; #endif -static char rcsid[] = "$OpenBSD: last.c,v 1.20 2002/09/23 04:10:14 millert Exp $"; +static char rcsid[] = "$OpenBSD: last.c,v 1.21 2003/04/05 16:24:59 deraadt Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -546,6 +546,7 @@ ttyconv(arg) char *arg; { char *mval; + size_t len = 8; /* * kludge -- we assume that all tty's end with @@ -553,14 +554,12 @@ ttyconv(arg) */ if (strlen(arg) == 2) { /* either 6 for "ttyxx" or 8 for "console" */ - if (!(mval = malloc((u_int)8))) + if (!(mval = malloc(len))) err(1, "malloc failure"); if (!strcmp(arg, "co")) - (void)strcpy(mval, "console"); - else { - (void)strcpy(mval, "tty"); - (void)strcpy(mval + 3, arg); - } + (void)strlcpy(mval, "console", len); + else + snprintf(mval, len, "tty%s", arg); return (mval); } if (!strncmp(arg, _PATH_DEV, sizeof(_PATH_DEV) - 1)) |