lookup_dentry broken

Andreas Schwab (schwab@issan.informatik.uni-dortmund.de)
Wed, 23 Jul 97 11:19:25 +0200


The lookup_dentry function in 2.1.46 does not return the correct error
when the last name component is not a directory but there is a trailing
slash or the name ends in "." or "..". Instead of returning ENOTDIR it
either returns EACCES or no error at all (if the file is executable). For
example, if "foo" is a plain executable file then "foo/", "foo/." and
"foo/.." are all accepted without error.

--- linux-2.1.46/fs/namei.c.~1~ Mon Jul 21 20:19:34 1997
+++ linux-2.1.46/fs/namei.c Wed Jul 23 00:22:24 1997
@@ -391,6 +391,9 @@
dentry = ERR_PTR(-ENOENT);
if (!base->d_inode)
break;
+ dentry = ERR_PTR(-ENOTDIR);
+ if (!S_ISDIR(base->d_inode->i_mode))
+ break;
this.name = name;
hash = init_name_hash();
len = 0;
@@ -421,9 +424,18 @@
break;

base = do_follow_link(base, dentry);
- if (c && !IS_ERR(base))
+ if (IS_ERR(base))
+ goto return_base;
+ if (c)
continue;
-
+ if (name[-1] == '/') {
+ dentry = ERR_PTR(-ENOENT);
+ if (!base->d_inode)
+ break;
+ dentry = ERR_PTR(-ENOTDIR);
+ if (!S_ISDIR(base->d_inode->i_mode))
+ break;
+ }
return_base:
return base;
}

-- 
Andreas Schwab                                      "And now for something
schwab@issan.informatik.uni-dortmund.de              completely different"