fdup could fail when want for fdalloc > than the free fd in the block.
authorprovos <provos@openbsd.org>
Sat, 1 Apr 2000 23:29:25 +0000 (23:29 +0000)
committerprovos <provos@openbsd.org>
Sat, 1 Apr 2000 23:29:25 +0000 (23:29 +0000)
slightly different fix than in the bug report by
Rob Pickering <rob@syntonet.co.uk>

sys/kern/kern_descrip.c

index 3f4e739..f3f15ed 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_descrip.c,v 1.19 2000/02/28 18:04:08 provos Exp $        */
+/*     $OpenBSD: kern_descrip.c,v 1.20 2000/04/01 23:29:25 provos Exp $        */
 /*     $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $       */
 
 /*
@@ -619,6 +619,13 @@ fdalloc(p, want, result)
                        i = find_next_zero(&fdp->fd_lomap[new], 
                                           new > off ? 0 : i & NDENTRYMASK,
                                           NDENTRIES);
+                       if (i == -1) {
+                               /* free file descriptor in this block was
+                                * below want, try again with higher want.
+                                */
+                               want = (new + 1) << NDENTRYSHIFT;
+                               continue;
+                       }
                        i += (new << NDENTRYSHIFT);
                        if (i < last) {
                                fd_used(fdp, i);