[d_path 4/7] Make getcwd() only return valid paths

Andreas Gruenbacher
2007-04-19T23:56:31Z

[-- Attachment #1: fix-getcwd.diff --]
[-- Type: text/plain, Size: 961 bytes --]

Make getcwd() fail with -ENOENT if the current working directory is
disconnected: the process is not asking for some previous name of that
directory but for the current name; returning a path meaningless in the
context of that process makes no sense.

Signed-off-by: Andreas Gruenbacher <agruen@suse.de>

---
fs/dcache.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1910,10 +1910,12 @@ asmlinkage long sys_getcwd(char __user *
read_unlock(&current->fs->lock);

cwd = __d_path(pwd, pwdmnt, root, rootmnt, page, PAGE_SIZE, 1);
- cwd = __connect_d_path(cwd, page);
error = PTR_ERR(cwd);
if (IS_ERR(cwd))
goto out;
+ error = -ENOENT;
+ if (*cwd != '/')
+ goto out;

error = -ERANGE;
len = PAGE_SIZE + page - cwd;

--
Andreas Gruenbacher <agruen@suse.de>
SUSE Labs, SUSE LINUX Products GmbH
GF: Markus Rex, HRB 16746 (AG Nuernberg)

GPG: AF77 FAD1 1819 D442 400F 4BC8 409A 6903 4FDD EE02