vfs: do_last(): check LOOKUP_DIRECTORY
authorMiklos Szeredi <mszeredi@suse.cz>
Mon, 21 May 2012 15:30:11 +0000 (17:30 +0200)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 1 Jun 2012 16:11:58 +0000 (12:11 -0400)
Check for ENOTDIR before finishing open.  This allows this code to be shared
between O_CREAT and plain opens.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/namei.c

index a7e994bb78c2b602b2c70d11d83b42495e12123a..4767c0588b6ed5436ec3d2b9288ddb7a377aa5d8 100644 (file)
@@ -2386,6 +2386,9 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
        error = -EISDIR;
        if (S_ISDIR(nd->inode->i_mode))
                goto exit;
+       error = -ENOTDIR;
+       if ((nd->flags & LOOKUP_DIRECTORY) && !nd->inode->i_op->lookup)
+               goto exit;
 ok:
        if (!S_ISREG(nd->inode->i_mode))
                will_truncate = 0;