Subject: bin/17673: mount_union does not resolve relative paths
To: None <>
From: Julio Merino <>
List: netbsd-bugs
Date: 07/22/2002 00:21:52
>Number:         17673
>Category:       bin
>Synopsis:       mount_union does not resolve relative paths
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 21 15:21:00 PDT 2002
>Originator:     Julio Merino
>Release:        NetBSD 1.6D
System: NetBSD darkstar.local 1.6D NetBSD 1.6D (DARKSTAR) #2: Wed Jul 17 19:45:32 CEST 2002 jmmv@darkstar.local:/var/build/kernel/DARKSTAR i386
Architecture: i386
Machine: i386
	The mount_union program does not resolve the full path of the mount
	point. If used with relative paths, you can't unmount the directory
	later because umount works only with absolute pathnames.

	If relative paths are entered, they must be converted to absolute
	pathnames, to avoid this problem. Currently, it is done with the
	target path, but not with the mount point.

	Consider the following situation:
	$ cd
	$ mkdir pkgsrc
	$ mount_union -b /usr/pkgsrc pkgsrc
	$ umount pkgsrc
	umount: /home/somebody/pkgsrc: not currently mounted

	The following patch should fix the problem, but I'm not sure it
	is the right way to solve it.

Index: mount_union.c
RCS file: /pub/NetBSD-CVS/basesrc/sbin/mount_union/mount_union.c,v
retrieving revision 1.7
diff -u -u -r1.7 mount_union.c
--- mount_union.c	2000/10/30 20:57:01	1.7
+++ mount_union.c	2002/07/21 22:14:42
@@ -90,7 +90,7 @@
 	struct union_args args;
 	int ch, mntflags;
-	char target[MAXPATHLEN];
+	char target[MAXPATHLEN], mntpt[MAXPATHLEN];
 	mntflags = 0;
 	args.mntflags = UNMNT_ABOVE;
@@ -121,14 +121,17 @@
 	if (realpath(argv[0], target) == 0)
 		err(1, "%s", target);
-	if (subdir(target, argv[1]) || subdir(argv[1], target))
-		errx(1, "%s (%s) and %s are not distinct paths",
-		    argv[0], target, argv[1]);
+	if (realpath(argv[1], mntpt) == 0)
+		err(1, "%s", mntpt);
+	if (subdir(target, mntpt) || subdir(mntpt, target))
+		errx(1, "%s (%s) and %s (%s) are not distinct paths",
+		    argv[0], target, argv[1], mntpt);
+ = target;
-	if (mount(MOUNT_UNION, argv[1], mntflags, &args))
-		err(1, "%s on %s", target, argv[1]);
+	if (mount(MOUNT_UNION, mntpt, mntflags, &args))
+		err(1, "%s on %s", target, mntpt);