From: Rafael Sadowski Subject: relayd: replace bzero(3) with memset(3) To: tech@openbsd.org Date: Sat, 16 May 2026 15:25:01 +0200 Since ssl.c has now been committed with explicit_bzero and everything else looks fine, is there any objection? OK? The bzero() function conforms to the X/Open System Interfaces option of the IEEE Std 1003.1-2004 (“POSIX.1”) specification. It was removed from the standard in IEEE Std 1003.1-2008 (“POSIX.1”), which recommends using memset(3) instead. -- bzero(3) Index: agentx_control.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/agentx_control.c,v diff -u -p -r1.8 agentx_control.c --- agentx_control.c 2 Mar 2026 19:28:01 -0000 1.8 +++ agentx_control.c 16 May 2026 13:17:30 -0000 @@ -445,7 +445,7 @@ agentx_setsock(struct relayd *lenv, enum if ((s = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) == -1) goto done; - bzero(&sun, sizeof(sun)); + memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; if (strlcpy(sun.sun_path, lenv->sc_conf.agentx_path, sizeof(sun.sun_path)) >= sizeof(sun.sun_path)) @@ -1124,7 +1124,7 @@ snmp_string2oid(const char *oidstr, stru if (strlcpy(str, oidstr, sizeof(str)) >= sizeof(str)) return -1; - bzero(o, sizeof(*o)); + memset(o, 0, sizeof(*o)); for (p = sp = str; p != NULL; sp = p) { if ((p = strpbrk(p, ".-")) != NULL) Index: carp.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/carp.c,v diff -u -p -r1.14 carp.c --- carp.c 2 Mar 2026 19:28:01 -0000 1.14 +++ carp.c 16 May 2026 13:17:30 -0000 @@ -113,7 +113,7 @@ carp_demote_get(char *group) return (-1); } - bzero(&ifgr, sizeof(ifgr)); + memset(&ifgr, 0, sizeof(ifgr)); if (strlcpy(ifgr.ifgr_name, group, sizeof(ifgr.ifgr_name)) >= sizeof(ifgr.ifgr_name)) { log_warn("%s: invalid group", __func__); @@ -198,7 +198,7 @@ carp_demote_ioctl(char *group, int demot return (-1); } - bzero(&ifgr, sizeof(ifgr)); + memset(&ifgr, 0, sizeof(ifgr)); if (strlcpy(ifgr.ifgr_name, group, sizeof(ifgr.ifgr_name)) >= sizeof(ifgr.ifgr_name)) { log_warn("%s: invalid group", __func__); Index: check_icmp.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/check_icmp.c,v diff -u -p -r1.49 check_icmp.c --- check_icmp.c 2 Mar 2026 19:28:01 -0000 1.49 +++ check_icmp.c 16 May 2026 13:17:30 -0000 @@ -175,7 +175,7 @@ send_icmp(int s, short event, void *arg) return; } - bzero(&packet, sizeof(packet)); + memset(&packet, 0, sizeof(packet)); icp = (struct icmp *)packet; icp6 = (struct icmp6_hdr *)packet; if (cie->af == AF_INET) { @@ -301,8 +301,8 @@ recv_icmp(int s, short event, void *arg) return; } - bzero(&packet, sizeof(packet)); - bzero(&ss, sizeof(ss)); + memset(&packet, 0, sizeof(packet)); + memset(&ss, 0, sizeof(ss)); slen = sizeof(ss); r = recvfrom(s, packet, sizeof(packet), 0, Index: check_script.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/check_script.c,v diff -u -p -r1.23 check_script.c --- check_script.c 2 Mar 2026 19:28:01 -0000 1.23 +++ check_script.c 16 May 2026 13:17:30 -0000 @@ -148,7 +148,7 @@ script_exec(struct relayd *env, struct c default: /* Kill the process after a timeout */ signal(SIGALRM, script_sig_alarm); - bzero(&it, sizeof(it)); + memset(&it, 0, sizeof(it)); bcopy(tv, &it.it_value, sizeof(it.it_value)); setitimer(ITIMER_REAL, &it, NULL); @@ -169,7 +169,7 @@ script_exec(struct relayd *env, struct c done: /* Disable the process timeout timer */ - bzero(&it, sizeof(it)); + memset(&it, 0, sizeof(it)); setitimer(ITIMER_REAL, &it, NULL); child = -1; Index: check_tcp.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/check_tcp.c,v diff -u -p -r1.62 check_tcp.c --- check_tcp.c 2 Mar 2026 19:28:01 -0000 1.62 +++ check_tcp.c 16 May 2026 13:17:30 -0000 @@ -79,7 +79,7 @@ check_tcp(struct ctl_tcp_event *cte) cte->s = s; - bzero(&lng, sizeof(lng)); + memset(&lng, 0, sizeof(lng)); if (setsockopt(s, SOL_SOCKET, SO_LINGER, &lng, sizeof(lng)) == -1) goto bad; @@ -265,7 +265,7 @@ tcp_read_buf(int s, short event, void *a return; } - bzero(rbuf, sizeof(rbuf)); + memset(rbuf, 0, sizeof(rbuf)); br = read(s, rbuf, sizeof(rbuf) - 1); switch (br) { case -1: Index: check_tls.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/check_tls.c,v diff -u -p -r1.4 check_tls.c --- check_tls.c 2 Mar 2026 19:28:01 -0000 1.4 +++ check_tls.c 16 May 2026 13:17:30 -0000 @@ -52,7 +52,7 @@ check_tls_read(int s, short event, void return; } - bzero(rbuf, sizeof(rbuf)); + memset(rbuf, 0, sizeof(rbuf)); ret = tls_read(cte->tls, rbuf, sizeof(rbuf)); if (ret > 0) { Index: config.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/config.c,v diff -u -p -r1.50 config.c --- config.c 3 Apr 2026 13:21:00 -0000 1.50 +++ config.c 16 May 2026 13:17:30 -0000 @@ -99,7 +99,7 @@ config_init(struct relayd *env) return (-1); TAILQ_INIT(env->sc_protos); - bzero(&env->sc_proto_default, sizeof(env->sc_proto_default)); + memset(&env->sc_proto_default, 0, sizeof(env->sc_proto_default)); env->sc_proto_default.id = EMPTY_ID; env->sc_proto_default.flags = F_USED; env->sc_proto_default.tcpflags = TCPFLAG_DEFAULT; @@ -655,7 +655,7 @@ config_setrule(struct relayd *env, struc /* Now send all the rules */ TAILQ_FOREACH(rule, &proto->rules, rule_entry) { rule->rule_protoid = proto->id; - bzero(&rule->rule_ctl, sizeof(rule->rule_ctl)); + memset(&rule->rule_ctl, 0, sizeof(rule->rule_ctl)); c = 0; iov[c].iov_base = rule; iov[c++].iov_len = sizeof(*rule); Index: hce.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/hce.c,v diff -u -p -r1.83 hce.c --- hce.c 2 Mar 2026 19:28:01 -0000 1.83 +++ hce.c 16 May 2026 13:17:30 -0000 @@ -82,7 +82,7 @@ hce_setup_events(void) if (!event_initialized(&env->sc_ev)) { evtimer_set(&env->sc_ev, hce_launch_checks, env); - bzero(&tv, sizeof(tv)); + memset(&tv, 0, sizeof(tv)); evtimer_add(&env->sc_ev, &tv); } Index: parse.y =================================================================== RCS file: /cvs/src/usr.sbin/relayd/parse.y,v diff -u -p -r1.263 parse.y --- parse.y 15 May 2026 13:57:24 -0000 1.263 +++ parse.y 16 May 2026 13:17:30 -0000 @@ -3232,7 +3232,7 @@ host_dns(const char *s, struct addressli if ((cnt = host_if(s, al, max, port, ifname, ipproto)) != 0) return (cnt); - bzero(&hints, sizeof(hints)); + memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; /* DUMMY */ hints.ai_flags = AI_ADDRCONFIG; Index: pfe.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/pfe.c,v diff -u -p -r1.92 pfe.c --- pfe.c 2 Mar 2026 19:28:01 -0000 1.92 +++ pfe.c 16 May 2026 13:17:30 -0000 @@ -497,7 +497,7 @@ enable_rdr(struct ctl_conn *c, struct ct rdr->conf.flags |= F_ADD; log_debug("%s: redirect %d", __func__, rdr->conf.id); - bzero(&eid, sizeof(eid)); + memset(&eid, 0, sizeof(eid)); /* XXX: we're syncing twice */ eid.id = rdr->table->conf.id; @@ -711,8 +711,8 @@ pfe_sync(void) struct ctl_demote demote; struct router *rt; - bzero(&id, sizeof(id)); - bzero(&imsg, sizeof(imsg)); + memset(&id, 0, sizeof(id)); + memset(&imsg, 0, sizeof(imsg)); TAILQ_FOREACH(rdr, env->sc_rdrs, entry) { rdr->conf.flags &= ~(F_BACKUP); rdr->conf.flags &= ~(F_DOWN); Index: pfe_filter.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/pfe_filter.c,v diff -u -p -r1.67 pfe_filter.c --- pfe_filter.c 2 Mar 2026 19:28:01 -0000 1.67 +++ pfe_filter.c 16 May 2026 13:17:30 -0000 @@ -226,7 +226,7 @@ kill_srcnodes(struct relayd *env, struct struct sockaddr_in *sain; struct sockaddr_in6 *sain6; - bzero(&psnk, sizeof(psnk)); + memset(&psnk, 0, sizeof(psnk)); /* Only match the destination address, source mask will be zero */ memset(&psnk.psnk_dst.addr.v.a.mask, 0xff, @@ -308,7 +308,7 @@ transaction_init(struct relayd *env, con env->sc_pf->pft.esize = sizeof(env->sc_pf->pfte); env->sc_pf->pft.array = &env->sc_pf->pfte; - bzero(&env->sc_pf->pfte, sizeof(env->sc_pf->pfte)); + memset(&env->sc_pf->pfte, 0, sizeof(env->sc_pf->pfte)); (void)strlcpy(env->sc_pf->pfte.anchor, anchor, PF_ANCHOR_NAME_SIZE); env->sc_pf->pfte.type = PF_TRANS_RULESET; @@ -343,7 +343,7 @@ sync_ruleset(struct relayd *env, struct if ((env->sc_conf.flags & F_NEEDPF) == 0) return; - bzero(anchor, sizeof(anchor)); + memset(anchor, 0, sizeof(anchor)); if (strlcpy(anchor, RELAYD_ANCHOR "/", sizeof(anchor)) >= PF_ANCHOR_NAME_SIZE) goto toolong; @@ -548,7 +548,7 @@ natlook(struct relayd *env, struct ctl_n if (!(env->sc_conf.flags & F_NEEDPF)) return (0); - bzero(&pnl, sizeof(pnl)); + memset(&pnl, 0, sizeof(pnl)); if ((pnl.af = cnl->src.ss_family) != cnl->dst.ss_family) fatalx("%s: illegal address families", __func__); @@ -622,7 +622,7 @@ check_table(struct relayd *env, struct r if (table == NULL) return (0); - bzero(&io, sizeof(io)); + memset(&io, 0, sizeof(io)); io.pfrio_esize = sizeof(struct pfr_tstats); io.pfrio_size = 1; io.pfrio_buffer = &tstats; Index: pfe_route.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/pfe_route.c,v diff -u -p -r1.15 pfe_route.c --- pfe_route.c 2 Mar 2026 19:28:01 -0000 1.15 +++ pfe_route.c 16 May 2026 13:17:30 -0000 @@ -97,7 +97,7 @@ pfe_apply_prefixlen(struct sockaddr_stor q = len >> 3; r = len & 7; - bzero(ss, sizeof(*ss)); + memset(ss, 0, sizeof(*ss)); ss->ss_family = af; switch (af) { case AF_INET: @@ -130,7 +130,7 @@ pfe_route(struct relayd *env, struct ctl int iovcnt = 0; char *gwname; - bzero(&hdr, sizeof(hdr)); + memset(&hdr, 0, sizeof(hdr)); hdr.rtm_msglen = sizeof(hdr); hdr.rtm_version = RTM_VERSION; hdr.rtm_type = HOST_ISUP(crt->up) ? RTM_ADD : RTM_DELETE; Index: proxy_protocol.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/proxy_protocol.c,v diff -u -p -r1.1 proxy_protocol.c --- proxy_protocol.c 18 Feb 2026 22:27:03 -0000 1.1 +++ proxy_protocol.c 16 May 2026 13:17:30 -0000 @@ -57,8 +57,8 @@ proxy_protocol_v1(struct rsession *con, const char *proxyproto; int ret; - bzero(&ibuf, sizeof(ibuf)); - bzero(&obuf, sizeof(obuf)); + memset(&ibuf, 0, sizeof(ibuf)); + memset(&obuf, 0, sizeof(obuf)); if (print_host(&con->se_in.ss, ibuf, sizeof(ibuf)) == NULL || print_host(&con->se_sockname, obuf, sizeof(obuf)) == NULL) Index: relay.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/relay.c,v diff -u -p -r1.263 relay.c --- relay.c 2 Apr 2026 13:38:24 -0000 1.263 +++ relay.c 16 May 2026 13:17:30 -0000 @@ -388,7 +388,7 @@ relay_statistics(int fd, short events, v getmonotime(&tv_now); TAILQ_FOREACH(rlay, env->sc_relays, rl_entry) { - bzero(&crs, sizeof(crs)); + memset(&crs, 0, sizeof(crs)); resethour = resetday = 0; cur = &rlay->rl_stats[ps->ps_instance]; @@ -554,7 +554,7 @@ relay_socket(struct sockaddr_storage *ss /* * Socket options */ - bzero(&lng, sizeof(lng)); + memset(&lng, 0, sizeof(lng)); if (setsockopt(s, SOL_SOCKET, SO_LINGER, &lng, sizeof(lng)) == -1) goto bad; if (reuseport) { @@ -965,7 +965,7 @@ relay_splice(struct ctl_relay_event *cre return (0); } - bzero(&sp, sizeof(sp)); + memset(&sp, 0, sizeof(sp)); sp.sp_fd = cre->dst->s; sp.sp_max = cre->toread > 0 ? cre->toread : 0; bcopy(&rlay->rl_conf.timeout, &sp.sp_idle, sizeof(sp.sp_idle)); @@ -1224,7 +1224,7 @@ relay_accept(int fd, short event, void * } con->se_cnl = cnl; - bzero(cnl, sizeof(*cnl)); + memset(cnl, 0, sizeof(*cnl)); cnl->in = -1; cnl->id = con->se_id; cnl->proc = ps->ps_instance; @@ -1486,7 +1486,7 @@ relay_bindanyreq(struct rsession *con, i struct ctl_bindany bnd; struct timeval tv; - bzero(&bnd, sizeof(bnd)); + memset(&bnd, 0, sizeof(bnd)); bnd.bnd_id = con->se_id; bnd.bnd_proc = ps->ps_instance; bnd.bnd_port = port; @@ -1751,8 +1751,8 @@ relay_close(struct rsession *con, const if ((env->sc_conf.opts & (RELAYD_OPT_LOGCON|RELAYD_OPT_LOGCONERR)) && msg != NULL) { - bzero(&ibuf, sizeof(ibuf)); - bzero(&obuf, sizeof(obuf)); + memset(&ibuf, 0, sizeof(ibuf)); + memset(&obuf, 0, sizeof(obuf)); (void)print_host(&con->se_in.ss, ibuf, sizeof(ibuf)); (void)print_host(&con->se_out.ss, obuf, sizeof(obuf)); if (EVBUFFER_LENGTH(con->se_log) && @@ -1949,7 +1949,7 @@ relay_dispatch_pfe(int fd, struct privse bcopy(&cnl, con->se_cnl, sizeof(*con->se_cnl)); evtimer_del(&con->se_ev); evtimer_set(&con->se_ev, relay_natlook, con); - bzero(&tv, sizeof(tv)); + memset(&tv, 0, sizeof(tv)); evtimer_add(&con->se_ev, &tv); break; case IMSG_CTL_SESSION: @@ -2011,7 +2011,7 @@ relay_dispatch_parent(int fd, struct pri evtimer_del(&con->se_ev); evtimer_set(&con->se_ev, relay_bindany, con); - bzero(&tv, sizeof(tv)); + memset(&tv, 0, sizeof(tv)); evtimer_add(&con->se_ev, &tv); break; case IMSG_CFG_TABLE: Index: relay_http.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/relay_http.c,v diff -u -p -r1.96 relay_http.c --- relay_http.c 2 Apr 2026 13:35:36 -0000 1.96 +++ relay_http.c 16 May 2026 13:17:30 -0000 @@ -887,7 +887,7 @@ relay_lookup_url(struct ctl_relay_event return (RES_BAD); } - bzero(hi, sizeof(hi)); + memset(hi, 0, sizeof(hi)); for (dots = -1, i = strlen(ph) - 1; i > 0; i--) { if (ph[i] == '.' && ++dots) hi[dots - 1] = &ph[i + 1]; @@ -1733,7 +1733,7 @@ relay_apply_actions(struct ctl_relay_eve kv->kv_match = match; } if (match != NULL && kp->kv_flags & KV_FLAG_MACRO) { - bzero(buf, sizeof(buf)); + memset(buf, 0, sizeof(buf)); if ((ptr = relay_expand_http(cre, kp->kv_value, buf, sizeof(buf))) == NULL) goto fail; Index: relay_udp.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/relay_udp.c,v diff -u -p -r1.52 relay_udp.c --- relay_udp.c 2 Mar 2026 19:28:01 -0000 1.52 +++ relay_udp.c 16 May 2026 13:17:30 -0000 @@ -309,7 +309,7 @@ relay_udp_server(int fd, short sig, void if (cnl != NULL) { con->se_cnl = cnl; - bzero(cnl, sizeof(*cnl)); + memset(cnl, 0, sizeof(*cnl)); cnl->in = -1; cnl->id = con->se_id; cnl->proc = ps->ps_instance; Index: relayd.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/relayd.c,v diff -u -p -r1.198 relayd.c --- relayd.c 15 May 2026 13:57:24 -0000 1.198 +++ relayd.c 16 May 2026 13:17:30 -0000 @@ -1502,7 +1502,7 @@ event_again(struct event *ev, int fd, sh timersub(&tv_now, start, &tv_now); timersub(&tv_next, &tv_now, &tv_next); - bzero(&tv, sizeof(tv)); + memset(&tv, 0, sizeof(tv)); if (timercmp(&tv_next, &tv, >)) bcopy(&tv_next, &tv, sizeof(tv)); @@ -1614,7 +1614,7 @@ canonicalize_host(const char *host, char /* 1. remove repeated dots and convert upper case to lower case */ plen = strlen(host); - bzero(name, len); + memset(name, 0, len); for (i = j = 0; i < plen; i++) { if (j >= (len - 1)) goto fail; @@ -1723,7 +1723,7 @@ map6to4(struct sockaddr_storage *in6) struct sockaddr_in *sin4 = (struct sockaddr_in *)&out4; struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)in6; - bzero(sin4, sizeof(*sin4)); + memset(sin4, 0, sizeof(*sin4)); sin4->sin_len = sizeof(*sin4); sin4->sin_family = AF_INET; sin4->sin_port = sin6->sin6_port; @@ -1897,7 +1897,7 @@ prefixlen2mask6(u_int8_t prefixlen, u_in if (prefixlen > 128) prefixlen = 128; - bzero(&s6, sizeof(s6)); + memset(&s6, 0, sizeof(s6)); for (i = 0; i < prefixlen / 8; i++) s6.s6_addr[i] = 0xff; i = prefixlen % 8; Index: util.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/util.c,v diff -u -p -r1.6 util.c --- util.c 2 Mar 2026 19:28:01 -0000 1.6 +++ util.c 16 May 2026 13:17:30 -0000 @@ -209,7 +209,7 @@ print_availability(u_long cnt, u_long up if (cnt == 0) return (""); - bzero(buf, sizeof(buf)); + memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf), "%.2f%%", (double)up / cnt * 100); return (buf); } @@ -250,7 +250,7 @@ printb_flags(const u_int32_t v, const ch char c, *p, *r; p = r = buf[++idx % 2]; - bzero(p, BUFSIZ); + memset(p, 0, BUFSIZ); if (bits) { bits++;