diff options
author | 2001-06-27 00:58:53 +0000 | |
---|---|---|
committer | 2001-06-27 00:58:53 +0000 | |
commit | f1a075da3e4bb4f84a5bb83783c6b1943dc3da49 (patch) | |
tree | f3b98ca6be26aa2b00a7770f1dceff5312265655 /lib/libc/net | |
parent | Keep track of the ACQUIRE sequence number, and pass it to the kernel (diff) | |
download | wireguard-openbsd-f1a075da3e4bb4f84a5bb83783c6b1943dc3da49.tar.xz wireguard-openbsd-f1a075da3e4bb4f84a5bb83783c6b1943dc3da49.zip |
use strlcpy vs strncpy+a[len-1]='\0'. millert@ ok.
Diffstat (limited to 'lib/libc/net')
-rw-r--r-- | lib/libc/net/ethers.c | 7 | ||||
-rw-r--r-- | lib/libc/net/getaddrinfo.c | 5 | ||||
-rw-r--r-- | lib/libc/net/gethostnamadr.c | 8 | ||||
-rw-r--r-- | lib/libc/net/getifaddrs.c | 5 | ||||
-rw-r--r-- | lib/libc/net/getnetnamadr.c | 17 | ||||
-rw-r--r-- | lib/libc/net/ipx_addr.c | 5 | ||||
-rw-r--r-- | lib/libc/net/ns_addr.c | 5 | ||||
-rw-r--r-- | lib/libc/net/rcmd.c | 5 | ||||
-rw-r--r-- | lib/libc/net/res_init.c | 18 | ||||
-rw-r--r-- | lib/libc/net/res_query.c | 8 |
10 files changed, 34 insertions, 49 deletions
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); } |