Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Apr 1996 18:29:55 GMT
From:      James Raynard <jraynard@dial.pipex.com>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   kern/1144: sig{add, del}set and sigismember fns don't check signo
Message-ID:  <199604151829.SAA01603@me>
Resent-Message-ID: <199604152200.PAA11602@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         1144
>Category:       kern
>Synopsis:       sig{add, del}set and sigismember fns don't check signo
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 15 15:00:06 PDT 1996
>Last-Modified:
>Originator:     James Raynard
>Organization:
A FreeBSD Box
>Release:        FreeBSD 2.1-STABLE i386
>Environment:

		FreeBSD-2.1.0-RELEASE


>Description:

	According to Stevens (advanced Programming in the Unix 
	Environment, p. 292), POSIX.1 requires that sigaddset,
	sigdelset and sigismember check the signal number argument
	for validity and set errno if it is invalid. FreeBSD's
	implementation of these functions does not comply with
	this.

>How-To-Repeat:

	Look at /usr/src/lib/libc/gen/sigsetops.c and 
	/usr/include/signal.h.

>Fix:
	
	The following patch to /usr/src/lib/libc/gen/sigsetops.c is 
	based on code given by Stevens to demonstrate how to do this 
	if they are implemented as functions. 

	However, FreeBSD also implements them as macros in 
	/usr/include/signal.h, the function versions only being 
	available if the macros are #undef'd. Obviously the macros 
	would be much harder to fix (are they actually necessary, BTW?)

*** sigsetops.c.old     Mon Apr 15 17:39:46 1996
--- sigsetops.c 	Mon Apr 15 17:54:19 1996
***************
*** 38,43 ****
--- 38,44 ----
#endif /* LIBC_SCCS and not lint */
	    
#include <signal.h>
+ #include <errno.h>
		
#undef sigemptyset
#undef sigfillset
***************
*** 45,50 ****
--- 46,53 ----
#undef sigdelset
#undef sigismember
+ #define SIGBAD(signo) ((signo) <= 0 || (signo) >= NSIG)
+ 
  sigemptyset(set)
         sigset_t *set;
  {
***************
*** 63,68 ****
--- 66,73 ----
        sigset_t *set;
        int signo;
  {
+       if (SIGBAD (signo)) { errno = EINVAL; return (-1); }
+ 
        *set |= sigmask(signo);
        return (0);
  }
***************
*** 71,76 ****
--- 76,83 ----
	sigset_t *set;
	int signo;
  {
+       if (SIGBAD (signo)) { errno = EINVAL; return (-1); }
+ 
	*set &= ~sigmask(signo);
	return (0);
   }
***************
*** 79,83 ****
--- 86,92 ----
        const sigset_t *set;
	int signo;
  {
+       if (SIGBAD (signo)) { errno = EINVAL; return (-1); }
+ 
        return ((*set & ~sigmask(signo)) != 0);
  }

>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199604151829.SAA01603>