Subject: standards/3182: waitpid(2) and friends silently ignore invalid `options' values
To: None <gnats-bugs@gnats.netbsd.org>
From: Klaus Klein <kleink@layla.inka.de>
List: netbsd-bugs
Date: 02/02/1997 12:24:27
>Number:         3182
>Category:       standards
>Synopsis:       waitpid(2) and friends silently ignore invalid `options' values
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Feb  2 03:35:00 1997
>Last-Modified:
>Originator:     Klaus Klein
>Organization:
private site
>Release:        970201
>Environment:
System: NetBSD quesera.inka.de 1.2C NetBSD 1.2C (QUESERA) #72: Sun Feb 2 11:27:39 CET 1997 kleink@quesera.inka.de:/usr/src/sys/arch/hp300/compile/QUESERA hp300


>Description:
Given an invalid value as `options' parameter (i.e. 4), waitpid(2), wait4(2)
and wait3(2) do not return with EINVAL set; they just check for "known"
bits set and silently ignore invalid ones.

Though I do not have the POSIX specs for waitpid() at hand to look this up,
I'm under the impression that this is a spec violation, as
  i) commercial/"compliant" implementations I've checked do return EINVAL
 ii) NIST-PCTS:151-2 requires an "options" value to be specified
     upon which EINVAL will be returned

I have no idea why this check is #ifdef'ed out in kern_exit.c:wait4();
apparently it's been so at least since lite2.

>How-To-Repeat:
_Try_ to figure out a value for EINVAL_WAITPID in NIST-PCTS:151-2. :-)

>Fix:

Index: src/lib/libc/sys/wait.2
===================================================================
RCS file: /cvsroot/netbsd/src/lib/libc/sys/wait.2,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.1
diff -b -c -r1.1.1.1 -r1.1.1.1.2.1
*** wait.2	1996/12/20 13:21:14	1.1.1.1
--- wait.2	1997/02/02 02:15:16	1.1.1.1.2.1
***************
*** 272,277 ****
--- 272,289 ----
  .Dv SA_RESTART
  flag set.
  .El
+ .Pp
+ Additionally,
+ .Fn wait4 ,
+ .Fn wait3
+ and
+ .Fn waitpid
+ will fail and return immediately if:
+ .Bl -tag -width Er
+ .It Bq Er EINVAL
+ An invalid value was specified for
+ .Fa options .
+ .El
  .Sh STANDARDS
  The
  .Fn wait
Index: src/sys/kern/kern_exit.c
===================================================================
RCS file: /cvsroot/netbsd/src/sys/kern/kern_exit.c,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.2
diff -b -c -r1.1.1.1 -r1.1.1.1.2.2
*** kern_exit.c	1996/12/20 13:28:34	1.1.1.1
--- kern_exit.c	1997/02/02 09:48:48	1.1.1.1.2.2
***************
*** 296,305 ****
  
  	if (SCARG(uap, pid) == 0)
  		SCARG(uap, pid) = -q->p_pgid;
- #ifdef notyet
  	if (SCARG(uap, options) &~ (WUNTRACED|WNOHANG))
  		return (EINVAL);
! #endif
  loop:
  	nfound = 0;
  	for (p = q->p_children.lh_first; p != 0; p = p->p_sibling.le_next) {
--- 296,304 ----
  
  	if (SCARG(uap, pid) == 0)
  		SCARG(uap, pid) = -q->p_pgid;
  	if (SCARG(uap, options) &~ (WUNTRACED|WNOHANG))
  		return (EINVAL);
! 
  loop:
  	nfound = 0;
  	for (p = q->p_children.lh_first; p != 0; p = p->p_sibling.le_next) {
>Audit-Trail:
>Unformatted: