aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2001-05-02 21:17:38 +0000
committerMatt Kraai <kraai@debian.org>2001-05-02 21:17:38 +0000
commit3425111bb9925b9a00c34cbe95639a6e0bce58c1 (patch)
treea0cbb3581f34979f542b546face217c103080d72
parent0fcd447d59fffa2fafe090f0cd76bd115de02add (diff)
downloadbusybox-w32-3425111bb9925b9a00c34cbe95639a6e0bce58c1.tar.gz
busybox-w32-3425111bb9925b9a00c34cbe95639a6e0bce58c1.tar.bz2
busybox-w32-3425111bb9925b9a00c34cbe95639a6e0bce58c1.zip
Fix bug #1108 by always canonicalizing arguments.
-rw-r--r--mount.c29
-rw-r--r--util-linux/mount.c29
2 files changed, 32 insertions, 26 deletions
diff --git a/mount.c b/mount.c
index fa298d93a..89eb099c5 100644
--- a/mount.c
+++ b/mount.c
@@ -43,6 +43,7 @@
43 * 43 *
44 */ 44 */
45 45
46#include <limits.h>
46#include <stdlib.h> 47#include <stdlib.h>
47#include <unistd.h> 48#include <unistd.h>
48#include <errno.h> 49#include <errno.h>
@@ -338,8 +339,7 @@ extern int mount_main(int argc, char **argv)
338 char *extra_opts = string_flags_buf; 339 char *extra_opts = string_flags_buf;
339 int flags = 0; 340 int flags = 0;
340 char *filesystemType = "auto"; 341 char *filesystemType = "auto";
341 char *device = NULL; 342 char device[PATH_MAX], directory[PATH_MAX];
342 char *directory = NULL;
343 int all = FALSE; 343 int all = FALSE;
344 int fakeIt = FALSE; 344 int fakeIt = FALSE;
345 int useMtab = TRUE; 345 int useMtab = TRUE;
@@ -378,15 +378,18 @@ extern int mount_main(int argc, char **argv)
378 } 378 }
379 } 379 }
380 380
381 if (argv[optind] != NULL) { 381 if (!all && optind == argc)
382 device = argv[optind];
383 directory = argv[optind + 1];
384 }
385
386 if (device == NULL && !all)
387 show_mounts(); 382 show_mounts();
388 383
389 if (all == TRUE || directory == NULL) { 384 if (optind < argc)
385 if (realpath(argv[optind], device) == NULL)
386 perror_msg_and_die("%s", device);
387
388 if (optind + 1 < argc)
389 if (realpath(argv[optind + 1], directory) == NULL)
390 perror_msg_and_die("%s", directory);
391
392 if (all == TRUE || optind + 1 == argc) {
390 struct mntent *m; 393 struct mntent *m;
391 FILE *f = setmntent("/etc/fstab", "r"); 394 FILE *f = setmntent("/etc/fstab", "r");
392 fstabmount = TRUE; 395 fstabmount = TRUE;
@@ -395,7 +398,7 @@ extern int mount_main(int argc, char **argv)
395 perror_msg_and_die( "\nCannot read /etc/fstab"); 398 perror_msg_and_die( "\nCannot read /etc/fstab");
396 399
397 while ((m = getmntent(f)) != NULL) { 400 while ((m = getmntent(f)) != NULL) {
398 if (all == FALSE && directory == NULL && ( 401 if (all == FALSE && optind + 1 == argc && (
399 (strcmp(device, m->mnt_fsname) != 0) && 402 (strcmp(device, m->mnt_fsname) != 0) &&
400 (strcmp(device, m->mnt_dir) != 0) ) ) { 403 (strcmp(device, m->mnt_dir) != 0) ) ) {
401 continue; 404 continue;
@@ -414,8 +417,8 @@ extern int mount_main(int argc, char **argv)
414 parse_mount_options(m->mnt_opts, &flags, string_flags); 417 parse_mount_options(m->mnt_opts, &flags, string_flags);
415 } 418 }
416 419
417 device = strdup(m->mnt_fsname); 420 strcpy(device, m->mnt_fsname);
418 directory = strdup(m->mnt_dir); 421 strcpy(directory, m->mnt_dir);
419 filesystemType = strdup(m->mnt_type); 422 filesystemType = strdup(m->mnt_type);
420singlemount: 423singlemount:
421 string_flags = strdup(string_flags); 424 string_flags = strdup(string_flags);
@@ -441,7 +444,7 @@ singlemount:
441 if (fstabmount == TRUE) 444 if (fstabmount == TRUE)
442 endmntent(f); 445 endmntent(f);
443 446
444 if (all == FALSE && fstabmount == TRUE && directory == NULL) 447 if (all == FALSE && fstabmount == TRUE && optind + 1 == argc)
445 fprintf(stderr, "Can't find %s in /etc/fstab\n", device); 448 fprintf(stderr, "Can't find %s in /etc/fstab\n", device);
446 449
447 return rc; 450 return rc;
diff --git a/util-linux/mount.c b/util-linux/mount.c
index fa298d93a..89eb099c5 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -43,6 +43,7 @@
43 * 43 *
44 */ 44 */
45 45
46#include <limits.h>
46#include <stdlib.h> 47#include <stdlib.h>
47#include <unistd.h> 48#include <unistd.h>
48#include <errno.h> 49#include <errno.h>
@@ -338,8 +339,7 @@ extern int mount_main(int argc, char **argv)
338 char *extra_opts = string_flags_buf; 339 char *extra_opts = string_flags_buf;
339 int flags = 0; 340 int flags = 0;
340 char *filesystemType = "auto"; 341 char *filesystemType = "auto";
341 char *device = NULL; 342 char device[PATH_MAX], directory[PATH_MAX];
342 char *directory = NULL;
343 int all = FALSE; 343 int all = FALSE;
344 int fakeIt = FALSE; 344 int fakeIt = FALSE;
345 int useMtab = TRUE; 345 int useMtab = TRUE;
@@ -378,15 +378,18 @@ extern int mount_main(int argc, char **argv)
378 } 378 }
379 } 379 }
380 380
381 if (argv[optind] != NULL) { 381 if (!all && optind == argc)
382 device = argv[optind];
383 directory = argv[optind + 1];
384 }
385
386 if (device == NULL && !all)
387 show_mounts(); 382 show_mounts();
388 383
389 if (all == TRUE || directory == NULL) { 384 if (optind < argc)
385 if (realpath(argv[optind], device) == NULL)
386 perror_msg_and_die("%s", device);
387
388 if (optind + 1 < argc)
389 if (realpath(argv[optind + 1], directory) == NULL)
390 perror_msg_and_die("%s", directory);
391
392 if (all == TRUE || optind + 1 == argc) {
390 struct mntent *m; 393 struct mntent *m;
391 FILE *f = setmntent("/etc/fstab", "r"); 394 FILE *f = setmntent("/etc/fstab", "r");
392 fstabmount = TRUE; 395 fstabmount = TRUE;
@@ -395,7 +398,7 @@ extern int mount_main(int argc, char **argv)
395 perror_msg_and_die( "\nCannot read /etc/fstab"); 398 perror_msg_and_die( "\nCannot read /etc/fstab");
396 399
397 while ((m = getmntent(f)) != NULL) { 400 while ((m = getmntent(f)) != NULL) {
398 if (all == FALSE && directory == NULL && ( 401 if (all == FALSE && optind + 1 == argc && (
399 (strcmp(device, m->mnt_fsname) != 0) && 402 (strcmp(device, m->mnt_fsname) != 0) &&
400 (strcmp(device, m->mnt_dir) != 0) ) ) { 403 (strcmp(device, m->mnt_dir) != 0) ) ) {
401 continue; 404 continue;
@@ -414,8 +417,8 @@ extern int mount_main(int argc, char **argv)
414 parse_mount_options(m->mnt_opts, &flags, string_flags); 417 parse_mount_options(m->mnt_opts, &flags, string_flags);
415 } 418 }
416 419
417 device = strdup(m->mnt_fsname); 420 strcpy(device, m->mnt_fsname);
418 directory = strdup(m->mnt_dir); 421 strcpy(directory, m->mnt_dir);
419 filesystemType = strdup(m->mnt_type); 422 filesystemType = strdup(m->mnt_type);
420singlemount: 423singlemount:
421 string_flags = strdup(string_flags); 424 string_flags = strdup(string_flags);
@@ -441,7 +444,7 @@ singlemount:
441 if (fstabmount == TRUE) 444 if (fstabmount == TRUE)
442 endmntent(f); 445 endmntent(f);
443 446
444 if (all == FALSE && fstabmount == TRUE && directory == NULL) 447 if (all == FALSE && fstabmount == TRUE && optind + 1 == argc)
445 fprintf(stderr, "Can't find %s in /etc/fstab\n", device); 448 fprintf(stderr, "Can't find %s in /etc/fstab\n", device);
446 449
447 return rc; 450 return rc;