rspamd_inet_addr_t *addr;
g_assert (sa != NULL);
- g_assert (slen >= sizeof (struct sockaddr));
+ /* Address of an AF_UNIX socket can be tiny */
+ g_assert (slen >= sizeof (sa_family_t) + 1);
addr = rspamd_inet_addr_create (sa->sa_family, NULL);
const struct sockaddr_un *un = (const struct sockaddr_un *)sa;
g_assert (slen >= SUN_LEN (un));
+ g_assert (slen <= sizeof (addr->u.un->addr));
- rspamd_strlcpy (addr->u.un->addr.sun_path, un->sun_path,
- sizeof (addr->u.un->addr.sun_path));
-#if defined(FREEBSD) || defined(__APPLE__)
- addr->u.un->addr.sun_len = un->sun_len;
-#endif
+ /* sun_path can legally contain intermittent NULL bytes */
+ memcpy (&addr->u.un->addr, un, slen);
+
+ /* length of AF_UNIX addresses is variable */
+ addr->slen = slen;
}
else if (sa->sa_family == AF_INET) {
g_assert (slen >= sizeof (struct sockaddr_in));