Skip to content

Commit fddcb84

Browse files
authored
Merge pull request #164 from malahal/strlcpy
Convert unsafe strncpy to strlcpy
2 parents 929c9da + 0104cd1 commit fddcb84

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/clnt_perror.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ rpc_sperror(const struct rpc_err *e, const char *s)
7272
len -= i;
7373
}
7474

75-
(void)strncpy(str, clnt_sperrno(e->re_status), len - 1);
75+
(void)strlcpy(str, clnt_sperrno(e->re_status), len);
7676
i = strlen(str);
7777
str += i;
7878
len -= i;

src/netnamer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ int netname2host(char netname[MAXNETNAMELEN + 1], char *hostname, int hostlen)
190190
if (getnetid(netname, valbuf)) {
191191
val = valbuf;
192192
if ((*val == '0') && (val[1] == ':')) {
193-
(void)strncpy(hostname, val + 2, hostlen);
193+
(void)strlcpy(hostname, val + 2, hostlen);
194194
return (1);
195195
}
196196
}

src/rpc_generic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ __rpc_uaddr2taddr_af(int af, const char *uaddr)
957957
sun = (struct sockaddr_un *)mem_zalloc(sizeof(*sun));
958958

959959
sun->sun_family = AF_LOCAL;
960-
strncpy(sun->sun_path, addrstr, sizeof(sun->sun_path) - 1);
960+
strlcpy(sun->sun_path, addrstr, sizeof(sun->sun_path));
961961
ret->len = SUN_LEN(sun);
962962
ret->maxlen = sizeof(struct sockaddr_un);
963963
ret->buf = sun;

src/rpcb_clnt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static CLIENT *getclnthandle(const char *host, const struct netconfig *nconf,
338338

339339
if (targaddr) {
340340
*targaddr = mem_zalloc(sizeof(sun.sun_path));
341-
strncpy(*targaddr, _PATH_RPCBINDSOCK,
341+
strlcpy(*targaddr, _PATH_RPCBINDSOCK,
342342
sizeof(sun.sun_path));
343343
}
344344
return (client);
@@ -598,7 +598,7 @@ __rpcbind_is_up(void)
598598
if (sock < 0)
599599
return (false);
600600
sun.sun_family = AF_LOCAL;
601-
strncpy(sun.sun_path, _PATH_RPCBINDSOCK, sizeof(sun.sun_path));
601+
strlcpy(sun.sun_path, _PATH_RPCBINDSOCK, sizeof(sun.sun_path));
602602

603603
if (connect(sock, (struct sockaddr *)&sun, sizeof(sun)) < 0) {
604604
close(sock);

0 commit comments

Comments
 (0)