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:
parent
43936ba0d1
commit
fb0570cc73
1 changed files with 4 additions and 0 deletions
4
socket.c
4
socket.c
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue