From: David van Moolenbroek Date: Sat, 28 Nov 2009 13:20:50 +0000 (+0000) Subject: fix _NSIG usage X-Git-Tag: v3.1.6~189 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/named.html?a=commitdiff_plain;h=6da61b8f053bdbc30f8b621709077ae504f5876b;p=minix.git fix _NSIG usage --- diff --git a/commands/sh/sh3.c b/commands/sh/sh3.c index 80df511d3..cdba82b58 100644 --- a/commands/sh/sh3.c +++ b/commands/sh/sh3.c @@ -854,7 +854,7 @@ register struct op *t; register int resetsig; if (t->words[1] == NULL) { - for (i=0; i<=_NSIG; i++) + for (i=0; i<_NSIG; i++) if (trap[i]) { prn(i); prs(": "); @@ -894,7 +894,7 @@ char *s; { register int n; - if ((n = getn(s)) < 0 || n > _NSIG) { + if ((n = getn(s)) < 0 || n >= _NSIG) { err("trap: bad signal number"); n = 0; } diff --git a/commands/sh/sh4.c b/commands/sh/sh4.c index 2603abbd6..4fe04df73 100644 --- a/commands/sh/sh4.c +++ b/commands/sh/sh4.c @@ -387,7 +387,7 @@ int quoted; } *e.linep = 0; /* allow trapped signals */ - for (i=0; i<=_NSIG; i++) + for (i=0; i<_NSIG; i++) if (ourtrap[i] && signal(i, SIG_IGN) != SIG_IGN) signal(i, SIG_DFL); dup2(pf[1], 1); diff --git a/commands/simple/kill.c b/commands/simple/kill.c index 7f25e4eef..354287f87 100644 --- a/commands/simple/kill.c +++ b/commands/simple/kill.c @@ -69,7 +69,7 @@ char **argv; } if (sig < 0) { /* numeric? */ ul = strtoul(argv[1] + 1, &end, 10); - if (end == argv[1] + 1 || *end != 0 || ul > _NSIG) usage(); + if (end == argv[1] + 1 || *end != 0 || ul >= _NSIG) usage(); sig = ul; } argv++; diff --git a/commands/simple/login.c b/commands/simple/login.c index c5cf560ca..1eed3ae37 100644 --- a/commands/simple/login.c +++ b/commands/simple/login.c @@ -445,7 +445,7 @@ char *argv[]; /* Reset signals to default values. */ sa.sa_handler = SIG_DFL; - for (n = 1; n <= _NSIG; ++n) sigaction(n, &sa, NULL); + for (n = 1; n < _NSIG; ++n) sigaction(n, &sa, NULL); /* Execute the user's shell. */ execve(sh, argx, env); diff --git a/kernel/system.c b/kernel/system.c index e0ee6fbd5..b949ac2db 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -336,7 +336,7 @@ PUBLIC void send_sig(int proc_nr, int sig_nr) *===========================================================================*/ PUBLIC void cause_sig(proc_nr, sig_nr) int proc_nr; /* process to be signalled */ -int sig_nr; /* signal to be sent, 1 to _NSIG */ +int sig_nr; /* signal to be sent */ { /* A system process wants to send a signal to a process. Examples are: * - HARDWARE wanting to cause a SIGSEGV after a CPU exception diff --git a/kernel/system/do_kill.c b/kernel/system/do_kill.c index f5d1d8685..118a53773 100644 --- a/kernel/system/do_kill.c +++ b/kernel/system/do_kill.c @@ -32,7 +32,7 @@ message *m_ptr; /* pointer to request message */ proc_nr_e= m_ptr->SIG_ENDPT; if (!isokendpt(proc_nr_e, &proc_nr)) return(EINVAL); - if (sig_nr > _NSIG) return(EINVAL); + if (sig_nr >= _NSIG) return(EINVAL); if (iskerneln(proc_nr)) return(EPERM); /* Set pending signal to be processed by the PM. */ diff --git a/lib/ansi/raise.c b/lib/ansi/raise.c index fb444291a..a7e951c6e 100644 --- a/lib/ansi/raise.c +++ b/lib/ansi/raise.c @@ -15,7 +15,7 @@ pid_t _getpid(void); int raise(int sig) { - if (sig < 0 || sig > _NSIG) + if (sig < 0 || sig >= _NSIG) return -1; return _kill(_getpid(), sig); } diff --git a/lib/ansi/signal.c b/lib/ansi/signal.c index bae9b5290..ff476e0b9 100644 --- a/lib/ansi/signal.c +++ b/lib/ansi/signal.c @@ -11,7 +11,7 @@ sighandler_t disp; /* signal handler, or SIG_DFL, or SIG_IGN */ { struct sigaction sa, osa; - if (sig <= 0 || sig > _NSIG || sig == SIGKILL) { + if (sig <= 0 || sig >= _NSIG || sig == SIGKILL) { errno = EINVAL; return(SIG_ERR); } diff --git a/lib/posix/_sigset.c b/lib/posix/_sigset.c index 91226de5f..a1813cf93 100644 --- a/lib/posix/_sigset.c +++ b/lib/posix/_sigset.c @@ -2,6 +2,8 @@ /* System processes use simpler macros with no range error checking (defined in * signal.h). The ANSI signal() implementation now also uses the macro * versions, which makes hiding of the functions here a historical remains. + * + * _NSIG is supposed to be the highest signal number plus one. */ #define sigaddset _sigaddset #define sigdelset _sigdelset @@ -13,10 +15,10 @@ /* Low bit of signal masks. */ #define SIGBIT_0 ((sigset_t) 1) -/* Mask of valid signals (0 - _NSIG). */ -#define SIGMASK (((SIGBIT_0 << _NSIG) << 1) - 1) +/* Mask of valid signals (0 - (_NSIG-1)). */ +#define SIGMASK ((SIGBIT_0 << _NSIG) - 1) -#define sigisvalid(signo) ((unsigned) (signo) <= _NSIG) +#define sigisvalid(signo) ((unsigned) (signo) < _NSIG) PUBLIC int sigaddset(set, signo) sigset_t *set; diff --git a/test/test37.c b/test/test37.c index d6e5c6f28..0193db288 100644 --- a/test/test37.c +++ b/test/test37.c @@ -238,10 +238,8 @@ void test37b() if (sigdelset(&s_nokill, SIGKILL) != 0) e(8); s_nokill_stop = s_nokill; if (sigdelset(&s_nokill_stop, SIGSTOP) != 0) e(8); -#ifndef _MINIX /* XXX - should unsupported signals be <= _NSIG? */ - if (SIGSTOP > _NSIG) e(666); - if (SIGSTOP <= _NSIG && sigdelset(&s_nokill, SIGSTOP) != 0) e(888); -#endif /* _MINIX */ + if (SIGSTOP >= _NSIG) e(666); + if (SIGSTOP < _NSIG && sigdelset(&s_nokill, SIGSTOP) != 0) e(888); /* Now get most of the signals into default state. Don't change SIGINT * or SIGQUIT, so this program can be killed. SIGKILL is also special. @@ -427,7 +425,7 @@ void test37c() if (signal(SIGINT, catch1) != SIG_DFL) e(11); /* Verify that SIG_ERR is correctly generated. */ - if (signal(_NSIG + 1, catch1) != SIG_ERR) e(12); + if (signal(_NSIG, catch1) != SIG_ERR) e(12); if (signal(0, catch1) != SIG_ERR) e(13); if (signal(-1, SIG_DFL) != SIG_ERR) e(14); @@ -987,8 +985,8 @@ void clearsigstate() sigset_t sigset_var; /* Clear the signal state. */ - for (i = 1; i <= _NSIG; i++) signal(i, SIG_IGN); - for (i = 1; i <= _NSIG; i++) signal(i, SIG_DFL); + for (i = 1; i < _NSIG; i++) signal(i, SIG_IGN); + for (i = 1; i < _NSIG; i++) signal(i, SIG_DFL); sigfillset(&sigset_var); sigprocmask(SIG_UNBLOCK, &sigset_var, (sigset_t *)NULL); }