When rename("a", "b/.") is performed, target namei() call returns

dvp == vp. Rename syscall does not check for the case, and at least
ufs_rename() cannot deal with it. POSIX explicitely requires that both
rename(2) and rmdir(2) return EINVAL when any of the pathes end in "/.".

Detect the slashdot lookup for RENAME or REMOVE in lookup(), and return
EINVAL.

Reported by:	Jim Meyering <jim meyering net>
Tested by:	simon, pho
MFC after:	1 week
This commit is contained in:
Konstantin Belousov 2009-11-10 11:50:37 +00:00
parent 75c586a4c8
commit 88e6f61a19

View File

@ -552,6 +552,12 @@ dirloop:
else
cnp->cn_flags &= ~ISLASTCN;
if ((cnp->cn_flags & ISLASTCN) != 0 &&
cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.' &&
(cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) {
error = EINVAL;
goto bad;
}
/*
* Check for degenerate name (e.g. / or "")