diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-17 15:04:01 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-17 15:04:01 +0000 |
commit | 3bc59aa2a46c132121d892254c81ad7e54eb796d (patch) | |
tree | 068e3d7786c2f6033511f18d46854a391da7e002 /util-linux/mount.c | |
parent | fc56dd2e2128556971b9c0de329a2a6d15d5489f (diff) | |
download | busybox-w32-3bc59aa2a46c132121d892254c81ad7e54eb796d.tar.gz busybox-w32-3bc59aa2a46c132121d892254c81ad7e54eb796d.tar.bz2 busybox-w32-3bc59aa2a46c132121d892254c81ad7e54eb796d.zip |
mount: fix bugs: free(mp->mnt_fsname) of non-malloced ptr;
check for "more than 2 arguments" was actually checking for -2.
Diffstat (limited to 'util-linux/mount.c')
-rw-r--r-- | util-linux/mount.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index 01b811471..ed81ba4b2 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -719,6 +719,7 @@ static void error_msg_rpc(const char *msg) | |||
719 | bb_error_msg("%.*s", len, msg); | 719 | bb_error_msg("%.*s", len, msg); |
720 | } | 720 | } |
721 | 721 | ||
722 | // NB: mp->xxx fields may be trashed on exit | ||
722 | static int nfsmount(struct mntent *mp, int vfsflags, char *filteropts) | 723 | static int nfsmount(struct mntent *mp, int vfsflags, char *filteropts) |
723 | { | 724 | { |
724 | CLIENT *mclient; | 725 | CLIENT *mclient; |
@@ -1260,7 +1261,7 @@ int nfsmount(struct mntent *mp, int vfsflags, char *filteropts); | |||
1260 | 1261 | ||
1261 | // Mount one directory. Handles CIFS, NFS, loopback, autobind, and filesystem | 1262 | // Mount one directory. Handles CIFS, NFS, loopback, autobind, and filesystem |
1262 | // type detection. Returns 0 for success, nonzero for failure. | 1263 | // type detection. Returns 0 for success, nonzero for failure. |
1263 | 1264 | // NB: mp->xxx fields may be trashed on exit | |
1264 | static int singlemount(struct mntent *mp, int ignore_busy) | 1265 | static int singlemount(struct mntent *mp, int ignore_busy) |
1265 | { | 1266 | { |
1266 | int rc = -1, vfsflags; | 1267 | int rc = -1, vfsflags; |
@@ -1306,15 +1307,15 @@ static int singlemount(struct mntent *mp, int ignore_busy) | |||
1306 | 1307 | ||
1307 | // compose new unc '\\server-ip\share' | 1308 | // compose new unc '\\server-ip\share' |
1308 | 1309 | ||
1309 | s = xasprintf("\\\\%s%s",ip+3,strchr(mp->mnt_fsname+2,'\\')); | 1310 | mp->mnt_fsname = xasprintf("\\\\%s%s", ip+3, |
1310 | if (ENABLE_FEATURE_CLEAN_UP) free(mp->mnt_fsname); | 1311 | strchr(mp->mnt_fsname+2,'\\')); |
1311 | mp->mnt_fsname = s; | ||
1312 | 1312 | ||
1313 | // lock is required | 1313 | // lock is required |
1314 | vfsflags |= MS_MANDLOCK; | 1314 | vfsflags |= MS_MANDLOCK; |
1315 | 1315 | ||
1316 | mp->mnt_type = "cifs"; | 1316 | mp->mnt_type = "cifs"; |
1317 | rc = mount_it_now(mp, vfsflags, filteropts); | 1317 | rc = mount_it_now(mp, vfsflags, filteropts); |
1318 | if (ENABLE_FEATURE_CLEAN_UP) free(mp->mnt_fsname); | ||
1318 | goto report_error; | 1319 | goto report_error; |
1319 | } | 1320 | } |
1320 | 1321 | ||
@@ -1457,14 +1458,16 @@ int mount_main(int argc, char **argv) | |||
1457 | bb_show_usage(); | 1458 | bb_show_usage(); |
1458 | } | 1459 | } |
1459 | } | 1460 | } |
1461 | argv += optind; | ||
1462 | argc -= optind; | ||
1460 | 1463 | ||
1461 | // Three or more non-option arguments? Die with a usage message. | 1464 | // Three or more non-option arguments? Die with a usage message. |
1462 | 1465 | ||
1463 | if (optind-argc>2) bb_show_usage(); | 1466 | if (argc > 2) bb_show_usage(); |
1464 | 1467 | ||
1465 | // If we have no arguments, show currently mounted filesystems | 1468 | // If we have no arguments, show currently mounted filesystems |
1466 | 1469 | ||
1467 | if (optind == argc) { | 1470 | if (!argc) { |
1468 | if (!all) { | 1471 | if (!all) { |
1469 | FILE *mountTable = setmntent(bb_path_mtab_file, "r"); | 1472 | FILE *mountTable = setmntent(bb_path_mtab_file, "r"); |
1470 | 1473 | ||
@@ -1484,15 +1487,15 @@ int mount_main(int argc, char **argv) | |||
1484 | if (ENABLE_FEATURE_CLEAN_UP) endmntent(mountTable); | 1487 | if (ENABLE_FEATURE_CLEAN_UP) endmntent(mountTable); |
1485 | return EXIT_SUCCESS; | 1488 | return EXIT_SUCCESS; |
1486 | } | 1489 | } |
1487 | } else storage_path = bb_simplify_path(argv[optind]); | 1490 | } else storage_path = bb_simplify_path(argv[0]); |
1488 | 1491 | ||
1489 | // When we have two arguments, the second is the directory and we can | 1492 | // When we have two arguments, the second is the directory and we can |
1490 | // skip looking at fstab entirely. We can always abspath() the directory | 1493 | // skip looking at fstab entirely. We can always abspath() the directory |
1491 | // argument when we get it. | 1494 | // argument when we get it. |
1492 | 1495 | ||
1493 | if (optind+2 == argc) { | 1496 | if (argc == 2) { |
1494 | mtpair->mnt_fsname = argv[optind]; | 1497 | mtpair->mnt_fsname = argv[0]; |
1495 | mtpair->mnt_dir = argv[optind+1]; | 1498 | mtpair->mnt_dir = argv[1]; |
1496 | mtpair->mnt_type = fstype; | 1499 | mtpair->mnt_type = fstype; |
1497 | mtpair->mnt_opts = cmdopts; | 1500 | mtpair->mnt_opts = cmdopts; |
1498 | rc = singlemount(mtpair, 0); | 1501 | rc = singlemount(mtpair, 0); |
@@ -1504,8 +1507,8 @@ int mount_main(int argc, char **argv) | |||
1504 | if (ENABLE_FEATURE_MOUNT_FLAGS && | 1507 | if (ENABLE_FEATURE_MOUNT_FLAGS && |
1505 | (i & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE ))) | 1508 | (i & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE ))) |
1506 | { | 1509 | { |
1507 | rc = mount("", argv[optind], "", i, ""); | 1510 | rc = mount("", argv[0], "", i, ""); |
1508 | if (rc) bb_perror_msg_and_die("%s", argv[optind]); | 1511 | if (rc) bb_perror_msg_and_die("%s", argv[0]); |
1509 | goto clean_up; | 1512 | goto clean_up; |
1510 | } | 1513 | } |
1511 | 1514 | ||
@@ -1533,13 +1536,13 @@ int mount_main(int argc, char **argv) | |||
1533 | { | 1536 | { |
1534 | // Were we looking for something specific? | 1537 | // Were we looking for something specific? |
1535 | 1538 | ||
1536 | if (optind != argc) { | 1539 | if (argc) { |
1537 | 1540 | ||
1538 | // If we didn't find anything, complain. | 1541 | // If we didn't find anything, complain. |
1539 | 1542 | ||
1540 | if (!mtnext->mnt_fsname) | 1543 | if (!mtnext->mnt_fsname) |
1541 | bb_error_msg_and_die("can't find %s in %s", | 1544 | bb_error_msg_and_die("can't find %s in %s", |
1542 | argv[optind], fstabname); | 1545 | argv[0], fstabname); |
1543 | 1546 | ||
1544 | // Mount the last thing we found. | 1547 | // Mount the last thing we found. |
1545 | 1548 | ||
@@ -1556,13 +1559,13 @@ int mount_main(int argc, char **argv) | |||
1556 | * skip it. Note we must match both the exact text in fstab (ala | 1559 | * skip it. Note we must match both the exact text in fstab (ala |
1557 | * "proc") or a full path from root */ | 1560 | * "proc") or a full path from root */ |
1558 | 1561 | ||
1559 | if (optind != argc) { | 1562 | if (argc) { |
1560 | 1563 | ||
1561 | // Is this what we're looking for? | 1564 | // Is this what we're looking for? |
1562 | 1565 | ||
1563 | if (strcmp(argv[optind],mtcur->mnt_fsname) && | 1566 | if (strcmp(argv[0],mtcur->mnt_fsname) && |
1564 | strcmp(storage_path,mtcur->mnt_fsname) && | 1567 | strcmp(storage_path,mtcur->mnt_fsname) && |
1565 | strcmp(argv[optind],mtcur->mnt_dir) && | 1568 | strcmp(argv[0],mtcur->mnt_dir) && |
1566 | strcmp(storage_path,mtcur->mnt_dir)) continue; | 1569 | strcmp(storage_path,mtcur->mnt_dir)) continue; |
1567 | 1570 | ||
1568 | // Remember this entry. Something later may have overmounted | 1571 | // Remember this entry. Something later may have overmounted |