summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2019-05-13 17:31:51 +0000
committerderaadt <deraadt@openbsd.org>2019-05-13 17:31:51 +0000
commit90829303f77d5fbf5b7ead896d38017e832e0947 (patch)
tree94da85528eb6a50d7963957e40f920332380b93b
parentThe fd used by nlist() isn't application visible, so mark it close-on-exec (diff)
downloadwireguard-openbsd-90829303f77d5fbf5b7ead896d38017e832e0947.tar.xz
wireguard-openbsd-90829303f77d5fbf5b7ead896d38017e832e0947.zip
dup2(n,n) would rlimit check before handling the n==n shortcut,
and incorrectly return EBADF when n>curlim. ok millert guenther tedu
-rw-r--r--sys/kern/kern_descrip.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index d20ef7ebaa1..7da5dadb4ee 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_descrip.c,v 1.183 2018/11/05 17:05:50 anton Exp $ */
+/* $OpenBSD: kern_descrip.c,v 1.184 2019/05/13 17:31:51 deraadt Exp $ */
/* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */
/*
@@ -343,11 +343,6 @@ dodup3(struct proc *p, int old, int new, int flags, register_t *retval)
restart:
if ((fp = fd_getfile(fdp, old)) == NULL)
return (EBADF);
- if ((u_int)new >= p->p_rlimit[RLIMIT_NOFILE].rlim_cur ||
- (u_int)new >= maxfiles) {
- FRELE(fp, p);
- return (EBADF);
- }
if (old == new) {
/*
* NOTE! This doesn't clear the close-on-exec flag. This might
@@ -358,6 +353,11 @@ restart:
FRELE(fp, p);
return (0);
}
+ if ((u_int)new >= p->p_rlimit[RLIMIT_NOFILE].rlim_cur ||
+ (u_int)new >= maxfiles) {
+ FRELE(fp, p);
+ return (EBADF);
+ }
fdplock(fdp);
if (new >= fdp->fd_nfiles) {
if ((error = fdalloc(p, new, &i)) != 0) {