diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2011-07-02 16:53:18 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2011-07-02 16:53:18 +0000 |
commit | 3f0a68828f3f52fb8040decba4ae21701d3350bf (patch) | |
tree | 067d51a37f67f72cbf29e6b1f77b29576db3d93c /sys | |
parent | a77fd49d931b8f2724b608249ce1b6261506a53c (diff) |
Use getvnode() instead of implementing our own file descriptor handling
code. This gets us some additional validation and correct reference
counting.
Issue spotted by matthew@
ok thib@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/diskmap.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/sys/dev/diskmap.c b/sys/dev/diskmap.c index a080dc24c29..62da4c2de3d 100644 --- a/sys/dev/diskmap.c +++ b/sys/dev/diskmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diskmap.c,v 1.4 2011/04/07 15:30:16 miod Exp $ */ +/* $OpenBSD: diskmap.c,v 1.5 2011/07/02 16:53:17 jsing Exp $ */ /* * Copyright (c) 2009, 2010 Joel Sing <jsing@openbsd.org> @@ -55,7 +55,7 @@ diskmapioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) struct dk_diskmap *dm; struct nameidata ndp; struct filedesc *fdp; - struct file *fp; + struct file *fp = NULL; struct vnode *vp = NULL, *ovp; char *devname; int fd, error = EINVAL; @@ -81,15 +81,8 @@ diskmapioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) fdp = p->p_fd; fdplock(fdp); - if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL) { - error = EINVAL; + if ((error = getvnode(fdp, fd, &fp)) != 0) goto bad; - } - - if (!FILE_IS_USABLE(fp)) { - error = EINVAL; - goto bad; - } ndp.ni_segflg = UIO_SYSSPACE; ndp.ni_dirp = devname; @@ -122,14 +115,17 @@ diskmapioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) VOP_UNLOCK(vp, 0, p); - free(devname, M_DEVBUF); + FRELE(fp); fdpunlock(fdp); + free(devname, M_DEVBUF); return 0; bad: if (vp) vput(vp); + if (fp) + FRELE(fp); fdpunlock(fdp); |