Re: bgpd switch to memxyz() from bxyz()

2022-08-17 Thread Theo Buehler
On Wed, Aug 17, 2022 at 04:04:26PM +0200, Claudio Jeker wrote:
> I did switch to memset from bzero and from bcopy to memcpy whenever I
> touched the code but now I just decided to change all users of bcopy(),
> bzero() and bcmp() to use memcpy(), memset() and memcmp().
> 
> None of the bcopy() users had overlapping memory regions so memcpy()
> should be fine.

I agree that there are no overlaps as at least one of the two variables
is always on the stack. Also, the arguments were correctly reversed.

ok tb



bgpd switch to memxyz() from bxyz()

2022-08-17 Thread Claudio Jeker
I did switch to memset from bzero and from bcopy to memcpy whenever I
touched the code but now I just decided to change all users of bcopy(),
bzero() and bcmp() to use memcpy(), memset() and memcmp().

None of the bcopy() users had overlapping memory regions so memcpy()
should be fine.

-- 
:wq Claudio

Index: usr.sbin/bgpctl/bgpctl.c
===
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
retrieving revision 1.281
diff -u -p -r1.281 bgpctl.c
--- usr.sbin/bgpctl/bgpctl.c28 Jul 2022 10:40:25 -  1.281
+++ usr.sbin/bgpctl/bgpctl.c17 Aug 2022 13:56:57 -
@@ -131,7 +131,7 @@ main(int argc, char *argv[])
if (pledge("stdio", NULL) == -1)
err(1, "pledge");
 
-   bzero(, sizeof(ribreq));
+   memset(, 0, sizeof(ribreq));
if (res->as.type != AS_UNDEF)
ribreq.as = res->as;
if (res->addr.aid) {
@@ -160,7 +160,7 @@ main(int argc, char *argv[])
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
err(1, "control_init: socket");
 
-   bzero(_un, sizeof(sa_un));
+   memset(_un, 0, sizeof(sa_un));
sa_un.sun_family = AF_UNIX;
if (strlcpy(sa_un.sun_path, sockname, sizeof(sa_un.sun_path)) >=
sizeof(sa_un.sun_path))
@@ -235,7 +235,7 @@ main(int argc, char *argv[])
NULL, 0);
break;
case SHOW_RIB:
-   bzero(, sizeof(ribreq));
+   memset(, 0, sizeof(ribreq));
type = IMSG_CTL_SHOW_RIB;
if (res->addr.aid) {
ribreq.prefix = res->addr;
@@ -310,7 +310,7 @@ main(int argc, char *argv[])
break;
case NETWORK_ADD:
case NETWORK_REMOVE:
-   bzero(, sizeof(net));
+   memset(, 0, sizeof(net));
net.prefix = res->addr;
net.prefixlen = res->prefixlen;
net.rd = res->rd;
@@ -333,14 +333,14 @@ main(int argc, char *argv[])
done = 1;
break;
case NETWORK_SHOW:
-   bzero(, sizeof(ribreq));
+   memset(, 0, sizeof(ribreq));
ribreq.aid = res->aid;
strlcpy(ribreq.rib, res->rib, sizeof(ribreq.rib));
imsg_compose(ibuf, IMSG_CTL_SHOW_NETWORK, 0, 0, -1,
, sizeof(ribreq));
break;
case NETWORK_MRT:
-   bzero(, sizeof(ribreq));
+   memset(, 0, sizeof(ribreq));
if (res->as.type != AS_UNDEF)
ribreq.as = res->as;
if (res->addr.aid) {
@@ -1076,7 +1076,7 @@ network_bulk(struct parse_result *res)
/* Stop processing after a comment */
if (*b == '#')
break;
-   bzero(, sizeof(net));
+   memset(, 0, sizeof(net));
if (parse_prefix(b, strlen(b), , ) != 1)
errx(1, "bad prefix: %s", b);
net.prefix = h;
@@ -1145,7 +1145,7 @@ show_mrt_dump(struct mrt_rib *mr, struct
 
for (i = 0; i < mr->nentries; i++) {
mre = >entries[i];
-   bzero(, sizeof(ctl));
+   memset(, 0, sizeof(ctl));
ctl.prefix = mr->prefix;
ctl.prefixlen = mr->prefixlen;
if (mre->originated <= now)
@@ -1228,7 +1228,7 @@ network_mrt_dump(struct mrt_rib *mr, str
now = time(NULL);
for (i = 0; i < mr->nentries; i++) {
mre = >entries[i];
-   bzero(, sizeof(ctl));
+   memset(, 0, sizeof(ctl));
ctl.prefix = mr->prefix;
ctl.prefixlen = mr->prefixlen;
if (mre->originated <= now)
@@ -1269,7 +1269,7 @@ network_mrt_dump(struct mrt_rib *mr, str
!match_aspath(mre->aspath, mre->aspath_len, >as))
continue;
 
-   bzero(, sizeof(net));
+   memset(, 0, sizeof(net));
net.prefix = ctl.prefix;
net.prefixlen = ctl.prefixlen;
net.type = NETWORK_MRTCLONE;
Index: usr.sbin/bgpctl/mrtparser.c
===
RCS file: /cvs/src/usr.sbin/bgpctl/mrtparser.c,v
retrieving revision 1.17
diff -u -p -r1.17 mrtparser.c
--- usr.sbin/bgpctl/mrtparser.c 6 Feb 2022 09:52:32 -   1.17
+++ usr.sbin/bgpctl/mrtparser.c 17 Aug 2022 13:56:57 -
@@ -58,7 +58,7 @@ mrt_read_msg(int fd, struct mrt_hdr *hdr
 {
void *buf;
 
-   bzero(hdr, sizeof(*hdr));
+   memset(hdr, 0, sizeof(*hdr));
if (mrt_read_buf(fd, hdr, sizeof(*hdr)) != sizeof(*hdr))
return (NULL);
 
Index: usr.sbin/bgpctl/parser.c