BUILD/MEDIUM: standard: get rid of the last strcpy()
OpenBSD complains about our use of strcpy() in standard.c. The checks
were OK and we didn't fall into the category of "almost always misused",
but it's very simple to fix it so better do it before a problem happens.
src/standard.o(.text+0x26ab): In function `str2sa_range':
src/standard.c:718: warning: strcpy() is almost always misused, please use strlcpy()
diff --git a/src/standard.c b/src/standard.c
index 569ecaa..f4f8b2a 100644
--- a/src/standard.c
+++ b/src/standard.c
@@ -700,6 +700,7 @@
else if (ss.ss_family == AF_UNIX) {
int prefix_path_len;
int max_path_len;
+ int adr_len;
/* complete unix socket path name during startup or soft-restart is
* <unix_bind_prefix><path>.<pid>.<bak|tmp>
@@ -708,18 +709,15 @@
max_path_len = (sizeof(((struct sockaddr_un *)&ss)->sun_path) - 1) -
(prefix_path_len ? prefix_path_len + 1 + 5 + 1 + 3 : 0);
- if (strlen(str2) > max_path_len) {
+ adr_len = strlen(str2);
+ if (adr_len > max_path_len) {
memprintf(err, "socket path '%s' too long (max %d)\n", str, max_path_len);
goto out;
}
- if (pfx) {
+ if (prefix_path_len)
memcpy(((struct sockaddr_un *)&ss)->sun_path, pfx, prefix_path_len);
- strcpy(((struct sockaddr_un *)&ss)->sun_path + prefix_path_len, str2);
- }
- else {
- strcpy(((struct sockaddr_un *)&ss)->sun_path, str2);
- }
+ memcpy(((struct sockaddr_un *)&ss)->sun_path + prefix_path_len, str2, adr_len + 1);
}
else { /* IPv4 and IPv6 */
port1 = strrchr(str2, ':');