diff options
| author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-10-09 11:16:01 +0000 |
|---|---|---|
| committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-10-09 11:16:01 +0000 |
| commit | c446a718d1e60469503d44407c66f49bbd46a7a9 (patch) | |
| tree | 49aeb3988f24c42fcdf45bba9c1862599f58c505 /coreutils | |
| parent | 3e0b7b10e691e3f15b7e1be9dd374947deae739a (diff) | |
| download | busybox-w32-c446a718d1e60469503d44407c66f49bbd46a7a9.tar.gz busybox-w32-c446a718d1e60469503d44407c66f49bbd46a7a9.tar.bz2 busybox-w32-c446a718d1e60469503d44407c66f49bbd46a7a9.zip | |
When lstat returns an error (such as file not found), the value of
st_mode is random garbage (under uClibc), leading to random triggering
of the S_ISDIR() case when the destination will be a normal file which
doesn't exist yet. I.E. checking the return value of lstat is not optional.
git-svn-id: svn://busybox.net/trunk/busybox@11815 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/install.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/coreutils/install.c b/coreutils/install.c index d0460412e..9fcb75405 100644 --- a/coreutils/install.c +++ b/coreutils/install.c | |||
| @@ -51,7 +51,6 @@ static const struct option install_long_options[] = { | |||
| 51 | 51 | ||
| 52 | extern int install_main(int argc, char **argv) | 52 | extern int install_main(int argc, char **argv) |
| 53 | { | 53 | { |
| 54 | struct stat statbuf; | ||
| 55 | mode_t mode; | 54 | mode_t mode; |
| 56 | uid_t uid; | 55 | uid_t uid; |
| 57 | gid_t gid; | 56 | gid_t gid; |
| @@ -59,9 +58,7 @@ extern int install_main(int argc, char **argv) | |||
| 59 | char *uid_str = "-1"; | 58 | char *uid_str = "-1"; |
| 60 | char *mode_str = "0755"; | 59 | char *mode_str = "0755"; |
| 61 | int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; | 60 | int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; |
| 62 | int ret = EXIT_SUCCESS; | 61 | int ret = EXIT_SUCCESS, flags, i, isdir; |
| 63 | int flags; | ||
| 64 | int i; | ||
| 65 | 62 | ||
| 66 | bb_applet_long_options = install_long_options; | 63 | bb_applet_long_options = install_long_options; |
| 67 | bb_opt_complementally = "!s~d:d~s"; | 64 | bb_opt_complementally = "!s~d:d~s"; |
| @@ -112,15 +109,16 @@ extern int install_main(int argc, char **argv) | |||
| 112 | return(ret); | 109 | return(ret); |
| 113 | } | 110 | } |
| 114 | 111 | ||
| 115 | cp_mv_stat2(argv[argc - 1], &statbuf, lstat); | 112 | { |
| 113 | struct stat statbuf; | ||
| 114 | isdir = lstat(argv[argc - 1], &statbuf)<0 | ||
| 115 | ? 0 : S_ISDIR(statbuf.st_mode); | ||
| 116 | } | ||
| 116 | for (i = optind; i < argc - 1; i++) { | 117 | for (i = optind; i < argc - 1; i++) { |
| 117 | unsigned char *dest; | 118 | unsigned char *dest; |
| 118 | 119 | ||
| 119 | if (S_ISDIR(statbuf.st_mode)) { | 120 | dest = argv[argc - 1]; |
| 120 | dest = concat_path_file(argv[argc - 1], basename(argv[i])); | 121 | if (isdir) dest = concat_path_file(argv[argc - 1], basename(argv[i])); |
| 121 | } else { | ||
| 122 | dest = argv[argc - 1]; | ||
| 123 | } | ||
| 124 | ret |= copy_file(argv[i], dest, copy_flags); | 122 | ret |= copy_file(argv[i], dest, copy_flags); |
| 125 | 123 | ||
| 126 | /* Set the file mode */ | 124 | /* Set the file mode */ |
| @@ -140,6 +138,7 @@ extern int install_main(int argc, char **argv) | |||
| 140 | ret = EXIT_FAILURE; | 138 | ret = EXIT_FAILURE; |
| 141 | } | 139 | } |
| 142 | } | 140 | } |
| 141 | if(ENABLE_FEATURE_CLEAN_UP && isdir) free(dest); | ||
| 143 | } | 142 | } |
| 144 | 143 | ||
| 145 | return(ret); | 144 | return(ret); |
