From: deraadt Date: Tue, 23 Jan 2024 14:13:55 +0000 (+0000) Subject: found some boilerplate strncpy to replace with strlcpy. They are in X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=55fc36399d0483b0959784a327c6bb54079febe8;p=openbsd found some boilerplate strncpy to replace with strlcpy. They are in messages, but the messages are zero'd first. ok jmatthew --- diff --git a/usr.sbin/ypbind/ypbind.c b/usr.sbin/ypbind/ypbind.c index 6193961f0b7..d8ca66d9571 100644 --- a/usr.sbin/ypbind/ypbind.c +++ b/usr.sbin/ypbind/ypbind.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ypbind.c,v 1.79 2023/11/27 18:37:53 tb Exp $ */ +/* $OpenBSD: ypbind.c,v 1.80 2024/01/23 14:13:55 deraadt Exp $ */ /* * Copyright (c) 1992, 1993, 1996, 1997, 1998 Theo de Raadt @@ -156,8 +156,7 @@ ypbindproc_domain_2x(SVCXPRT *transp, domainname *argp, CLIENT *clnt) if (ypdb == NULL) return NULL; memset(ypdb, 0, sizeof *ypdb); - strncpy(ypdb->dom_domain, *argp, sizeof ypdb->dom_domain-1); - ypdb->dom_domain[sizeof ypdb->dom_domain-1] = '\0'; + strlcpy(ypdb->dom_domain, *argp, sizeof ypdb->dom_domain); ypdb->dom_vers = YPVERS; ypdb->dom_alive = 0; ypdb->dom_lockfd = -1; @@ -487,8 +486,7 @@ main(int argc, char *argv[]) if (ypbindlist == NULL) errx(1, "no memory"); memset(ypbindlist, 0, sizeof *ypbindlist); - strncpy(ypbindlist->dom_domain, domain, sizeof ypbindlist->dom_domain-1); - ypbindlist->dom_domain[sizeof (ypbindlist->dom_domain)-1] = '\0'; + strlcpy(ypbindlist->dom_domain, domain, sizeof ypbindlist->dom_domain); ypbindlist->dom_vers = YPVERS; snprintf(ypbindlist->dom_servlist, sizeof ypbindlist->dom_servlist, "%s/%s", SERVERSDIR, ypbindlist->dom_domain); @@ -960,8 +958,7 @@ rpc_received(char *dom, struct sockaddr_in *raddrp, int force) if (ypdb == NULL) return; memset(ypdb, 0, sizeof *ypdb); - strncpy(ypdb->dom_domain, dom, sizeof ypdb->dom_domain-1); - ypdb->dom_domain[sizeof (ypdb->dom_domain)-1] = '\0'; + strlcpy(ypdb->dom_domain, dom, sizeof ypdb->dom_domain); ypdb->dom_lockfd = -1; ypdb->dom_xid = unique_xid(ypdb); ypdb->dom_pnext = ypbindlist;