summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2019-05-13 17:31:52 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2019-05-13 17:31:52 +0000
commit9ebccbfd943ee0a8eab4e5e40cddbba63e4f8600 (patch)
tree4f0f733313bfbdeaa4dfeb5b4296942b91cb503d
parentf4cff3d79341015ed7e800e2eda04a6dc6046314 (diff)
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) {