From marcs@alive.znep.com  Sat Nov  7 22:03:44 1998
Received: from alive.znep.com (207-178-54-226.go2net.com [207.178.54.226])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id WAA05030
          for <FreeBSD-gnats-submit@freebsd.org>; Sat, 7 Nov 1998 22:03:42 -0800 (PST)
          (envelope-from marcs@alive.znep.com)
Received: (from marcs@localhost)
	by alive.znep.com (8.9.1/8.9.1) id VAA04518;
	Sat, 7 Nov 1998 21:59:35 -0800 (PST)
	(envelope-from marcs)
Message-Id: <199811080559.VAA04518@alive.znep.com>
Date: Sat, 7 Nov 1998 21:59:35 -0800 (PST)
From: marcs@znep.com
Reply-To: marcs@znep.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: poll(2) sets POLLNVAL for negative descriptors
X-Send-Pr-Version: 3.2

>Number:         8599
>Category:       kern
>Synopsis:       poll(2) sets POLLNVAL for negative descriptors
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov  7 22:10:00 PST 1998
>Closed-Date:    Wed Dec 9 17:51:20 PST 1998
>Last-Modified:  Wed Dec  9 17:54:05 PST 1998
>Originator:     Marc Slemko
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
>Environment:


FreeBSD alive.znep.com 3.0-CURRENT FreeBSD 3.0-CURRENT #8: Sat Nov  7 21:26:59 PST 1998     marcs@alive.znep.com:/usr/src/sys/compile/ALIVE  i386

3.0-current as of a few days ago.

>Description:

poll(2) sets POLLNVAL for descriptors passed in that are less than
0.  This makes it difficult to do efficient manipulation of the 
struct pollfd since you can't leave a slot empty.

>How-To-Repeat:

Set fds[n].fd = -1 and do a poll on it.  It treats it as an 
POLLNVAL when it should ignore it.

>Fix:

I have no idea why fds->fd was being cast to a u_int.

Index: sys_generic.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/sys_generic.c,v
retrieving revision 1.41
diff -u -r1.41 sys_generic.c
--- sys_generic.c	1998/09/05 14:30:11	1.41
+++ sys_generic.c	1998/11/08 05:26:43
@@ -793,9 +793,11 @@
 	int n = 0;
 
 	for (i = 0; i < nfd; i++, fds++) {
-		if ((u_int)fds->fd >= fdp->fd_nfiles) {
+		if (fds->fd >= fdp->fd_nfiles) {
 			fds->revents = POLLNVAL;
 			n++;
+		} else if (fds->fd < 0) {
+			fds->revents = 0;
 		} else {
 			fp = fdp->fd_ofiles[fds->fd];
 			if (fp == 0) {
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: jkh 
State-Changed-When: Wed Dec 9 17:51:20 PST 1998 
State-Changed-Why:  
Committed, thanks! 
>Unformatted:
