Blob Blame History Raw
autofs-5.1.7 - fix mount_fullpath()

From: Ian Kent <raven@themaw.net>

mount_fullpath() incorrecly fills fullpath with the contents of root
when name[0] == '/'. The cases root[last] == '/' and name[0] == '/'
need to be handled seperately.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG           |    1 +
 lib/mounts.c        |    4 +++-
 modules/parse_amd.c |    6 ++++--
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 390028ac..e2fd532c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -36,6 +36,7 @@
 - add tree_mapent_add_node().
 - add tree_mapent_delete_offsets().
 - add tree_mapent_traverse_subtree().
+- fix mount_fullpath().
 
 25/01/2021 autofs-5.1.7
 - make bind mounts propagation slave by default.
diff --git a/lib/mounts.c b/lib/mounts.c
index fded4c09..497c28c9 100644
--- a/lib/mounts.c
+++ b/lib/mounts.c
@@ -371,8 +371,10 @@ int mount_fullpath(char *fullpath, size_t max_len,
 	/* Root offset of multi-mount or direct or offset mount.
 	 * Direct or offset mount, name (or root) is absolute path.
 	 */
-	if (root[last] == '/' || *name == '/')
+	if (root[last] == '/')
 		len = snprintf(fullpath, max_len, "%s", root);
+	else if (*name == '/')
+		len = snprintf(fullpath, max_len, "%s", name);
 	else
 		len = snprintf(fullpath, max_len, "%s/%s", root, name);
 
diff --git a/modules/parse_amd.c b/modules/parse_amd.c
index 5a9079d6..64c1ce63 100644
--- a/modules/parse_amd.c
+++ b/modules/parse_amd.c
@@ -1177,7 +1177,8 @@ static int do_generic_mount(struct autofs_point *ap, const char *name,
 		 * the automount filesystem.
 		 */
 		if (!is_mounted(entry->fs, MNTS_REAL)) {
-			ret = do_mount(ap, entry->fs, "/", 1,
+			ret = do_mount(ap, entry->fs,
+				       entry->fs, strlen(entry->fs),
 				       target, entry->type, opts);
 			if (ret)
 				goto out;
@@ -1227,7 +1228,8 @@ static int do_nfs_mount(struct autofs_point *ap, const char *name,
 					     mount_nfs->context);
 	} else {
 		if (!is_mounted(entry->fs, MNTS_REAL)) {
-			ret = mount_nfs->mount_mount(ap, entry->fs, "/", 1,
+			ret = mount_nfs->mount_mount(ap, entry->fs,
+						entry->fs, strlen(entry->fs),
 						target, entry->type, opts,
 						mount_nfs->context);
 			if (ret)