From 8b7ab960df02da128c56283ce14b78227ac2d200 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Sun, 15 Jun 2008 10:55:34 +1000 Subject: - (djm) [openbsd-compat/sigact.c] Avoid NULL derefs in ancient sigaction replacement code; patch from ighighi AT gmail.com in bz#1240; ok dtucker --- openbsd-compat/sigact.c | 50 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'openbsd-compat/sigact.c') diff --git a/openbsd-compat/sigact.c b/openbsd-compat/sigact.c index 8b8e4dd2c..d67845cf1 100644 --- a/openbsd-compat/sigact.c +++ b/openbsd-compat/sigact.c @@ -36,6 +36,7 @@ /* OPENBSD ORIGINAL: lib/libcurses/base/sigaction.c */ #include "includes.h" +#include #include #include "sigact.h" @@ -47,28 +48,39 @@ int sigaction(int sig, struct sigaction *sigact, struct sigaction *osigact) { - return sigvec(sig, &(sigact->sv), &(osigact->sv)); + return sigvec(sig, sigact ? &sigact->sv : NULL, + osigact ? &osigact->sv : NULL); } int -sigemptyset (sigset_t * mask) +sigemptyset (sigset_t *mask) { + if (!mask) { + errno = EINVAL; + return -1; + } *mask = 0; return 0; } int -sigprocmask (int mode, sigset_t * mask, sigset_t * omask) +sigprocmask (int mode, sigset_t *mask, sigset_t *omask) { sigset_t current = sigsetmask(0); - if (omask) *omask = current; + if (!mask) { + errno = EINVAL; + return -1; + } - if (mode==SIG_BLOCK) + if (omask) + *omask = current; + + if (mode == SIG_BLOCK) current |= *mask; - else if (mode==SIG_UNBLOCK) + else if (mode == SIG_UNBLOCK) current &= ~*mask; - else if (mode==SIG_SETMASK) + else if (mode == SIG_SETMASK) current = *mask; sigsetmask(current); @@ -76,28 +88,44 @@ sigprocmask (int mode, sigset_t * mask, sigset_t * omask) } int -sigsuspend (sigset_t * mask) +sigsuspend (sigset_t *mask) { + if (!mask) { + errno = EINVAL; + return -1; + } return sigpause(*mask); } int -sigdelset (sigset_t * mask, int sig) +sigdelset (sigset_t *mask, int sig) { + if (!mask) { + errno = EINVAL; + return -1; + } *mask &= ~sigmask(sig); return 0; } int -sigaddset (sigset_t * mask, int sig) +sigaddset (sigset_t *mask, int sig) { + if (!mask) { + errno = EINVAL; + return -1; + } *mask |= sigmask(sig); return 0; } int -sigismember (sigset_t * mask, int sig) +sigismember (sigset_t *mask, int sig) { + if (!mask) { + errno = EINVAL; + return -1; + } return (*mask & sigmask(sig)) != 0; } -- cgit v1.2.3