mirror of
https://github.com/sheumann/hush.git
synced 2025-01-14 12:30:40 +00:00
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.
This commit is contained in:
parent
f1048143ee
commit
ae907f38f0
@ -51,7 +51,6 @@ static const struct option install_long_options[] = {
|
|||||||
|
|
||||||
extern int install_main(int argc, char **argv)
|
extern int install_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct stat statbuf;
|
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
@ -59,9 +58,7 @@ extern int install_main(int argc, char **argv)
|
|||||||
char *uid_str = "-1";
|
char *uid_str = "-1";
|
||||||
char *mode_str = "0755";
|
char *mode_str = "0755";
|
||||||
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
|
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
|
||||||
int ret = EXIT_SUCCESS;
|
int ret = EXIT_SUCCESS, flags, i, isdir;
|
||||||
int flags;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
bb_applet_long_options = install_long_options;
|
bb_applet_long_options = install_long_options;
|
||||||
bb_opt_complementally = "!s~d:d~s";
|
bb_opt_complementally = "!s~d:d~s";
|
||||||
@ -112,15 +109,16 @@ extern int install_main(int argc, char **argv)
|
|||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
cp_mv_stat2(argv[argc - 1], &statbuf, lstat);
|
{
|
||||||
|
struct stat statbuf;
|
||||||
|
isdir = lstat(argv[argc - 1], &statbuf)<0
|
||||||
|
? 0 : S_ISDIR(statbuf.st_mode);
|
||||||
|
}
|
||||||
for (i = optind; i < argc - 1; i++) {
|
for (i = optind; i < argc - 1; i++) {
|
||||||
unsigned char *dest;
|
unsigned char *dest;
|
||||||
|
|
||||||
if (S_ISDIR(statbuf.st_mode)) {
|
dest = argv[argc - 1];
|
||||||
dest = concat_path_file(argv[argc - 1], basename(argv[i]));
|
if (isdir) dest = concat_path_file(argv[argc - 1], basename(argv[i]));
|
||||||
} else {
|
|
||||||
dest = argv[argc - 1];
|
|
||||||
}
|
|
||||||
ret |= copy_file(argv[i], dest, copy_flags);
|
ret |= copy_file(argv[i], dest, copy_flags);
|
||||||
|
|
||||||
/* Set the file mode */
|
/* Set the file mode */
|
||||||
@ -140,6 +138,7 @@ extern int install_main(int argc, char **argv)
|
|||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(ENABLE_FEATURE_CLEAN_UP && isdir) free(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(ret);
|
return(ret);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user