Re: _FORTIFY_SOURCE=3 causes latest Samba builds to core dump...
Peter Eriksson <[email protected]>
| Newsgroups | gmane.os.freebsd.devel.hackers |
|---|---|
| Message-ID | <[email protected]> |
Looking at this a bit more at least one of my core dumps are “fun” :-). It core dumps on recvfrom() in samba:
The reason for the crash in recvfrom() is that on FreeBSD the 'struct sockaddr' definition is the old classical one:
struct sockaddr {
unsigned char sa_len; /* total length */
sa_family_t sa_family; /* address family */
char sa_data[14]; /* actually longer; address value */
};
whereas Linux uses:
struct sockaddr {
sa_family_t sa_family; /* address family, AF_xxx */
union {
char sa_data_min[14]; /* Minimum 14 bytes of protocol address */
DECLARE_FLEX_ARRAY(char, sa_data);
};
};
and the code in lib/tsocket/tsocket_bsd.c:tdgram_bsd_recvfrom_handler() uses:
ZERO_STRUCTP(bsda);
bsda->sa_socklen = sizeof(bsda->u.ss);
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
bsda->u.sa.sa_len = bsda->sa_socklen;
#endif
ret = recvfrom(bsds->fd, state->buf, state->len, 0,
&bsda->u.sa, &bsda->sa_socklen);
and thus it will fail due to sizeof(bsda->u.sa <http://u.sa/>) < bsda->sa_socklen...
One could probably fix this by addding a 'char dummy[]' array to the definition of struct sockaddr in BSD's header files similar to the Linux one (probably).
Or patch Samba to use (struct sockaddr *) &bsda->u.ss instead of ->u.sa (and find all other similar cases in the code) probably...
Hmm.. :-)
- Peter
> On 24 Apr 2026, at 17:00, Peter Eriksson <[email protected]> wrote:
>
> Which isn’t so surprising since it seems that FreeBSD’s own implementation (ssp) doesn’t support _FORTIFY_SOURCE=3.
>
> Are there any plans of updating this that anyone know of?
>
> (For others attempting to build Samba 4.24.1 och 4.23.7 - just edit buildtools/wafsamba/samba_autoconf and change 3 to 1)
>
> - Peter
>
>