• Simon McVittie's avatar
    sysdeps: Reassure gcc 8 that we are not overflowing struct sockaddr_un · cfdfcac5
    Simon McVittie authored
    Using strncpy (buffer, str, strlen (str)) is a "code smell" that
    might indicate a serious bug (it effectively turns strncpy into
    strcpy), and gcc 8 now warns about it. In fact we avoided the bug
    here, but it wasn't at all obvious.
    
    We already checked that path_len is less than or equal to
    _DBUS_MAX_SUN_PATH_LENGTH, which is 99, chosen to be strictly less
    than the POSIX minimum sizeof(sun_path) >= 100, so we couldn't
    actually be overflowing the available buffer.
    
    The new static assertion in this commit matches a comment above the
    definition of _DBUS_MAX_SUN_PATH_LENGTH: we define
    _DBUS_MAX_SUN_PATH_LENGTH to 99, because POSIX says struct
    sockaddr_un's sun_path member is at least 100 bytes (including space
    for a \0 terminator). dbus will now fail to compile on
    platforms that are non-POSIX-compliant in this way, except for Windows.
    
    We zeroed the struct sockaddr_un before writing into it, so stopping
    one byte short of the end of sun_path ensures that we get \0
    termination.
    Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
    Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107350Reviewed-by: Thiago Macieira's avatarThiago Macieira <thiago@kde.org>
    Reviewed-by: Philip Withnall's avatarPhilip Withnall <withnall@endlessm.com>
    (cherry picked from commit f4296313)
    cfdfcac5
Name
Last commit
Last update
bus Loading commit data...
cmake Loading commit data...
dbus Loading commit data...
doc Loading commit data...
m4 Loading commit data...
test Loading commit data...
tools Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
AUTHORS Loading commit data...
COPYING Loading commit data...
ChangeLog Loading commit data...
ChangeLog.pre-1-0 Loading commit data...
ChangeLog.pre-1-2 Loading commit data...
Doxyfile.in Loading commit data...
HACKING Loading commit data...
INSTALL Loading commit data...
Makefile.am Loading commit data...
Makefile.cvs Loading commit data...
NEWS Loading commit data...
NEWS.pre-1-0 Loading commit data...
NEWS.pre-1-2 Loading commit data...
README Loading commit data...
README.cmake Loading commit data...
README.cygwin Loading commit data...
README.launchd Loading commit data...
README.valgrind Loading commit data...
README.win Loading commit data...
README.wince Loading commit data...
autogen.sh Loading commit data...
cleanup-man-pages.sh Loading commit data...
configure.ac Loading commit data...
dbus-1-uninstalled.pc.in Loading commit data...
dbus-1.pc.in Loading commit data...