From 8852a4e96620349bdbb8b1910914433eb4ae5b23 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Wed, 29 May 2002 18:33:41 +0000 Subject: strlcat --- usr.bin/jot/jot.c | 6 +++--- usr.bin/lndir/lndir.c | 4 ++-- usr.bin/mixerctl/mixerctl.c | 14 +++++++++----- usr.bin/nohup/nohup.c | 10 +++++----- usr.bin/top/commands.c | 5 +++-- usr.bin/whois/whois.c | 19 ++++++++++--------- 6 files changed, 32 insertions(+), 26 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/jot/jot.c b/usr.bin/jot/jot.c index 34fb117e0cb..1dd3b5e2bcf 100644 --- a/usr.bin/jot/jot.c +++ b/usr.bin/jot/jot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: jot.c,v 1.9 2002/02/16 21:27:47 millert Exp $ */ +/* $OpenBSD: jot.c,v 1.10 2002/05/29 18:33:38 deraadt Exp $ */ /* $NetBSD: jot.c,v 1.3 1994/12/02 20:29:43 pk Exp $ */ /*- @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)jot.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: jot.c,v 1.9 2002/02/16 21:27:47 millert Exp $"; +static char rcsid[] = "$OpenBSD: jot.c,v 1.10 2002/05/29 18:33:38 deraadt Exp $"; #endif /* not lint */ /* @@ -362,7 +362,7 @@ getformat() } else if (!*(p+1)) { if (sz <= 0) errx(1, "-w word too long"); - strcat(format, "%"); /* cannot end in single '%' */ + strlcat(format, "%", sizeof format); /* cannot end in single '%' */ } else { for (; *p && !isalpha(*p); p++) /* Certain nonalphanumerics we can't allow */ diff --git a/usr.bin/lndir/lndir.c b/usr.bin/lndir/lndir.c index ccc27a67a56..84a9db47216 100644 --- a/usr.bin/lndir/lndir.c +++ b/usr.bin/lndir/lndir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lndir.c,v 1.8 2002/03/28 02:36:03 form Exp $ */ +/* $OpenBSD: lndir.c,v 1.9 2002/05/29 18:33:39 deraadt Exp $ */ /* $XConsortium: lndir.c /main/15 1995/08/30 10:56:18 gildea $ */ /* @@ -200,7 +200,7 @@ dodir(fn, fs, ts, rel) strcpy(buf, "../"); else buf[0] = '\0'; - strcat(buf, fn); + strlcat(buf, fn, sizeof buf); if (!(df = opendir(buf))) { warn("%s: Cannot opendir", buf); diff --git a/usr.bin/mixerctl/mixerctl.c b/usr.bin/mixerctl/mixerctl.c index 946e387ba33..864ccefcf7b 100644 --- a/usr.bin/mixerctl/mixerctl.c +++ b/usr.bin/mixerctl/mixerctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mixerctl.c,v 1.7 2002/02/16 21:27:49 millert Exp $ */ +/* $OpenBSD: mixerctl.c,v 1.8 2002/05/29 18:33:39 deraadt Exp $ */ /* $NetBSD: mixerctl.c,v 1.11 1998/04/27 16:55:23 augustss Exp $ */ /* @@ -70,10 +70,14 @@ catstr(p, q) char *p; char *q; { - char *r = malloc(strlen(p) + strlen(q) + 2); - strcpy(r, p); - strcat(r, "."); - strcat(r, q); + int len; + char *r; + + len = strlen(p) + 1 + strlen(q) + 1; + r = malloc(len); + strlcpy(r, p, len); + strlcat(r, ".", len); + strlcat(r, q, len); return r; } diff --git a/usr.bin/nohup/nohup.c b/usr.bin/nohup/nohup.c index a11cda04569..1115bc6dc66 100644 --- a/usr.bin/nohup/nohup.c +++ b/usr.bin/nohup/nohup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nohup.c,v 1.8 2001/09/19 10:58:07 mpech Exp $ */ +/* $OpenBSD: nohup.c,v 1.9 2002/05/29 18:33:39 deraadt Exp $ */ /* $NetBSD: nohup.c,v 1.6 1995/08/31 23:35:25 jtc Exp $ */ /* @@ -44,7 +44,7 @@ char copyright[] = #if 0 static char sccsid[] = "@(#)nohup.c 5.4 (Berkeley) 6/1/90"; #endif -static char rcsid[] = "$OpenBSD: nohup.c,v 1.8 2001/09/19 10:58:07 mpech Exp $"; +static char rcsid[] = "$OpenBSD: nohup.c,v 1.9 2002/05/29 18:33:39 deraadt Exp $"; #endif /* not lint */ #include @@ -118,9 +118,9 @@ dofile() goto dupit; if ((p = getenv("HOME")) != NULL && *p != '\0' && (strlen(p) + strlen(FILENAME) + 1) < sizeof(path)) { - (void)strcpy(path, p); - (void)strcat(path, "/"); - (void)strcat(path, FILENAME); + (void)strlcpy(path, p, sizeof path); + (void)strlcat(path, "/", sizeof path); + (void)strlcat(path, FILENAME, sizeof path); if ((fd = open(p = path, O_RDWR|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR)) >= 0) goto dupit; } diff --git a/usr.bin/top/commands.c b/usr.bin/top/commands.c index c7875883deb..434e0c6b42f 100644 --- a/usr.bin/top/commands.c +++ b/usr.bin/top/commands.c @@ -1,4 +1,4 @@ -/* $OpenBSD: commands.c,v 1.4 2002/02/16 21:27:55 millert Exp $ */ +/* $OpenBSD: commands.c,v 1.5 2002/05/29 18:33:40 deraadt Exp $ */ /* * Top users/processes display for Unix @@ -227,7 +227,8 @@ static char *err_string() { return(err_listem); } - (void) strcat(string, "; "); /* we know there's more */ + /* we know there's more */ + (void) strlcat(string, "; ", sizeof string); } currerr = errp->errno; first = Yes; diff --git a/usr.bin/whois/whois.c b/usr.bin/whois/whois.c index 652d1eab3f6..681efd08bec 100644 --- a/usr.bin/whois/whois.c +++ b/usr.bin/whois/whois.c @@ -1,4 +1,4 @@ -/* $OpenBSD: whois.c,v 1.14 2002/02/16 21:27:59 millert Exp $ */ +/* $OpenBSD: whois.c,v 1.15 2002/05/29 18:33:40 deraadt Exp $ */ /* * Copyright (c) 1980, 1993 @@ -43,7 +43,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)whois.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: whois.c,v 1.14 2002/02/16 21:27:59 millert Exp $"; +static char rcsid[] = "$OpenBSD: whois.c,v 1.15 2002/05/29 18:33:40 deraadt Exp $"; #endif #endif /* not lint */ @@ -162,21 +162,22 @@ main(argc, argv) if ((*argv)[i] == '.') j = i; if (j != 0) { - qnichost = (char *) calloc(i - j + 1 + - strlen(QNICHOST_TAIL), sizeof(char)); + int len = i - j + 1 + strlen(QNICHOST_TAIL); + + qnichost = (char *) calloc(len, sizeof(char)); if (!qnichost) err(1, "malloc"); - strcpy(qnichost, *argv + j + 1); - strcat(qnichost, QNICHOST_TAIL); + strlcpy(qnichost, *argv + j + 1, len); + strlcat(qnichost, QNICHOST_TAIL, len); memset(&hints, 0, sizeof(hints)); hints.ai_flags = 0; hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; error = getaddrinfo(qnichost, "whois", - &hints, &res); + &hints, &res); if (error != 0) errx(EX_NOHOST, "%s: %s", qnichost, - gai_strerror(error)); + gai_strerror(error)); } } if (!qnichost) { @@ -187,7 +188,7 @@ main(argc, argv) error = getaddrinfo(host, "whois", &hints, &res); if (error != 0) errx(EX_NOHOST, "%s: %s", host, - gai_strerror(error)); + gai_strerror(error)); } whois(*argv++, res, flags); -- cgit v1.2.3