diff options
author | 2018-04-12 10:28:13 +0000 | |
---|---|---|
committer | 2018-04-12 10:28:13 +0000 | |
commit | f58a38b150824f68cc1d037aa27449fbdb9db455 (patch) | |
tree | d279877718602ab5fdeaec896948e9cf4c571b97 | |
parent | Disable counting TCP packets in the test as it does not work reliably. (diff) | |
download | wireguard-openbsd-f58a38b150824f68cc1d037aa27449fbdb9db455.tar.xz wireguard-openbsd-f58a38b150824f68cc1d037aa27449fbdb9db455.zip |
Call FREF(9) earlier instead of incrementing `f_count' directly in
dupfdopen().
ok bluhm@, visa@
-rw-r--r-- | sys/kern/kern_descrip.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 64222af3df1..c223f280388 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_descrip.c,v 1.148 2018/04/11 16:47:17 bluhm Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.149 2018/04/12 10:28:13 mpi Exp $ */ /* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */ /* @@ -1297,20 +1297,24 @@ dupfdopen(struct proc *p, int indx, int mode) */ if ((wfp = fd_getfile(fdp, dupfd)) == NULL) return (EBADF); + FREF(wfp); /* * Check that the mode the file is being opened for is a * subset of the mode of the existing descriptor. */ - if (((mode & (FREAD|FWRITE)) | wfp->f_flag) != wfp->f_flag) + if (((mode & (FREAD|FWRITE)) | wfp->f_flag) != wfp->f_flag) { + FRELE(wfp, p); return (EACCES); - if (wfp->f_count == LONG_MAX-2) + } + if (wfp->f_count == LONG_MAX-2) { + FRELE(wfp, p); return (EDEADLK); + } fdp->fd_ofiles[indx] = wfp; fdp->fd_ofileflags[indx] = (fdp->fd_ofileflags[indx] & UF_EXCLOSE) | (fdp->fd_ofileflags[dupfd] & ~UF_EXCLOSE); - wfp->f_count++; fd_used(fdp, indx); return (0); } |