PATCH for pre-patch-2.1.45-5: "lookup_dentry" should *sometimes* return -ENOENT

Kevin Buhr (buhr@stat.wisc.edu)
14 Jul 1997 16:35:01 -0500


Linus:

First, here's a patch to fix a syntax error so it doesn't find its way
into the real 2.1.45:

--- linux/arch/i386/kernel/process.c 1997/07/14 15:59:47 1.1.1.1.4.1
+++ linux/arch/i386/kernel/process.c 1997/07/14 16:23:00
@@ -625,7 +625,7 @@
lock_kernel();
filename = getname((char *) regs.ebx);
error = PTR_ERR(filename);
- if (IS_ERR(filename)
+ if (IS_ERR(filename))
goto out;
error = do_execve(filename, (char **) regs.ecx, (char **) regs.edx, &regs);
putname(filename);

Next, "lookup_dentry" indicates the final component of the pathname
wasn't found by returning the "dentry" for the path with a NULL
"d_inode". BUT, it does exactly the same thing if some *middle*
component of the pathname wasn't found. As a result, if there's no
such directory as "foo", things like "mkdir foo/bar" or
"echo >foo/bur" will behave in an unexpected manner.

The following patch forces "lookup_dentry" to return an ENOENT error
if a *middle* path component (as opposed to a final path component)
isn't found. Hopefully, this works correctly for all cases.

--- linux/fs/namei.c 1997/07/14 15:59:52 1.1.1.2.2.3
+++ linux/fs/namei.c 1997/07/14 21:12:15
@@ -443,8 +443,13 @@
dentry = lookup(base, &this);
if (IS_ERR(dentry))
break;
- if (!dentry->d_inode)
+ if (!dentry->d_inode) {
+ if (c) {
+ dput(dentry);
+ dentry = ERR_PTR(-ENOENT);
+ }
break;
+ }

/* Last component? */
if (!c) {

Kevin <buhr@stat.wisc.edu>