mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-22 17:08:53 +02:00
Fix various strict aliasing problems with sockaddr
Fix various strict aliasing problems caused by casting between (struct sockaddr *) and (struct sockaddr_storage *): the correct code here is to keep the two in a union. Signed-off-by: Philip Withnall <withnall@endlessm.com> https://bugzilla.gnome.org/show_bug.cgi?id=791622
This commit is contained in:
@@ -2167,12 +2167,15 @@ g_log_writer_is_journald (gint output_fd)
|
||||
|
||||
if (g_once_init_enter (&initialized))
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
union {
|
||||
struct sockaddr_storage storage;
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_un un;
|
||||
} addr;
|
||||
socklen_t addr_len = sizeof(addr);
|
||||
int err = getpeername (output_fd, (struct sockaddr *) &addr, &addr_len);
|
||||
if (err == 0 && addr.ss_family == AF_UNIX)
|
||||
fd_is_journal = g_str_has_prefix (((struct sockaddr_un *)&addr)->sun_path,
|
||||
"/run/systemd/journal/");
|
||||
int err = getpeername (output_fd, &addr.sa, &addr_len);
|
||||
if (err == 0 && addr.storage.ss_family == AF_UNIX)
|
||||
fd_is_journal = g_str_has_prefix (addr.un.sun_path, "/run/systemd/journal/");
|
||||
|
||||
g_once_init_leave (&initialized, TRUE);
|
||||
}
|
||||
|
Reference in New Issue
Block a user