Subject: standards/3395: setpgid(2) does not return EINVAL upon pgrp < 0
To: None <gnats-bugs@gnats.netbsd.org>
From: Klaus Klein <kleink@layla.inka.de>
List: netbsd-bugs
Date: 03/26/1997 15:11:50
>Number:         3395
>Category:       standards
>Synopsis:       setpgid(2) does not return EINVAL upon pgrp < 0
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 26 10:05:01 1997
>Last-Modified:
>Originator:     Klaus Klein
>Organization:
private site
>Release:        970325
>Environment:
[mi]

>Description:
IEEE Std 1003.1-1988 section 4.3.3.4 (setpgid(2), Errors) states
that setpgid() shall fail with

 [EINVAL]	The value of the pgid argument is less than zero [...]

Also, document this.

>How-To-Repeat:

>Fix:

Index: lib/libc/sys/setpgid.2
===================================================================
RCS file: /cvsroot/netbsd/src/lib/libc/sys/setpgid.2,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.3
diff -b -c -r1.1.1.1 -r1.1.1.1.2.3
*** setpgid.2	1996/12/20 13:21:12	1.1.1.1
--- setpgid.2	1997/03/26 14:08:41	1.1.1.1.2.3
***************
*** 74,79 ****
--- 74,83 ----
  .Fa pid
  argument matches the process ID of a child process of the calling process, 
  and the child process has successfully executed one of the exec functions.
+ .It Bq Er EINVAL
+ The value of the
+ .Fa pgrp
+ argument is less than zero.
  .It Bq Er EPERM
  The effective user ID of the requested process is different
  from that of the caller and the process is not a descendant
Index: sys/kern/kern_prot.c
===================================================================
RCS file: /cvsroot/netbsd/src/sys/kern/kern_prot.c,v
retrieving revision 1.1.1.2
retrieving revision 1.1.1.2.2.3
diff -b -c -r1.1.1.2 -r1.1.1.2.2.3
*** kern_prot.c	1996/12/29 23:33:25	1.1.1.2
--- kern_prot.c	1997/02/07 11:37:27	1.1.1.2.2.3
***************
*** 226,231 ****
--- 226,232 ----
   *
   * caller does setpgid(targpid, targpgid)
   *
+  * pgid must be in valid range (EINVAL) 
   * pid must be caller or child of caller (ESRCH)
   * if a child
   *	pid must be in same session (EPERM)
***************
*** 252,257 ****
--- 253,261 ----
  	SCARG(uap, pid)  = (short) SCARG(uap, pid);		/* XXX */
  	SCARG(uap, pgid) = (short) SCARG(uap, pgid);		/* XXX */
  #endif
+ 
+ 	if (SCARG(uap, pgid) < 0)
+ 		return (EINVAL);
  
  	if (SCARG(uap, pid) != 0 && SCARG(uap, pid) != curp->p_pid) {
  		if ((targp = pfind(SCARG(uap, pid))) == 0 || !inferior(targp))
>Audit-Trail:
>Unformatted: