diff options
author | Constantine Sapuntzakis <csapuntz@cvs.openbsd.org> | 1998-01-09 16:21:58 +0000 |
---|---|---|
committer | Constantine Sapuntzakis <csapuntz@cvs.openbsd.org> | 1998-01-09 16:21:58 +0000 |
commit | cf2582baf0ff1957dea256c5c86c535b7bb84d56 (patch) | |
tree | 415d1989551067a0573b7d99818e30999636bdec /sys/kern | |
parent | feb2c2111190ec173af2abab2797cb84e851df52 (diff) |
A better fix for the mkdir ("path/") bug. This fix strips the trailing slashes
(except in the case where the path is just /////) in the following three
cases:
1) The path in mkdir
2) The destination path in rename if the source was a directory
3) The destination path in link if the source was a directory
Note #3 isn't strictly necessary since most of our file systems don't
support hard links of directories anyway.
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/vfs_lookup.c | 20 | ||||
-rw-r--r-- | sys/kern/vfs_syscalls.c | 28 |
2 files changed, 42 insertions, 6 deletions
diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index 15286e3ec6f..109e144b36a 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_lookup.c,v 1.13 1998/01/09 15:16:20 csapuntz Exp $ */ +/* $OpenBSD: vfs_lookup.c,v 1.14 1998/01/09 16:21:56 csapuntz Exp $ */ /* $NetBSD: vfs_lookup.c,v 1.17 1996/02/09 19:00:59 christos Exp $ */ /* @@ -130,6 +130,24 @@ namei(ndp) ndp->ni_vp = NULL; return (error); } + + /* + * Strip trailing slashes, as requested + */ + if (cnp->cn_flags & STRIPSLASHES) { + char *end = cnp->cn_pnbuf + ndp->ni_pathlen - 2; + + cp = end; + while (cp >= cnp->cn_pnbuf && + (*cp == '/')) cp--; + + /* Still some remaining characters in the buffer */ + if (cp >= cnp->cn_pnbuf) { + ndp->ni_pathlen -= (end - cp); + *(cp + 1) = '\0'; + } + } + ndp->ni_loopcnt = 0; /* diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index a08db234269..700e50588f6 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_syscalls.c,v 1.36 1998/01/02 05:42:49 deraadt Exp $ */ +/* $OpenBSD: vfs_syscalls.c,v 1.37 1998/01/09 16:21:55 csapuntz Exp $ */ /* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */ /* @@ -1063,12 +1063,19 @@ sys_link(p, v, retval) register struct vnode *vp; struct nameidata nd; int error; + int flags; NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); if ((error = namei(&nd)) != 0) return (error); vp = nd.ni_vp; - NDINIT(&nd, CREATE, LOCKPARENT, UIO_USERSPACE, SCARG(uap, link), p); + + flags = LOCKPARENT; + if (vp->v_type == VDIR) { + flags |= STRIPSLASHES; + } + + NDINIT(&nd, CREATE, flags, UIO_USERSPACE, SCARG(uap, link), p); if ((error = namei(&nd)) != 0) goto out; if (nd.ni_vp) { @@ -1993,14 +2000,23 @@ sys_rename(p, v, retval) register struct vnode *tvp, *fvp, *tdvp; struct nameidata fromnd, tond; int error; + int flags; NDINIT(&fromnd, DELETE, WANTPARENT | SAVESTART, UIO_USERSPACE, SCARG(uap, from), p); if ((error = namei(&fromnd)) != 0) return (error); fvp = fromnd.ni_vp; - NDINIT(&tond, RENAME, LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART, - UIO_USERSPACE, SCARG(uap, to), p); + + flags = LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART; + /* + * rename("foo/", "bar/"); is OK + */ + if (fvp->v_type == VDIR) + flags |= STRIPSLASHES; + + NDINIT(&tond, RENAME, flags, + UIO_USERSPACE, SCARG(uap, to), p); if ((error = namei(&tond)) != 0) { VOP_ABORTOP(fromnd.ni_dvp, &fromnd.ni_cnd); vrele(fromnd.ni_dvp); @@ -2077,7 +2093,9 @@ sys_mkdir(p, v, retval) int error; struct nameidata nd; - NDINIT(&nd, CREATE, LOCKPARENT, UIO_USERSPACE, SCARG(uap, path), p); + + NDINIT(&nd, CREATE, LOCKPARENT | STRIPSLASHES, + UIO_USERSPACE, SCARG(uap, path), p); if ((error = namei(&nd)) != 0) return (error); vp = nd.ni_vp; |