WARNS = 2, sbin/ping...
Sean Chittenden <[email protected]> Sun, 9 Feb 2003 03:08:53 -0800
| Newsgroups | gmane.os.freebsd.devel.audit |
|---|---|
| Message-ID | <[email protected]> |
Speaking of WARNS2, here's a patch that bumps ping(8) to WARNS2. Once upon a tie it used to be WARNS5, but the patch has rotted some. The biggie in this one was collisions with sin(3) and sockaddr_in variable sin. -sc -- Sean Chittenden
patch
(text/plain, 4.3 KB)
Index: Makefile
===================================================================
RCS file: /home/ncvs/src/sbin/ping/Makefile,v
retrieving revision 1.17
diff -u -r1.17 Makefile
--- Makefile 4 Dec 2001 02:19:55 -0000 1.17
+++ Makefile 9 Feb 2003 11:09:17 -0000
@@ -8,7 +8,7 @@
.if ${MACHINE_ARCH} == "alpha"
CFLAGS+=-fno-builtin # GCC's builtin memcpy doesn't do unaligned copies
.endif
-WARNS= 0
+WARNS= 2
DPADD= ${LIBM}
LDADD= -lm
Index: ping.c
===================================================================
RCS file: /home/ncvs/src/sbin/ping/ping.c,v
retrieving revision 1.83
diff -u -r1.83 ping.c
--- ping.c 29 Jan 2003 20:42:42 -0000 1.83
+++ ping.c 9 Feb 2003 11:09:17 -0000
@@ -203,7 +203,7 @@
int argc;
char *const *argv;
{
- struct sockaddr_in from, sin;
+ struct sockaddr_in from, sock_in;
struct in_addr ifaddr;
struct timeval last, intvl;
struct iovec iov;
@@ -230,7 +230,7 @@
#endif
unsigned char loop, mttl;
- source = NULL;
+ payload = source = NULL;
#ifdef IPSEC_POLICY_IPSEC
policy_in = policy_out = NULL;
#endif
@@ -431,9 +431,9 @@
fill((char *)datap, payload);
}
if (source) {
- bzero((char *)&sin, sizeof(sin));
- sin.sin_family = AF_INET;
- if (inet_aton(source, &sin.sin_addr) != 0) {
+ bzero((char *)&sock_in, sizeof(sock_in));
+ sock_in.sin_family = AF_INET;
+ if (inet_aton(source, &sock_in.sin_addr) != 0) {
shostname = source;
} else {
hp = gethostbyname2(source, AF_INET);
@@ -441,18 +441,18 @@
errx(EX_NOHOST, "cannot resolve %s: %s",
source, hstrerror(h_errno));
- sin.sin_len = sizeof sin;
- if (hp->h_length > sizeof(sin.sin_addr) ||
+ sock_in.sin_len = sizeof sock_in;
+ if ((unsigned)hp->h_length > sizeof(sock_in.sin_addr) ||
hp->h_length < 0)
errx(1, "gethostbyname2: illegal address");
- memcpy(&sin.sin_addr, hp->h_addr_list[0],
- sizeof(sin.sin_addr));
+ memcpy(&sock_in.sin_addr, hp->h_addr_list[0],
+ sizeof(sock_in.sin_addr));
(void)strncpy(snamebuf, hp->h_name,
sizeof(snamebuf) - 1);
snamebuf[sizeof(snamebuf) - 1] = '\0';
shostname = snamebuf;
}
- if (bind(s, (struct sockaddr *)&sin, sizeof sin) == -1)
+ if (bind(s, (struct sockaddr *)&sock_in, sizeof sock_in) == -1)
err(1, "bind");
}
@@ -468,7 +468,7 @@
errx(EX_NOHOST, "cannot resolve %s: %s",
target, hstrerror(h_errno));
- if (hp->h_length > sizeof(to->sin_addr))
+ if ((unsigned)hp->h_length > sizeof(to->sin_addr))
errx(1, "gethostbyname2 returned an illegal address");
memcpy(&to->sin_addr, hp->h_addr_list[0], sizeof to->sin_addr);
(void)strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1);
@@ -557,7 +557,7 @@
ip->ip_off = df ? IP_DF : 0;
ip->ip_ttl = ttl;
ip->ip_p = IPPROTO_ICMP;
- ip->ip_src.s_addr = source ? sin.sin_addr.s_addr : INADDR_ANY;
+ ip->ip_src.s_addr = source ? sock_in.sin_addr.s_addr : INADDR_ANY;
ip->ip_dst = to->sin_addr;
}
/* record route option */
@@ -701,7 +701,7 @@
int cc, n;
check_status();
- if (s >= FD_SETSIZE)
+ if ((unsigned)s >= FD_SETSIZE)
errx(EX_OSERR, "descriptor too large");
FD_ZERO(&rfds);
FD_SET(s, &rfds);
@@ -722,7 +722,7 @@
if (n < 0)
continue; /* Must be EINTR. */
if (n == 1) {
- struct timeval *t = NULL;
+ struct timeval *tv = NULL;
#ifdef SO_TIMESTAMP
struct cmsghdr *cmsg = (struct cmsghdr *)&ctrl;
@@ -738,19 +738,19 @@
#ifdef SO_TIMESTAMP
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_TIMESTAMP &&
- cmsg->cmsg_len == CMSG_LEN(sizeof *t)) {
+ cmsg->cmsg_len == CMSG_LEN(sizeof *tv)) {
/* Copy to avoid alignment problems: */
memcpy(&now, CMSG_DATA(cmsg), sizeof(now));
- t = &now;
+ tv = &now;
}
#endif
- if (t == NULL) {
+ if (tv == NULL) {
(void)gettimeofday(&now, NULL);
- t = &now;
+ tv = &now;
}
- pr_pack((char *)packet, cc, &from, t);
- if (options & F_ONCE && nreceived ||
- npackets && nreceived >= npackets)
+ pr_pack((char *)packet, cc, &from, tv);
+ if ((options & F_ONCE && nreceived) ||
+ (npackets && nreceived >= npackets))
break;
}
if (n == 0 || options & F_FLOOD) {
@@ -910,7 +910,7 @@
#else
tp = icp->icmp_data;
#endif
- tp+=MASKLEN;
+ tp += MASKLEN;
/* Copy to avoid alignment problems: */
memcpy(&tv1, tp, sizeof(tv1));
signature.asc
(application/pgp-signature, 202 B)
-----BEGIN PGP SIGNATURE----- Comment: Sean Chittenden <[email protected]> iD8DBQE+RjbEjoUuCl9bPssRAuBEAJ4uB1zsLtKdmL+dB9hzUvYbh7idPQCgrLmB fXSOGG9/Yrt4lpHgjUc0Vq4= =5r9P -----END PGP SIGNATURE-----