diff options
author | lebel <lebel@cvs.openbsd.org> | 2001-06-27 00:58:58 +0000 |
---|---|---|
committer | lebel <lebel@cvs.openbsd.org> | 2001-06-27 00:58:58 +0000 |
commit | 8af9ac2691950c45385aecf7c502a16c3c11db86 (patch) | |
tree | 2b4161da48e1261faa9895ae08bd1fcdf3be38a3 /lib | |
parent | c5355883f033c52fa97b73febb89e80adf21cbbd (diff) |
use strlcpy vs strncpy+a[len-1]='\0'. millert@ ok.
Diffstat (limited to 'lib')
29 files changed, 91 insertions, 132 deletions
diff --git a/lib/libc/compat-43/getwd.c b/lib/libc/compat-43/getwd.c index e6f0d0053b7..f7bccc192fe 100644 --- a/lib/libc/compat-43/getwd.c +++ b/lib/libc/compat-43/getwd.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: getwd.c,v 1.4 1996/12/21 22:23:37 millert Exp $"; +static char *rcsid = "$OpenBSD: getwd.c,v 1.5 2001/06/27 00:58:53 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -49,7 +49,6 @@ getwd(buf) if ((p = getcwd(buf, MAXPATHLEN))) return(p); - (void)strncpy(buf, strerror(errno), MAXPATHLEN-1); - buf[MAXPATHLEN-1] = '\0'; + strlcpy(buf, strerror(errno), MAXPATHLEN); return((char *)NULL); } diff --git a/lib/libc/crypt/crypt.c b/lib/libc/crypt/crypt.c index 8fd319a4f31..d1a342c1787 100644 --- a/lib/libc/crypt/crypt.c +++ b/lib/libc/crypt/crypt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crypt.c,v 1.13 1998/03/22 19:01:18 niklas Exp $ */ +/* $OpenBSD: crypt.c,v 1.14 2001/06/27 00:58:53 lebel Exp $ */ /* * FreeSec: libcrypt @@ -52,7 +52,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: crypt.c,v 1.13 1998/03/22 19:01:18 niklas Exp $"; +static char rcsid[] = "$OpenBSD: crypt.c,v 1.14 2001/06/27 00:58:53 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -650,7 +650,7 @@ crypt(key, setting) if (des_setkey((u_char *) keybuf)) return(NULL); } - strncpy((char *)output, setting, 9); + strlcpy((char *)output, setting, 10); /* * Double check that we weren't given a short setting. @@ -659,7 +659,6 @@ crypt(key, setting) * Just make sure the output string doesn't have an extra * NUL in it. */ - output[9] = '\0'; p = output + strlen((const char *)output); } else { /* diff --git a/lib/libc/gen/basename.c b/lib/libc/gen/basename.c index 5ffa17abad5..9126b5a1166 100644 --- a/lib/libc/gen/basename.c +++ b/lib/libc/gen/basename.c @@ -1,4 +1,4 @@ -/* $OpenBSD: basename.c,v 1.4 1999/05/30 17:10:30 espie Exp $ */ +/* $OpenBSD: basename.c,v 1.5 2001/06/27 00:58:54 lebel Exp $ */ /* * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> @@ -28,7 +28,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: basename.c,v 1.4 1999/05/30 17:10:30 espie Exp $"; +static char rcsid[] = "$OpenBSD: basename.c,v 1.5 2001/06/27 00:58:54 lebel Exp $"; #endif /* not lint */ #include <errno.h> @@ -69,7 +69,6 @@ basename(path) errno = ENAMETOOLONG; return(NULL); } - (void)strncpy(bname, startp, endp - startp + 1); - bname[endp - startp + 1] = '\0'; + strlcpy(bname, startp, endp - startp + 2); return(bname); } diff --git a/lib/libc/gen/confstr.c b/lib/libc/gen/confstr.c index cb25deed19a..90fbcc5330d 100644 --- a/lib/libc/gen/confstr.c +++ b/lib/libc/gen/confstr.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: confstr.c,v 1.3 1996/09/15 09:30:55 tholo Exp $"; +static char rcsid[] = "$OpenBSD: confstr.c,v 1.4 2001/06/27 00:58:54 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -73,8 +73,7 @@ confstr(name, buf, len) * POSIX 1003.2 requires partial return of * the string -- that should be *real* useful. */ - (void)strncpy(buf, p, len - 1); - buf[len - 1] = '\0'; + strlcpy(buf, p, len); free(p); } return (tlen + 1); diff --git a/lib/libc/gen/dirname.c b/lib/libc/gen/dirname.c index 573c7d3bfcb..29c6725627a 100644 --- a/lib/libc/gen/dirname.c +++ b/lib/libc/gen/dirname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dirname.c,v 1.4 1999/05/30 17:10:30 espie Exp $ */ +/* $OpenBSD: dirname.c,v 1.5 2001/06/27 00:58:54 lebel Exp $ */ /* * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> @@ -28,7 +28,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: dirname.c,v 1.4 1999/05/30 17:10:30 espie Exp $"; +static char rcsid[] = "$OpenBSD: dirname.c,v 1.5 2001/06/27 00:58:54 lebel Exp $"; #endif /* not lint */ #include <errno.h> @@ -72,7 +72,6 @@ dirname(path) errno = ENAMETOOLONG; return(NULL); } - (void)strncpy(bname, path, endp - path + 1); - bname[endp - path + 1] = '\0'; + strlcpy(bname, path, endp - path + 2); return(bname); } diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c index bf6da99b94f..4ed7d62cfb5 100644 --- a/lib/libc/gen/fstab.c +++ b/lib/libc/gen/fstab.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: fstab.c,v 1.8 1999/09/03 16:23:18 millert Exp $"; +static char rcsid[] = "$OpenBSD: fstab.c,v 1.9 2001/06/27 00:58:54 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -124,8 +124,7 @@ fstabscan() _fs_fstab.fs_passno = l; } } - strncpy(subline, _fs_fstab.fs_mntops, sizeof subline-1); - subline[sizeof subline-1] = '\0'; + strlcpy(subline, _fs_fstab.fs_mntops, sizeof subline); for (typexx = 0, cp = strtok(subline, ","); cp; cp = strtok((char *)NULL, ",")) { if (strlen(cp) != 2) diff --git a/lib/libc/gen/pwcache.c b/lib/libc/gen/pwcache.c index 509bdbb10b5..f09f291aa69 100644 --- a/lib/libc/gen/pwcache.c +++ b/lib/libc/gen/pwcache.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: pwcache.c,v 1.4 2001/01/31 17:42:25 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: pwcache.c,v 1.5 2001/06/27 00:58:54 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -72,8 +72,7 @@ user_from_uid(uid, nouser) return (nbuf); } cp->uid = uid; - (void)strncpy(cp->name, pw->pw_name, _PW_NAME_LEN); - cp->name[_PW_NAME_LEN] = '\0'; + strlcpy(cp->name, pw->pw_name, sizeof(cp->name)); } return (cp->name); } @@ -105,8 +104,7 @@ group_from_gid(gid, nogroup) return (nbuf); } cp->gid = gid; - (void)strncpy(cp->name, gr->gr_name, _PW_NAME_LEN); - cp->name[_PW_NAME_LEN] = '\0'; + strlcpy(cp->name, gr->gr_name, sizeof(cp->name)); } return (cp->name); } diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c index 11a106ba85c..b33a663e406 100644 --- a/lib/libc/gen/syslog.c +++ b/lib/libc/gen/syslog.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: syslog.c,v 1.9 2000/01/02 23:35:58 hugh Exp $"; +static char rcsid[] = "$OpenBSD: syslog.c,v 1.10 2001/06/27 00:58:54 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -278,9 +278,8 @@ connectlog() memset(&SyslogAddr, '\0', sizeof(SyslogAddr)); SyslogAddr.sun_len = sizeof(SyslogAddr); SyslogAddr.sun_family = AF_UNIX; - (void)strncpy(SyslogAddr.sun_path, _PATH_LOG, - sizeof(SyslogAddr.sun_path) - 1); - SyslogAddr.sun_path[sizeof(SyslogAddr.sun_path) - 1] = '\0'; + strlcpy(SyslogAddr.sun_path, _PATH_LOG, + sizeof(SyslogAddr.sun_path)); if (connect(LogFile, (struct sockaddr *)&SyslogAddr, sizeof(SyslogAddr)) == -1) { (void)close(LogFile); diff --git a/lib/libc/gen/timezone.c b/lib/libc/gen/timezone.c index d9a05408981..498243f8c3f 100644 --- a/lib/libc/gen/timezone.c +++ b/lib/libc/gen/timezone.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: timezone.c,v 1.4 1997/12/19 09:43:16 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: timezone.c,v 1.5 2001/06/27 00:58:54 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -67,8 +67,7 @@ timezone(zone, dst) if (dst) return(++end); *end = '\0'; - (void)strncpy(czone,beg,sizeof(czone) - 1); - czone[sizeof(czone) - 1] = '\0'; + strlcpy(czone,beg,sizeof(czone)); *end = ','; return(czone); } diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index 5f8eeb39f8a..42363d5c4e2 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setlocale.c,v 1.6 1997/07/09 01:08:21 millert Exp $ */ +/* $OpenBSD: setlocale.c,v 1.7 2001/06/27 00:58:54 lebel Exp $ */ /* * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. @@ -36,7 +36,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: setlocale.c,v 1.6 1997/07/09 01:08:21 millert Exp $"; +static char rcsid[] = "$OpenBSD: setlocale.c,v 1.7 2001/06/27 00:58:54 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/localedef.h> @@ -126,24 +126,20 @@ setlocale(category, locale) if (!env || !*env) env = "C"; - (void) strncpy(new_categories[category], env, 31); - new_categories[category][31] = 0; + strlcpy(new_categories[category], env, 32); if (!category) { for (i = 1; i < _LC_LAST; ++i) { if (!(env = getenv(categories[i])) || !*env) env = new_categories[0]; - (void)strncpy(new_categories[i], env, 31); - new_categories[i][31] = 0; + strlcpy(new_categories[i], env, 32); } } } else if (category) { - (void)strncpy(new_categories[category], locale, 31); - new_categories[category][31] = 0; + strlcpy(new_categories[category], locale, 32); } else { if ((r = strchr(locale, '/')) == 0) { for (i = 1; i < _LC_LAST; ++i) { - (void)strncpy(new_categories[i], locale, 31); - new_categories[i][31] = 0; + strlcpy(new_categories[i], locale, 32); } } else { for (i = 1; r[1] == '/'; ++r); @@ -151,8 +147,7 @@ setlocale(category, locale) return (NULL); /* Hmm, just slashes... */ do { len = r - locale > 31 ? 31 : r - locale; - (void)strncpy(new_categories[i++], locale, len); - new_categories[i++][len] = 0; + strlcpy(new_categories[i++], locale, len + 1); locale = r; while (*locale == '/') ++locale; diff --git a/lib/libc/net/ethers.c b/lib/libc/net/ethers.c index 1124e432534..2c8328a9ba0 100644 --- a/lib/libc/net/ethers.c +++ b/lib/libc/net/ethers.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ethers.c,v 1.11 2000/08/22 19:04:41 deraadt Exp $ */ +/* $OpenBSD: ethers.c,v 1.12 2001/06/27 00:58:54 lebel Exp $ */ /* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> @@ -34,7 +34,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: ethers.c,v 1.11 2000/08/22 19:04:41 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ethers.c,v 1.12 2001/06/27 00:58:54 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -263,8 +263,7 @@ ether_line(line, e, hostname) n = strcspn(p, " \t\n"); if (n >= MAXHOSTNAMELEN) goto bad; - (void)strncpy(hostname, p, n); - hostname[n] = '\0'; + strlcpy(hostname, p, n + 1); return (0); bad: diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index 0a0b112589d..cc313c5c6ad 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo.c,v 1.28 2001/06/11 10:05:58 itojun Exp $ */ +/* $OpenBSD: getaddrinfo.c,v 1.29 2001/06/27 00:58:54 lebel Exp $ */ /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ /* @@ -1797,8 +1797,7 @@ res_querydomainN(name, domain, target) return (-1); } if (n > 0 && name[--n] == '.') { - strncpy(nbuf, name, n); - nbuf[n] = '\0'; + strlcpy(nbuf, name, n + 1); } else longname = name; } else { diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c index 33c9643f700..d7d6c621cf0 100644 --- a/lib/libc/net/gethostnamadr.c +++ b/lib/libc/net/gethostnamadr.c @@ -52,7 +52,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.42 2000/07/30 14:07:14 itojun Exp $"; +static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.43 2001/06/27 00:58:55 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -574,8 +574,7 @@ gethostbyname2(name, af) h_errno = HOST_NOT_FOUND; return (NULL); } - strncpy(hostbuf, name, MAXHOSTNAMELEN-1); - hostbuf[MAXHOSTNAMELEN-1] = '\0'; + strlcpy(hostbuf, name, MAXHOSTNAMELEN); bp = hostbuf + MAXHOSTNAMELEN; len = sizeof hostbuf - MAXHOSTNAMELEN; host.h_name = hostbuf; @@ -607,8 +606,7 @@ gethostbyname2(name, af) h_errno = HOST_NOT_FOUND; return (NULL); } - strncpy(hostbuf, name, MAXHOSTNAMELEN-1); - hostbuf[MAXHOSTNAMELEN-1] = '\0'; + strlcpy(hostbuf, name, MAXHOSTNAMELEN); bp = hostbuf + MAXHOSTNAMELEN; len = sizeof hostbuf - MAXHOSTNAMELEN; host.h_name = hostbuf; diff --git a/lib/libc/net/getifaddrs.c b/lib/libc/net/getifaddrs.c index 29348cd492c..5be334cb6c4 100644 --- a/lib/libc/net/getifaddrs.c +++ b/lib/libc/net/getifaddrs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getifaddrs.c,v 1.3 2000/11/24 08:26:47 itojun Exp $ */ +/* $OpenBSD: getifaddrs.c,v 1.4 2001/06/27 00:58:55 lebel Exp $ */ /* * Copyright (c) 1995, 1999 @@ -353,8 +353,7 @@ getifaddrs(struct ifaddrs **pif) struct sockaddr *sa; ift->ifa_name = names; - names[sizeof(ifr->ifr_name)] = 0; - strncpy(names, ifr->ifr_name, sizeof(ifr->ifr_name)); + strlcpy(names, ifr->ifr_name, sizeof(ifr->ifr_name)); while (*names++) ; diff --git a/lib/libc/net/getnetnamadr.c b/lib/libc/net/getnetnamadr.c index 0ebc77b6568..f755cd9b149 100644 --- a/lib/libc/net/getnetnamadr.c +++ b/lib/libc/net/getnetnamadr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnetnamadr.c,v 1.13 1999/06/04 06:38:10 niklas Exp $ */ +/* $OpenBSD: getnetnamadr.c,v 1.14 2001/06/27 00:58:55 lebel Exp $ */ /* * Copyright (c) 1997, Jason Downs. All rights reserved. @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93"; static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.13 1999/06/04 06:38:10 niklas Exp $"; +static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.14 2001/06/27 00:58:55 lebel Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -184,8 +184,7 @@ getnetanswer(answer, anslen, net_i) break; cp += n; ans[0] = '\0'; - (void)strncpy(&ans[0], bp, sizeof ans-1); - ans[sizeof ans-1] = '\0'; + strlcpy(&ans[0], bp, sizeof ans); GETSHORT(type, cp); GETSHORT(class, cp); cp += INT32SZ; /* TTL */ @@ -226,10 +225,9 @@ getnetanswer(answer, anslen, net_i) ; if (nchar != 1 || *in != '0' || flag) { flag = 1; - (void)strncpy(paux1, - (i==0) ? in : in-1, - (i==0) ?nchar : nchar+1); - paux1[(i==0) ? nchar : nchar+1] = '\0'; + strlcpy(paux1, + (i==0) ? in : in-1, + (i==0) ? nchar+1 : nchar+2); pauxt = paux2; paux2 = strcat(paux1, paux2); paux1 = pauxt; @@ -358,8 +356,7 @@ getnetbyname(net) break; #endif /* YP */ case 'b': - strncpy(qbuf, net, sizeof qbuf-1); - qbuf[sizeof qbuf-1] = '\0'; + strlcpy(qbuf, net, sizeof qbuf); anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf)); if (anslen < 0) { diff --git a/lib/libc/net/ipx_addr.c b/lib/libc/net/ipx_addr.c index 9c9fe651cd6..0d225e281b2 100644 --- a/lib/libc/net/ipx_addr.c +++ b/lib/libc/net/ipx_addr.c @@ -37,7 +37,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: ipx_addr.c,v 1.4 2001/01/04 21:45:30 todd Exp $"; +static char rcsid[] = "$OpenBSD: ipx_addr.c,v 1.5 2001/06/27 00:58:55 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -57,8 +57,7 @@ ipx_addr(name) char *hostname, *socketname, *cp; char buf[50]; - (void)strncpy(buf, name, sizeof(buf) - 1); - buf[sizeof(buf) - 1] = '\0'; + strlcpy(buf, name, sizeof(buf)); /* * First, figure out what he intends as a field separtor. diff --git a/lib/libc/net/ns_addr.c b/lib/libc/net/ns_addr.c index e44ac211957..7dcc988afeb 100644 --- a/lib/libc/net/ns_addr.c +++ b/lib/libc/net/ns_addr.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: ns_addr.c,v 1.5 2001/01/04 21:45:31 todd Exp $"; +static char rcsid[] = "$OpenBSD: ns_addr.c,v 1.6 2001/06/27 00:58:55 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -56,8 +56,7 @@ ns_addr(name) char *hostname, *socketname, *cp; char buf[50]; - (void)strncpy(buf, name, sizeof(buf) - 1); - buf[sizeof(buf) - 1] = '\0'; + strlcpy(buf, name, sizeof(buf)); /* * First, figure out what he intends as a field separtor. diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c index 2ad3530c873..1439fff061a 100644 --- a/lib/libc/net/rcmd.c +++ b/lib/libc/net/rcmd.c @@ -34,7 +34,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: rcmd.c,v 1.37 2001/02/10 21:55:07 millert Exp $"; +static char *rcsid = "$OpenBSD: rcmd.c,v 1.38 2001/06/27 00:58:55 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -125,8 +125,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) return (-1); } if (res->ai_canonname) { - strncpy(hbuf, res->ai_canonname, sizeof(hbuf) - 1); - hbuf[sizeof(hbuf) - 1] = '\0'; + strlcpy(hbuf, res->ai_canonname, sizeof(hbuf)); *ahost = hbuf; } else ; /*XXX*/ diff --git a/lib/libc/net/res_init.c b/lib/libc/net/res_init.c index c44539604a3..5134323f4e8 100644 --- a/lib/libc/net/res_init.c +++ b/lib/libc/net/res_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_init.c,v 1.21 2001/06/11 10:06:00 itojun Exp $ */ +/* $OpenBSD: res_init.c,v 1.22 2001/06/27 00:58:55 lebel Exp $ */ /* * ++Copyright++ 1985, 1989, 1993 @@ -64,7 +64,7 @@ static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_init.c,v 1.21 2001/06/11 10:06:00 itojun Exp $"; +static char rcsid[] = "$OpenBSD: res_init.c,v 1.22 2001/06/27 00:58:55 lebel Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -215,8 +215,7 @@ res_init() /* Allow user to override the local domain definition */ if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) { - (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); - _res.defdname[sizeof(_res.defdname) - 1] = '\0'; + strlcpy(_res.defdname, cp, sizeof(_res.defdname)); haveenv++; /* @@ -278,8 +277,7 @@ res_init() cp++; if ((*cp == '\0') || (*cp == '\n')) continue; - strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); - _res.defdname[sizeof(_res.defdname) - 1] = '\0'; + strlcpy(_res.defdname, cp, sizeof(_res.defdname)); if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) *cp = '\0'; havesearch = 0; @@ -321,8 +319,7 @@ res_init() cp++; if ((*cp == '\0') || (*cp == '\n')) continue; - strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); - _res.defdname[sizeof(_res.defdname) - 1] = '\0'; + strlcpy(_res.defdname, cp, sizeof(_res.defdname)); if ((cp = strchr(_res.defdname, '\n')) != NULL) *cp = '\0'; /* @@ -520,9 +517,8 @@ res_init() gethostname(buf, sizeof(_res.defdname) - 1) == 0 && (cp = strchr(buf, '.')) != NULL) { - strncpy(_res.defdname, cp + 1, - sizeof(_res.defdname) - 1); - _res.defdname[sizeof(_res.defdname) - 1] = '\0'; + strlcpy(_res.defdname, cp + 1, + sizeof(_res.defdname)); } /* find components of local domain that might be searched */ diff --git a/lib/libc/net/res_query.c b/lib/libc/net/res_query.c index 433e80f6482..db76821fc69 100644 --- a/lib/libc/net/res_query.c +++ b/lib/libc/net/res_query.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_query.c,v 1.14 2001/06/11 10:06:01 itojun Exp $ */ +/* $OpenBSD: res_query.c,v 1.15 2001/06/27 00:58:55 lebel Exp $ */ /* * ++Copyright++ 1988, 1993 @@ -60,7 +60,7 @@ static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_query.c,v 1.14 2001/06/11 10:06:01 itojun Exp $"; +static char rcsid[] = "$OpenBSD: res_query.c,v 1.15 2001/06/27 00:58:55 lebel Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -390,8 +390,8 @@ hostalias(name) break; for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2) ; - strncpy(abuf, cp1, sizeof(abuf) - 1); - abuf[sizeof(abuf) - 1] = *cp2 = '\0'; + *cp2 = '\0'; + strlcpy(abuf, cp1, sizeof(abuf)); fclose(fp); return (abuf); } diff --git a/lib/libc/regex/regerror.c b/lib/libc/regex/regerror.c index 23915915a5b..a5c26f60122 100644 --- a/lib/libc/regex/regerror.c +++ b/lib/libc/regex/regerror.c @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94"; #else -static char rcsid[] = "$OpenBSD: regerror.c,v 1.5 1998/03/19 00:30:10 millert Exp $"; +static char rcsid[] = "$OpenBSD: regerror.c,v 1.6 2001/06/27 00:58:55 lebel Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -149,8 +149,7 @@ size_t errbuf_size; len = strlen(s) + 1; if (errbuf_size > 0) { - (void) strncpy(errbuf, s, errbuf_size-1); - errbuf[errbuf_size-1] = '\0'; + strlcpy(errbuf, s, errbuf_size); } return(len); diff --git a/lib/libc/rpc/clnt_simple.c b/lib/libc/rpc/clnt_simple.c index fd4e2fe5a16..06ee3c430cc 100644 --- a/lib/libc/rpc/clnt_simple.c +++ b/lib/libc/rpc/clnt_simple.c @@ -29,7 +29,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: clnt_simple.c,v 1.9 2001/03/03 06:50:28 deraadt Exp $"; +static char *rcsid = "$OpenBSD: clnt_simple.c,v 1.10 2001/06/27 00:58:56 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -111,8 +111,7 @@ callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out) crp->valid = 1; crp->oldprognum = prognum; crp->oldversnum = versnum; - (void) strncpy(crp->oldhost, host, MAXHOSTNAMELEN-1); - crp->oldhost[MAXHOSTNAMELEN-1] = '\0'; + strlcpy(crp->oldhost, host, MAXHOSTNAMELEN); } tottimeout.tv_sec = 25; tottimeout.tv_usec = 0; diff --git a/lib/libc/rpc/getrpcent.c b/lib/libc/rpc/getrpcent.c index a1c523aff59..a78a5ff3319 100644 --- a/lib/libc/rpc/getrpcent.c +++ b/lib/libc/rpc/getrpcent.c @@ -29,7 +29,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: getrpcent.c,v 1.9 2001/03/03 06:50:28 deraadt Exp $"; +static char *rcsid = "$OpenBSD: getrpcent.c,v 1.10 2001/06/27 00:58:56 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -165,8 +165,7 @@ interpret(val, len) if (d == NULL) return (0); - (void) strncpy(d->line, val, BUFSIZ); - d->line[BUFSIZ] = '\0'; + strlcpy(d->line, val, sizeof(d->line)); p = d->line; p[len] = '\n'; if (*p == '#') diff --git a/lib/libc/stdlib/realpath.c b/lib/libc/stdlib/realpath.c index 02886014649..a6195c1dcbd 100644 --- a/lib/libc/stdlib/realpath.c +++ b/lib/libc/stdlib/realpath.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: realpath.c,v 1.4 1998/05/18 09:55:19 deraadt Exp $"; +static char *rcsid = "$OpenBSD: realpath.c,v 1.5 2001/06/27 00:58:56 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -78,8 +78,7 @@ realpath(path, resolved) * if it is a directory, then change to that directory. * get the current directory name and append the basename. */ - (void)strncpy(resolved, path, MAXPATHLEN - 1); - resolved[MAXPATHLEN - 1] = '\0'; + strlcpy(resolved, path, MAXPATHLEN); loop: q = strrchr(resolved, '/'); if (q != NULL) { diff --git a/lib/libc/string/__strerror.c b/lib/libc/string/__strerror.c index 9c023f8a534..04fdce580a4 100644 --- a/lib/libc/string/__strerror.c +++ b/lib/libc/string/__strerror.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: __strerror.c,v 1.6 1996/09/25 08:17:30 deraadt Exp $"; +static char *rcsid = "$OpenBSD: __strerror.c,v 1.7 2001/06/27 00:58:56 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #ifdef NLS @@ -87,16 +87,14 @@ __strerror(num, buf) errnum = num; /* convert to unsigned */ if (errnum < sys_nerr) { #ifdef NLS - strncpy(buf, catgets(catd, 1, errnum, - (char *)sys_errlist[errnum]), NL_TEXTMAX-1); - buf[NL_TEXTMAX - 1] = '\0'; + strlcpy(buf, catgets(catd, 1, errnum, + (char *)sys_errlist[errnum]), NL_TEXTMAX); #else return(sys_errlist[errnum]); #endif } else { #ifdef NLS - strncpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX-1); - buf[NL_TEXTMAX - 1] = '\0'; + strlcpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX); #else strcpy(buf, UPREFIX); #endif diff --git a/lib/libc/string/__strsignal.c b/lib/libc/string/__strsignal.c index ae0df72cd36..4ca5bad3c0f 100644 --- a/lib/libc/string/__strsignal.c +++ b/lib/libc/string/__strsignal.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: __strsignal.c,v 1.5 1996/09/25 13:19:01 deraadt Exp $"; +static char *rcsid = "$OpenBSD: __strsignal.c,v 1.6 2001/06/27 00:58:56 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #ifdef NLS @@ -80,16 +80,14 @@ __strsignal(num, buf) signum = num; /* convert to unsigned */ if (signum < NSIG) { #ifdef NLS - strncpy(buf, catgets(catd, 2, signum, - (char *)sys_siglist[signum]), NL_TEXTMAX-1); - buf[NL_TEXTMAX-1] = '\0'; + strlcpy(buf, catgets(catd, 2, signum, + (char *)sys_siglist[signum]), NL_TEXTMAX); #else return((char *)sys_siglist[signum]); #endif } else { #ifdef NLS - strncpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX-1); - buf[NL_TEXTMAX-1] = '\0'; + strlcpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX); #else strcpy(buf, UPREFIX); #endif diff --git a/lib/libc/time/localtime.c b/lib/libc/time/localtime.c index 399d53802f0..106103ad80c 100644 --- a/lib/libc/time/localtime.c +++ b/lib/libc/time/localtime.c @@ -5,7 +5,7 @@ #if defined(LIBC_SCCS) && !defined(lint) && !defined(NOID) static char elsieid[] = "@(#)localtime.c 7.70"; -static char rcsid[] = "$OpenBSD: localtime.c,v 1.19 2000/04/16 16:24:03 d Exp $"; +static char rcsid[] = "$OpenBSD: localtime.c,v 1.20 2001/06/27 00:58:57 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -904,12 +904,10 @@ const int lastditch; if ((size_t) sp->charcnt > sizeof sp->chars) return -1; cp = sp->chars; - (void) strncpy(cp, stdname, stdlen); - cp += stdlen; - *cp++ = '\0'; + strlcpy(cp, stdname, stdlen + 1); + cp += stdlen + 1; if (dstlen != 0) { - (void) strncpy(cp, dstname, dstlen); - *(cp + dstlen) = '\0'; + strlcpy(cp, dstname, dstlen + 1); } return 0; } diff --git a/lib/libc/time/zdump.c b/lib/libc/time/zdump.c index de3bb6464ac..a4a4049b09b 100644 --- a/lib/libc/time/zdump.c +++ b/lib/libc/time/zdump.c @@ -1,6 +1,6 @@ #if defined(LIBC_SCCS) && !defined(lint) && !defined(NOID) static char elsieid[] = "@(#)zdump.c 7.29"; -static char rcsid[] = "$OpenBSD: zdump.c,v 1.8 2001/03/26 15:25:51 millert Exp $"; +static char rcsid[] = "$OpenBSD: zdump.c,v 1.9 2001/06/27 00:58:57 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -229,7 +229,7 @@ _("%s: usage is %s [ -v ] [ -c cutoff ] zonename ...\n"), t += SECSPERHOUR * HOURSPERDAY; show(argv[i], t, TRUE); tm = *localtime(&t); - (void) strncpy(buf, abbr(&tm), (sizeof buf) - 1); + strlcpy(buf, abbr(&tm), (sizeof buf)); for ( ; ; ) { if (cutoff != NULL && t >= cuttime) break; @@ -244,8 +244,8 @@ _("%s: usage is %s [ -v ] [ -c cutoff ] zonename ...\n"), strcmp(abbr(&newtm), buf) != 0) { newt = hunt(argv[i], t, newt); newtm = *localtime(&newt); - (void) strncpy(buf, abbr(&newtm), - (sizeof buf) - 1); + strlcpy(buf, abbr(&newtm), + (sizeof buf)); } t = newt; tm = newtm; @@ -285,7 +285,7 @@ time_t hit; static char loab[MAX_STRING_LENGTH]; lotm = *localtime(&lot); - (void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1); + strlcpy(loab, abbr(&lotm), (sizeof loab)); while ((hit - lot) >= 2) { t = lot / 2 + hit / 2; if (t <= lot) diff --git a/lib/libc/yp/yp_bind.c b/lib/libc/yp/yp_bind.c index 47cf920737b..c0a84b30e4a 100644 --- a/lib/libc/yp/yp_bind.c +++ b/lib/libc/yp/yp_bind.c @@ -31,7 +31,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: yp_bind.c,v 1.10 1999/08/17 09:13:13 millert Exp $"; +static char *rcsid = "$OpenBSD: yp_bind.c,v 1.11 2001/06/27 00:58:57 lebel Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -226,8 +226,7 @@ gotdata: sizeof(ysd->dom_server_addr.sin_addr.s_addr)); ysd->dom_server_port = ysd->dom_server_addr.sin_port; ysd->dom_vers = YPVERS; - (void)strncpy(ysd->dom_domain, dom, sizeof ysd->dom_domain-1); - ysd->dom_domain[sizeof ysd->dom_domain-1] = '\0'; + strlcpy(ysd->dom_domain, dom, sizeof ysd->dom_domain); } tv.tv_sec = _yplib_timeout / 2; tv.tv_usec = 0; |