Skip to content

Commit

Permalink
Prevent safe construction of struct sigevent
Browse files Browse the repository at this point in the history
sigevent's Debug, PartialEq, and Hash trait impls might read union
fields that could be potentially uninitialized by a standard
initializer.  Those trait impls shouldn't be present (see
rust-lang#2816), but can't easily be
removed.  Until they get removed, the constructor must be `unsafe` to
force the user to zero all fields.

The same issue applies to the Deref<Target=sigevent_0_2_126> trait impl,
which exists only for backwards compatibility.
  • Loading branch information
asomers committed Aug 11, 2023
1 parent 18c0186 commit dbca3cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Expand Up @@ -1410,6 +1410,12 @@ s_no_extra_traits! {
pub sigev_signo: ::c_int,
pub sigev_value: ::sigval,
pub _sigev_un: __c_anonymous_sigev_un,
/// Exists just to prevent the struct from being safely constructed,
/// because the Debug, Hash, PartialImpl, and
/// Deref<Target=sigevent_0_2_0126> trait impls might read uninitialized
/// fields of _sigev_un. This field may be removed once those trait
/// impls are.
_private: ()
}

pub struct ptsstat {
Expand Down
6 changes: 6 additions & 0 deletions src/unix/linux_like/mod.rs
Expand Up @@ -291,6 +291,12 @@ s_no_extra_traits! {
pub sigev_signo: ::c_int,
pub sigev_notify: ::c_int,
pub _sigev_un: __c_anonymous_sigev_un,
/// Exists just to prevent the struct from being safely constructed,
/// because the Debug, Hash, PartialImpl, and
/// Deref<Target=sigevent_0_2_0126> trait impls might read uninitialized
/// fields of _sigev_un. This field may be removed once those trait
/// impls are.
_private: ()
}
}

Expand Down

0 comments on commit dbca3cc

Please sign in to comment.