Skip to contentSkip to conversation

cluster/gfs2/mount mount.gfs2.c

Cluster-devel [email protected] 1 participant 1 message Apr 23, 2007

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/cluster
Module name: cluster
Changes by: teigland at sourceware.org 2007-04-23 20:18:09

Modified files:
gfs2/mount : mount.gfs2.c

Log message:

	Use realpath(3) to canonicalize path names for device and mount point.
	bz 237544

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/mount/mount.gfs2.c.diff?cvsroot=cluster&r1=1.20&r2=1.21

gfs2/mount/mount.gfs2.c +13 -9
@@ -38,7 +38,7 @@
 {
 	int cont = 1;
 	int optchar;
-	int l;
+	char *real;
 
 	/* FIXME: check for "quiet" option and don't print in that case */
 
@@ -77,18 +77,22 @@
 		}
 	}
 
-	if (optind < argc && argv[optind])
-		strncpy(mo->dev, argv[optind], PATH_MAX);
+	if (optind < argc && argv[optind]) {
+		real = realpath(argv[optind], NULL);
+		if (!real)
+			die("invalid device path \"%s\"\n", argv[optind]);
+		strncpy(mo->dev, real, PATH_MAX);
+		free(real);
+	}
 
 	++optind;
 
 	if (optind < argc && argv[optind]) {
-		strncpy(mo->dir, argv[optind], PATH_MAX);
-		l = strlen(mo->dir) - 1;
-		while (l > 0 && mo->dir[l] == '/') {
-			mo->dir[l] = '\0';
-			l--;
-		};
+		real = realpath(argv[optind], NULL);
+		if (!real)
+			die("invalid mount point path \"%s\"\n", argv[optind]);
+		strncpy(mo->dir, real, PATH_MAX);
+		free(real);
 	}
 
 	log_debug("mount %s %s", mo->dev, mo->dir);