Date: Sun, 9 Feb 2003 03:08:53 -0800 From: Sean Chittenden <seanc@FreeBSD.org> To: audit@FreeBSD.org Subject: WARNS = 2, sbin/ping... Message-ID: <20030209110853.GP15936@perrin.int.nxad.com>
next in thread | raw e-mail | index | archive | help
--+/c+wG9PuVDVAlsu Content-Type: multipart/mixed; boundary="uLcrxnkzOGy8pA6s" Content-Disposition: inline --uLcrxnkzOGy8pA6s Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 =20 --=20 Sean Chittenden --uLcrxnkzOGy8pA6s Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=patch Content-Transfer-Encoding: quoted-printable Index: Makefile =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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} =3D=3D "alpha" CFLAGS+=3D-fno-builtin # GCC's builtin memcpy doesn't do unaligned copies .endif -WARNS=3D 0 +WARNS=3D 2 DPADD=3D ${LIBM} LDADD=3D -lm =20 Index: ping.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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; =20 - source =3D NULL; + payload =3D source =3D NULL; #ifdef IPSEC_POLICY_IPSEC policy_in =3D policy_out =3D NULL; #endif @@ -431,9 +431,9 @@ fill((char *)datap, payload); } if (source) { - bzero((char *)&sin, sizeof(sin)); - sin.sin_family =3D AF_INET; - if (inet_aton(source, &sin.sin_addr) !=3D 0) { + bzero((char *)&sock_in, sizeof(sock_in)); + sock_in.sin_family =3D AF_INET; + if (inet_aton(source, &sock_in.sin_addr) !=3D 0) { shostname =3D source; } else { hp =3D gethostbyname2(source, AF_INET); @@ -441,18 +441,18 @@ errx(EX_NOHOST, "cannot resolve %s: %s", source, hstrerror(h_errno)); =20 - sin.sin_len =3D sizeof sin; - if (hp->h_length > sizeof(sin.sin_addr) || + sock_in.sin_len =3D 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] =3D '\0'; shostname =3D snamebuf; } - if (bind(s, (struct sockaddr *)&sin, sizeof sin) =3D=3D -1) + if (bind(s, (struct sockaddr *)&sock_in, sizeof sock_in) =3D=3D -1) err(1, "bind"); } =20 @@ -468,7 +468,7 @@ errx(EX_NOHOST, "cannot resolve %s: %s", target, hstrerror(h_errno)); =20 - 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 =3D df ? IP_DF : 0; ip->ip_ttl =3D ttl; ip->ip_p =3D IPPROTO_ICMP; - ip->ip_src.s_addr =3D source ? sin.sin_addr.s_addr : INADDR_ANY; + ip->ip_src.s_addr =3D source ? sock_in.sin_addr.s_addr : INADDR_ANY; ip->ip_dst =3D to->sin_addr; } /* record route option */ @@ -701,7 +701,7 @@ int cc, n; =20 check_status(); - if (s >=3D FD_SETSIZE) + if ((unsigned)s >=3D 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 =3D=3D 1) { - struct timeval *t =3D NULL; + struct timeval *tv =3D NULL; #ifdef SO_TIMESTAMP struct cmsghdr *cmsg =3D (struct cmsghdr *)&ctrl; =20 @@ -738,19 +738,19 @@ #ifdef SO_TIMESTAMP if (cmsg->cmsg_level =3D=3D SOL_SOCKET && cmsg->cmsg_type =3D=3D SCM_TIMESTAMP && - cmsg->cmsg_len =3D=3D CMSG_LEN(sizeof *t)) { + cmsg->cmsg_len =3D=3D CMSG_LEN(sizeof *tv)) { /* Copy to avoid alignment problems: */ memcpy(&now, CMSG_DATA(cmsg), sizeof(now)); - t =3D &now; + tv =3D &now; } #endif - if (t =3D=3D NULL) { + if (tv =3D=3D NULL) { (void)gettimeofday(&now, NULL); - t =3D &now; + tv =3D &now; } - pr_pack((char *)packet, cc, &from, t); - if (options & F_ONCE && nreceived || - npackets && nreceived >=3D npackets) + pr_pack((char *)packet, cc, &from, tv); + if ((options & F_ONCE && nreceived) || + (npackets && nreceived >=3D npackets)) break; } if (n =3D=3D 0 || options & F_FLOOD) { @@ -910,7 +910,7 @@ #else tp =3D icp->icmp_data; #endif - tp+=3DMASKLEN; + tp +=3D MASKLEN; =20 /* Copy to avoid alignment problems: */ memcpy(&tv1, tp, sizeof(tv1)); --uLcrxnkzOGy8pA6s-- --+/c+wG9PuVDVAlsu Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Comment: Sean Chittenden <sean@chittenden.org> iD8DBQE+RjbEjoUuCl9bPssRAuBEAJ4uB1zsLtKdmL+dB9hzUvYbh7idPQCgrLmB fXSOGG9/Yrt4lpHgjUc0Vq4= =5r9P -----END PGP SIGNATURE----- --+/c+wG9PuVDVAlsu-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030209110853.GP15936>