diff options
| author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-05-15 01:32:47 +0000 |
|---|---|---|
| committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-05-15 01:32:47 +0000 |
| commit | 68b586c888174ae8046ba8bbfd962898c4c4719b (patch) | |
| tree | 800520f8ae26cb32c4c9739c8c942a17e188fe62 /miscutils | |
| parent | 4a5aa6fdaa5124c06ec664a7ca598919f64532f5 (diff) | |
| download | busybox-w32-68b586c888174ae8046ba8bbfd962898c4c4719b.tar.gz busybox-w32-68b586c888174ae8046ba8bbfd962898c4c4719b.tar.bz2 busybox-w32-68b586c888174ae8046ba8bbfd962898c4c4719b.zip | |
Tito pointed out I'd broken -t (argv[optind] can't be before getulflags),
and replaced the use of system() (and resulting security implications).
git-svn-id: svn://busybox.net/trunk/busybox@10333 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/eject.c | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/miscutils/eject.c b/miscutils/eject.c index df275d74b..8864687e4 100644 --- a/miscutils/eject.c +++ b/miscutils/eject.c | |||
| @@ -26,8 +26,9 @@ | |||
| 26 | 26 | ||
| 27 | #include <fcntl.h> | 27 | #include <fcntl.h> |
| 28 | #include <sys/ioctl.h> | 28 | #include <sys/ioctl.h> |
| 29 | #include <stdlib.h> | ||
| 30 | #include <unistd.h> | 29 | #include <unistd.h> |
| 30 | #include <sys/mount.h> | ||
| 31 | #include <mntent.h> | ||
| 31 | #include "busybox.h" | 32 | #include "busybox.h" |
| 32 | 33 | ||
| 33 | /* various defines swiped from linux/cdrom.h */ | 34 | /* various defines swiped from linux/cdrom.h */ |
| @@ -35,33 +36,28 @@ | |||
| 35 | #define CDROMEJECT 0x5309 /* Ejects the cdrom media */ | 36 | #define CDROMEJECT 0x5309 /* Ejects the cdrom media */ |
| 36 | #define DEFAULT_CDROM "/dev/cdrom" | 37 | #define DEFAULT_CDROM "/dev/cdrom" |
| 37 | 38 | ||
| 38 | #ifdef CONFIG_FEATURE_MTAB_SUPPORT | ||
| 39 | #define MTAB CONFIG_FEATURE_MTAB_FILENAME | ||
| 40 | #else | ||
| 41 | #define MTAB "/proc/mounts" | ||
| 42 | #endif | ||
| 43 | |||
| 44 | extern int eject_main(int argc, char **argv) | 39 | extern int eject_main(int argc, char **argv) |
| 45 | { | 40 | { |
| 46 | unsigned long flags; | 41 | unsigned long flags; |
| 47 | char * command; | 42 | char *device; |
| 48 | char *device=argv[optind] ? : DEFAULT_CDROM; | 43 | struct mntent *m; |
| 49 | 44 | ||
| 50 | flags = bb_getopt_ulflags(argc, argv, "t"); | 45 | flags = bb_getopt_ulflags(argc, argv, "t"); |
| 51 | bb_xasprintf(&command, "umount '%s'", device); | 46 | device=argv[optind] ? : DEFAULT_CDROM; |
| 52 | |||
| 53 | /* validate input before calling system */ | ||
| 54 | if(find_mount_point(device, MTAB)) | ||
| 55 | system(command); | ||
| 56 | 47 | ||
| 48 | if((m = find_mount_point(device, bb_path_mtab_file))) { | ||
| 49 | if(umount(m->mnt_dir)) | ||
| 50 | bb_error_msg_and_die("Can't umount"); | ||
| 51 | #ifdef CONFIG_FEATURE_MTAB_SUPPORT | ||
| 52 | else | ||
| 53 | erase_mtab(m->mnt_fsname); | ||
| 54 | #endif | ||
| 55 | } | ||
| 57 | if (ioctl(bb_xopen( device, | 56 | if (ioctl(bb_xopen( device, |
| 58 | (O_RDONLY | O_NONBLOCK)), | 57 | (O_RDONLY | O_NONBLOCK)), |
| 59 | ( flags ? CDROMCLOSETRAY : CDROMEJECT))) | 58 | ( flags ? CDROMCLOSETRAY : CDROMEJECT))) |
| 60 | { | 59 | { |
| 61 | bb_perror_msg_and_die(device); | 60 | bb_perror_msg_and_die(device); |
| 62 | } | 61 | } |
| 63 | #ifdef CONFIG_FEATURE_CLEAN_UP | ||
| 64 | free(command); | ||
| 65 | #endif | ||
| 66 | return(EXIT_SUCCESS); | 62 | return(EXIT_SUCCESS); |
| 67 | } | 63 | } |
