socket: zero sockaddr_un to initialize sa_len

Zero the whole sockaddr struct before calling bind() and connect() to
initialize the FreeBSD-specific sa_len field.

This fixes errors reported by valgrind.
This commit is contained in:
Miroslav Lichvar 2021-12-16 10:41:31 +01:00
parent 43936ba0d1
commit fb0570cc73

View file

@ -505,6 +505,8 @@ bind_unix_address(int sock_fd, const char *addr, int flags)
{ {
union sockaddr_all saddr; union sockaddr_all saddr;
memset(&saddr, 0, sizeof (saddr));
if (snprintf(saddr.un.sun_path, sizeof (saddr.un.sun_path), "%s", addr) >= if (snprintf(saddr.un.sun_path, sizeof (saddr.un.sun_path), "%s", addr) >=
sizeof (saddr.un.sun_path)) { sizeof (saddr.un.sun_path)) {
DEBUG_LOG("Unix socket path %s too long", addr); DEBUG_LOG("Unix socket path %s too long", addr);
@ -537,6 +539,8 @@ connect_unix_address(int sock_fd, const char *addr)
{ {
union sockaddr_all saddr; union sockaddr_all saddr;
memset(&saddr, 0, sizeof (saddr));
if (snprintf(saddr.un.sun_path, sizeof (saddr.un.sun_path), "%s", addr) >= if (snprintf(saddr.un.sun_path, sizeof (saddr.un.sun_path), "%s", addr) >=
sizeof (saddr.un.sun_path)) { sizeof (saddr.un.sun_path)) {
DEBUG_LOG("Unix socket path %s too long", addr); DEBUG_LOG("Unix socket path %s too long", addr);