Skip to content

Commit 30fd872

Browse files
committed
Prevent safe construction of struct sigevent
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.
1 parent 0ee3de5 commit 30fd872

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,12 @@ s_no_extra_traits! {
10811081
pub sigev_signo: ::c_int,
10821082
pub sigev_value: ::sigval,
10831083
pub _sigev_un: __c_anonymous_sigev_un,
1084+
/// Exists just to prevent the struct from being safely constructed,
1085+
/// because the Debug, Hash, PartialImpl, and
1086+
/// Deref<Target=sigevent_0_2_0126> trait impls might read uninitialized
1087+
/// fields of _sigev_un. This field may be removed once those trait
1088+
/// impls are.
1089+
_private: ()
10841090
}
10851091

10861092
pub struct ptsstat {

src/unix/linux_like/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ s_no_extra_traits! {
291291
pub sigev_signo: ::c_int,
292292
pub sigev_notify: ::c_int,
293293
pub _sigev_un: __c_anonymous_sigev_un,
294+
/// Exists just to prevent the struct from being safely constructed,
295+
/// because the Debug, Hash, PartialImpl, and
296+
/// Deref<Target=sigevent_0_2_0126> trait impls might read uninitialized
297+
/// fields of _sigev_un. This field may be removed once those trait
298+
/// impls are.
299+
_private: ()
294300
}
295301
}
296302

0 commit comments

Comments
 (0)