--- sysdep/bsd/krt-sock.c 2021-03-21 22:29:42 UTC +++ sysdep/bsd/krt-sock.c @@ -6,6 +6,7 @@ * Can be freely distributed and used under the terms of the GNU GPL. */ +#include #include #include #include @@ -189,7 +189,17 @@ struct ks_msg static inline void sockaddr_fill_dl(struct sockaddr_dl *sa, struct iface *ifa) { - uint len = OFFSETOF(struct sockaddr_dl, sdl_data); + /* The original code does not work on FreeBSD 13.0. The kernel checks + if the passed struct is properly initialized. It checks that len is at + least as large as sizeof(sockaddr_dl_short). Unfortunately, + sockaddr_dl_short is not defined in the user space header file. + + Also note that the caller only ever allocates `sizeof(struct sockaddr*)` + for the `struct sockaddr_dl*` parameter, but sockaddr_dl is potentially + much bigger. */ + // uint len = OFFSETOF(struct sockaddr_dl, sdl_data); // buggy + static_assert(sizeof(struct sockaddr) <= sizeof(struct sockaddr_dl)); + uint len = sizeof(struct sockaddr); memset(sa, 0, len); sa->sdl_len = len; sa->sdl_family = AF_LINK;