mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-01-31 06:51:11 +01:00
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()
This commit is contained in:
parent
0e82b92a97
commit
94ef3f3115
@ -700,6 +700,7 @@ struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char
|
||||
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 @@ struct sockaddr_storage *str2sa_range(const char *str, int *low, int *high, char
|
||||
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, ':');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user