@@ -2287,33 +2287,35 @@ int sigaction_impl(int sig, const __sanitizer_sigaction *act,
2287
2287
SCOPED_INTERCEPTOR_RAW (sigaction , sig, act, old);
2288
2288
__sanitizer_sigaction *sigactions = interceptor_ctx ()->sigactions ;
2289
2289
__sanitizer_sigaction old_stored;
2290
- internal_memcpy (&old_stored, &sigactions[sig], sizeof (old_stored));
2291
- if (act == 0 ) return 0 ;
2292
- // Copy act into sigactions[sig].
2293
- // Can't use struct copy, because compiler can emit call to memcpy.
2294
- // Can't use internal_memcpy, because it copies byte-by-byte,
2295
- // and signal handler reads the handler concurrently. It it can read
2296
- // some bytes from old value and some bytes from new value.
2297
- // Use volatile to prevent insertion of memcpy.
2298
- sigactions[sig].handler =
2299
- *(volatile __sanitizer_sighandler_ptr const *)&act->handler ;
2300
- sigactions[sig].sa_flags = *(volatile int const *)&act->sa_flags ;
2301
- internal_memcpy (&sigactions[sig].sa_mask , &act->sa_mask ,
2302
- sizeof (sigactions[sig].sa_mask ));
2303
- #if !SANITIZER_FREEBSD && !SANITIZER_MAC && !SANITIZER_NETBSD
2304
- sigactions[sig].sa_restorer = act->sa_restorer ;
2305
- #endif
2290
+ if (old) internal_memcpy (&old_stored, &sigactions[sig], sizeof (old_stored));
2306
2291
__sanitizer_sigaction newact;
2307
- internal_memcpy (&newact, act, sizeof (newact));
2308
- internal_sigfillset (&newact.sa_mask );
2309
- if ((uptr)act->handler != sig_ign && (uptr)act->handler != sig_dfl) {
2310
- if (newact.sa_flags & SA_SIGINFO)
2311
- newact.sigaction = rtl_sigaction;
2312
- else
2313
- newact.handler = rtl_sighandler;
2292
+ if (act) {
2293
+ // Copy act into sigactions[sig].
2294
+ // Can't use struct copy, because compiler can emit call to memcpy.
2295
+ // Can't use internal_memcpy, because it copies byte-by-byte,
2296
+ // and signal handler reads the handler concurrently. It it can read
2297
+ // some bytes from old value and some bytes from new value.
2298
+ // Use volatile to prevent insertion of memcpy.
2299
+ sigactions[sig].handler =
2300
+ *(volatile __sanitizer_sighandler_ptr const *)&act->handler ;
2301
+ sigactions[sig].sa_flags = *(volatile int const *)&act->sa_flags ;
2302
+ internal_memcpy (&sigactions[sig].sa_mask , &act->sa_mask ,
2303
+ sizeof (sigactions[sig].sa_mask ));
2304
+ #if !SANITIZER_FREEBSD && !SANITIZER_MAC && !SANITIZER_NETBSD
2305
+ sigactions[sig].sa_restorer = act->sa_restorer ;
2306
+ #endif
2307
+ internal_memcpy (&newact, act, sizeof (newact));
2308
+ internal_sigfillset (&newact.sa_mask );
2309
+ if ((uptr)act->handler != sig_ign && (uptr)act->handler != sig_dfl) {
2310
+ if (newact.sa_flags & SA_SIGINFO)
2311
+ newact.sigaction = rtl_sigaction;
2312
+ else
2313
+ newact.handler = rtl_sighandler;
2314
+ }
2315
+ ReleaseStore (thr, pc, (uptr)&sigactions[sig]);
2316
+ act = &newact;
2314
2317
}
2315
- ReleaseStore (thr, pc, (uptr)&sigactions[sig]);
2316
- int res = REAL (sigaction )(sig, &newact, old);
2318
+ int res = REAL (sigaction )(sig, act, old);
2317
2319
if (res == 0 && old) {
2318
2320
uptr cb = (uptr)old->sigaction ;
2319
2321
if (cb == (uptr)rtl_sigaction || cb == (uptr)rtl_sighandler) {
0 commit comments