|
1 | | -/* $NetBSD: mount_ados.c,v 1.17 2003/05/03 15:37:07 christos Exp $ */ |
| 1 | +/* $NetBSD: mount_ados.c,v 1.18 2005/01/31 05:19:18 erh Exp $ */ |
2 | 2 |
|
3 | 3 | /* |
4 | 4 | * Copyright (c) 1994 Christopher G. Demetriou |
|
36 | 36 |
|
37 | 37 | #include <sys/cdefs.h> |
38 | 38 | #ifndef lint |
39 | | -__RCSID("$NetBSD: mount_ados.c,v 1.17 2003/05/03 15:37:07 christos Exp $"); |
| 39 | +__RCSID("$NetBSD: mount_ados.c,v 1.18 2005/01/31 05:19:18 erh Exp $"); |
40 | 40 | #endif /* not lint */ |
41 | 41 |
|
42 | 42 | #include <sys/cdefs.h> |
@@ -84,7 +84,7 @@ mount_ados(argc, argv) |
84 | 84 | struct adosfs_args args; |
85 | 85 | struct stat sb; |
86 | 86 | int c, mntflags, set_gid, set_uid, set_mask; |
87 | | - char *dev, *dir, ndir[MAXPATHLEN+1]; |
| 87 | + char *dev, *dir, canon_dir[MAXPATHLEN], canon_dev[MAXPATHLEN]; |
88 | 88 |
|
89 | 89 | mntflags = set_gid = set_uid = set_mask = 0; |
90 | 90 | (void)memset(&args, '\0', sizeof(args)); |
@@ -118,13 +118,20 @@ mount_ados(argc, argv) |
118 | 118 |
|
119 | 119 | dev = argv[optind]; |
120 | 120 | dir = argv[optind + 1]; |
121 | | - if (dir[0] != '/') { |
| 121 | + |
| 122 | + if (realpath(dev, canon_dev) == NULL) /* Check device path */ |
| 123 | + err(1, "realpath %s", dev); |
| 124 | + if (strncmp(dev, canon_dev, MAXPATHLEN)) { |
| 125 | + warnx("\"%s\" is a relative path.", dev); |
| 126 | + dev = canon_dev; |
| 127 | + warnx("using \"%s\" instead.", dev); |
| 128 | + } |
| 129 | + |
| 130 | + if (realpath(dir, canon_dir) == NULL) /* Check mounton path */ |
| 131 | + err(1, "realpath %s", dir); |
| 132 | + if (strncmp(dir, canon_dir, MAXPATHLEN)) { |
122 | 133 | warnx("\"%s\" is a relative path.", dir); |
123 | | - if (getcwd(ndir, sizeof(ndir)) == NULL) |
124 | | - err(1, "getcwd"); |
125 | | - strncat(ndir, "/", sizeof(ndir) - strlen(ndir) - 1); |
126 | | - strncat(ndir, dir, sizeof(ndir) - strlen(ndir) - 1); |
127 | | - dir = ndir; |
| 134 | + dir = canon_dir; |
128 | 135 | warnx("using \"%s\" instead.", dir); |
129 | 136 | } |
130 | 137 |
|
|
0 commit comments