cmdmon: fix handling of packets from unbound Unix sockets

When a packet is received from an unbound Unix domain socket, recvfrom()
may return with zero addrlen.
This commit is contained in:
Miroslav Lichvar 2015-08-19 15:52:36 +02:00
parent 794a1e6cfe
commit b7a4b84f0a

View file

@ -1558,8 +1558,11 @@ read_from_cmd_socket(void *anything)
return; return;
} }
if (from_length > sizeof (where_from)) if (from_length > sizeof (where_from) ||
LOG_FATAL(LOGF_CmdMon, "Truncated source address"); from_length <= sizeof (where_from.sa.sa_family)) {
DEBUG_LOG(LOGF_CmdMon, "Read command packet without source address");
return;
}
read_length = status; read_length = status;
@ -1582,11 +1585,9 @@ read_from_cmd_socket(void *anything)
break; break;
#endif #endif
case IPADDR_UNSPEC: case IPADDR_UNSPEC:
/* Unix domain socket */ /* This should be the Unix domain socket */
if (where_from.sa.sa_family != AF_UNIX) { if (where_from.sa.sa_family != AF_UNIX)
DEBUG_LOG(LOGF_CmdMon, "Read command packet with no address");
return; return;
}
assert(sock_fd == sock_fdu); assert(sock_fd == sock_fdu);
localhost = 1; localhost = 1;
break; break;