[linux-cifs-client] [PATCH] cifs: fix off-by-one bug in compose_mount_options

Jeff Layton jlayton at redhat.com
Fri Dec 12 16:54:27 GMT 2008


Igor recently added a patch to use path_consumed in DFS referrals to
determine how much of the given path has been consumed by the referral.
The problem there is that path_consumed assumes that the path has a
single backslash at the beginning, but build_path_from_dentry builds
paths that have a double backslash. path_consumed is therefore generally
off-by-one. This patch fixes it to account for this difference.

Signed-off-by: Jeff Layton <jlayton at redhat.com>
---
 fs/cifs/cifs_dfs_ref.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c
index e1c1836..4ef6ebd 100644
--- a/fs/cifs/cifs_dfs_ref.c
+++ b/fs/cifs/cifs_dfs_ref.c
@@ -200,14 +200,18 @@ static char *compose_mount_options(const char *sb_mountdata,
 	if (tkn_e == NULL) /* invalid unc, missing share name*/
 		goto compose_mount_options_out;
 
+	/*
+	 * build_path_from_dentry adds a leading backslash to the path that
+	 * is not accounted for in path_consumed.
+	 */
 	fullpath = build_path_from_dentry(dentry);
 	tkn_e = strchr(tkn_e + 1, '\\');
-	if (tkn_e || strlen(fullpath) - (ref->path_consumed)) {
+	if (tkn_e || strlen(fullpath) - (ref->path_consumed + 1)) {
 		strncat(mountdata, &sep, 1);
 		strcat(mountdata, "prefixpath=");
 		if (tkn_e)
 			strcat(mountdata, tkn_e + 1);
-		strcat(mountdata, fullpath + (ref->path_consumed));
+		strcat(mountdata, fullpath + (ref->path_consumed + 1));
 	}
 	kfree(fullpath);
 
-- 
1.5.5.1



More information about the linux-cifs-client mailing list