Re: switchd: bzero -> memset

2018-04-03 Thread Michael W. Bombardieri
On Tue, Apr 03, 2018 at 10:20:42PM -0600, Theo de Raadt wrote:
> Michael W. Bombardieri  wrote:
> 
> > Hello,
> > 
> > switchd can just use memset instead of mixing memset with bzero.
> > But does the util.c change need to be sync'ed with other tools?
> 
> There are 418 calls to bzero in *bin/*/*c
> 
> bcopy isn't going to be removed from libc, and frankly it is
> diomatically simpler.
> 
> Would you believe in 15 years ago we have found calls where c and len
> were swapped, making it a no-op -- in security sensitive software?
Nice.
> 
> So I don't see the specific value in your proposal.

I agree, bzero is simpler and easier to grep for. But then grep'ing
is more complicated if you mix bzero and memset, so I guess it makes
sense to use one or the other at least within the same file.



Re: switchd: bzero -> memset

2018-04-03 Thread Theo de Raadt
Michael W. Bombardieri  wrote:

> Hello,
> 
> switchd can just use memset instead of mixing memset with bzero.
> But does the util.c change need to be sync'ed with other tools?

There are 418 calls to bzero in *bin/*/*c

bcopy isn't going to be removed from libc, and frankly it is
diomatically simpler.

Would you believe in 15 years ago we have found calls where c and len
were swapped, making it a no-op -- in security sensitive software?

So I don't see the specific value in your proposal.



switchd: bzero -> memset

2018-04-03 Thread Michael W. Bombardieri
Hello,

switchd can just use memset instead of mixing memset with bzero.
But does the util.c change need to be sync'ed with other tools?

- Michael


Index: ofp10.c
===
RCS file: /cvs/src/usr.sbin/switchd/ofp10.c,v
retrieving revision 1.19
diff -u -p -u -r1.19 ofp10.c
--- ofp10.c 2 Dec 2016 14:39:46 -   1.19
+++ ofp10.c 4 Apr 2018 04:00:19 -
@@ -342,7 +342,7 @@ ofp10_packet_match(struct packet *pkt, s
 {
struct ether_header *eh = pkt->pkt_eh;
 
-   bzero(m, sizeof(*m));
+   memset(m, 0, sizeof(*m));
m->m_wildcards = htonl(~flags);
 
if ((flags & (OFP10_WILDCARD_DL_SRC|OFP10_WILDCARD_DL_DST)) &&
@@ -377,7 +377,7 @@ ofp10_packet_in(struct switchd *sc, stru
if ((pin = ibuf_getdata(ibuf, sizeof(*pin))) == NULL)
return (-1);
 
-   bzero(, sizeof(pkt));
+   memset(, 0, sizeof(pkt));
len = ntohs(pin->pin_total_len);
srcport = ntohs(pin->pin_port);
 
Index: ofp13.c
===
RCS file: /cvs/src/usr.sbin/switchd/ofp13.c,v
retrieving revision 1.43
diff -u -p -u -r1.43 ofp13.c
--- ofp13.c 17 Jan 2017 09:21:50 -  1.43
+++ ofp13.c 4 Apr 2018 04:00:20 -
@@ -1029,7 +1029,7 @@ ofp13_packet_in(struct switchd *sc, stru
if (pin->pin_reason != OFP_PKTIN_REASON_NO_MATCH)
return (-1);
 
-   bzero(, sizeof(pkt));
+   memset(, 0, sizeof(pkt));
len = ntohs(pin->pin_total_len);
 
/* very basic way of getting the source port */
Index: switchd.c
===
RCS file: /cvs/src/usr.sbin/switchd/switchd.c,v
retrieving revision 1.15
diff -u -p -u -r1.15 switchd.c
--- switchd.c   9 Jan 2017 14:49:22 -   1.15
+++ switchd.c   4 Apr 2018 04:00:20 -
@@ -242,7 +242,7 @@ switchd_socket(struct sockaddr *sock, in
/*
 * Socket options
 */
-   bzero(, sizeof(lng));
+   memset(, 0, sizeof(lng));
if (setsockopt(s, SOL_SOCKET, SO_LINGER, , sizeof(lng)) == -1)
goto bad;
if (reuseport) {
Index: util.c
===
RCS file: /cvs/src/usr.sbin/switchd/util.c,v
retrieving revision 1.6
diff -u -p -u -r1.6 util.c
--- util.c  9 Jan 2017 14:49:22 -   1.6
+++ util.c  4 Apr 2018 04:00:20 -
@@ -196,7 +196,7 @@ prefixlen2mask6(uint8_t prefixlen, uint3
if (prefixlen > 128)
prefixlen = 128;
 
-   bzero(, sizeof(s6));
+   memset(, 0, sizeof(s6));
for (i = 0; i < prefixlen / 8; i++)
s6.s6_addr[i] = 0xff;
i = prefixlen % 8;
@@ -277,7 +277,7 @@ print_map(unsigned int type, struct cons
 
if (idx >= SWITCHD_CYCLE_BUFFERS)
idx = 0;
-   bzero(buf[idx], sizeof(buf[idx]));
+   memset(buf[idx], 0, sizeof(buf[idx]));
 
for (i = 0; map[i].cm_name != NULL; i++) {
if (map[i].cm_type == type) {