@@ -86,13 +86,21 @@ mod imp {
86
86
// out many large systems and all implementations allow returning from a
87
87
// signal handler to work. For a more detailed explanation see the
88
88
// comments on #26458.
89
+ /// SIGSEGV/SIGBUS entry point
90
+ /// # Safety
91
+ /// Rust doesn't call this, it *gets called*.
92
+ #[ forbid( unsafe_op_in_unsafe_fn) ]
89
93
unsafe extern "C" fn signal_handler (
90
94
signum : libc:: c_int ,
91
95
info : * mut libc:: siginfo_t ,
92
96
_data : * mut libc:: c_void ,
93
97
) {
94
98
let ( start, end) = GUARD . get ( ) ;
95
- let addr = ( * info) . si_addr ( ) as usize ;
99
+ if info. is_null ( ) || !info. is_aligned ( ) {
100
+ rtabort ! ( "signal handler passed null/non-aligned siginfo_t ptr" )
101
+ } ;
102
+ // SAFETY: we've done our due diligence, so assume the pointer is to a real siginfo_t
103
+ let addr = unsafe { ( * info) . si_addr ( ) as usize } ;
96
104
97
105
// If the faulting address is within the guard page, then we print a
98
106
// message saying so and abort.
@@ -104,9 +112,11 @@ mod imp {
104
112
rtabort ! ( "stack overflow" ) ;
105
113
} else {
106
114
// Unregister ourselves by reverting back to the default behavior.
107
- let mut action: sigaction = mem:: zeroed ( ) ;
115
+ // SAFETY: assuming all platforms define struct sigaction as "zero-initializable"
116
+ let mut action: sigaction = unsafe { mem:: zeroed ( ) } ;
108
117
action. sa_sigaction = SIG_DFL ;
109
- sigaction ( signum, & action, ptr:: null_mut ( ) ) ;
118
+ // SAFETY: pray this is a well-behaved POSIX implementation of fn sigaction
119
+ unsafe { sigaction ( signum, & action, ptr:: null_mut ( ) ) } ;
110
120
111
121
// See comment above for why this function returns.
112
122
}
0 commit comments