diff options
author | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2004-01-21 00:30:16 +0000 |
---|---|---|
committer | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2004-01-21 00:30:16 +0000 |
commit | 749724bd744d27e0c7bb851226133f1509be6584 (patch) | |
tree | 0fcca6d3822cd8f2645230924f374b9ede16aeab | |
parent | 47dd934cb84b71e78e79df9251cfc2ab126aaf22 (diff) |
Replace some strncpy() calls with strlcpy()
tested by jose@, ok canacar@ and otto@
-rw-r--r-- | lib/libpcap/inet.c | 17 | ||||
-rw-r--r-- | lib/libpcap/pcap-bpf.c | 6 |
2 files changed, 11 insertions, 12 deletions
diff --git a/lib/libpcap/inet.c b/lib/libpcap/inet.c index 2d932ceb930..63940e1a53d 100644 --- a/lib/libpcap/inet.c +++ b/lib/libpcap/inet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inet.c,v 1.14 2002/02/19 19:39:37 millert Exp $ */ +/* $OpenBSD: inet.c,v 1.15 2004/01/21 00:30:15 jfb Exp $ */ /* * Copyright (c) 1994, 1995, 1996, 1997, 1998 @@ -35,7 +35,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/inet.c,v 1.14 2002/02/19 19:39:37 millert Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/inet.c,v 1.15 2004/01/21 00:30:15 jfb Exp $ (LBL)"; #endif #include <sys/param.h> @@ -123,14 +123,13 @@ pcap_lookupdev(errbuf) } } if (mp == NULL) { - (void)strncpy(errbuf, "no suitable device found", + (void)strlcpy(errbuf, "no suitable device found", PCAP_ERRBUF_SIZE); freeifaddrs(ifap); return (NULL); } - (void)strncpy(device, mp->ifa_name, sizeof(device) - 1); - device[sizeof(device) - 1] = '\0'; + (void)strlcpy(device, mp->ifa_name, sizeof(device)); freeifaddrs(ifap); return (device); #else @@ -181,7 +180,8 @@ pcap_lookupdev(errbuf) * SIOCGIFFLAGS stomps over it because the requests * are returned in a union.) */ - strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name)); + (void)strlcpy(ifr.ifr_name, ifrp->ifr_name, + sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) { if (errno == ENXIO) continue; @@ -212,8 +212,7 @@ pcap_lookupdev(errbuf) return (NULL); } - (void)strncpy(device, mp->ifr_name, sizeof(device) - 1); - device[sizeof(device) - 1] = '\0'; + (void)strlcpy(device, mp->ifr_name, sizeof(device)); return (device); #endif } @@ -239,7 +238,7 @@ pcap_lookupnet(device, netp, maskp, errbuf) /* XXX Work around Linux kernel bug */ ifr.ifr_addr.sa_family = AF_INET; #endif - (void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + (void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) { if (errno == EADDRNOTAVAIL) { (void)snprintf(errbuf, PCAP_ERRBUF_SIZE, diff --git a/lib/libpcap/pcap-bpf.c b/lib/libpcap/pcap-bpf.c index c2ed883de2b..3e07bca9942 100644 --- a/lib/libpcap/pcap-bpf.c +++ b/lib/libpcap/pcap-bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcap-bpf.c,v 1.13 2003/11/24 05:39:42 mickey Exp $ */ +/* $OpenBSD: pcap-bpf.c,v 1.14 2004/01/21 00:30:15 jfb Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996, 1998 @@ -22,7 +22,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/pcap-bpf.c,v 1.13 2003/11/24 05:39:42 mickey Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/lib/libpcap/pcap-bpf.c,v 1.14 2004/01/21 00:30:15 jfb Exp $ (LBL)"; #endif #include <sys/param.h> /* optionally get BSD define */ @@ -209,7 +209,7 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf) */ (void) ioctl(fd, BIOCSBLEN, (caddr_t)&v); - (void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); + (void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) { snprintf(ebuf, PCAP_ERRBUF_SIZE, "%s: %s", device, pcap_strerror(errno)); |