mirror of
https://github.com/sheumann/hush.git
synced 2024-09-12 15:54:56 +00:00
ar: fix two bugs, one added by prev comment and other we SEGV with no params
cpio: use optind less function old new delta ar_main 189 184 -5 cpio_main 549 533 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-21) Total: -21 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
2ec91aead5
commit
40e5a30b66
@ -49,7 +49,7 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
archive_handle = init_handle();
|
archive_handle = init_handle();
|
||||||
|
|
||||||
/* Prepend '-' to the first argument if required */
|
/* Prepend '-' to the first argument if required */
|
||||||
opt_complementary = "--:p:t:x:-1:p--tx:t--px:x--pt";
|
opt_complementary = "--:-1:p:t:x:-1:p--tx:t--px:x--pt";
|
||||||
opt = getopt32(argv, "ptxovcr");
|
opt = getopt32(argv, "ptxovcr");
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
bb_error_msg_and_die(msg_unsupported_err, "insertion");
|
bb_error_msg_and_die(msg_unsupported_err, "insertion");
|
||||||
}
|
}
|
||||||
|
|
||||||
archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
|
archive_handle->src_fd = xopen(*argv++, O_RDONLY);
|
||||||
|
|
||||||
while (*argv) {
|
while (*argv) {
|
||||||
archive_handle->filter = filter_accept_list;
|
archive_handle->filter = filter_accept_list;
|
||||||
|
@ -307,16 +307,17 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
opt = getopt32(argv, OPTION_STR, &cpio_filename);
|
opt = getopt32(argv, OPTION_STR, &cpio_filename);
|
||||||
#else
|
#else
|
||||||
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
|
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
|
||||||
|
argv += optind;
|
||||||
if (opt & CPIO_OPT_PASSTHROUGH) {
|
if (opt & CPIO_OPT_PASSTHROUGH) {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
struct fd_pair pp;
|
struct fd_pair pp;
|
||||||
|
|
||||||
if (argv[optind] == NULL)
|
if (argv[0] == NULL)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
if (opt & CPIO_OPT_CREATE_LEADING_DIR)
|
if (opt & CPIO_OPT_CREATE_LEADING_DIR)
|
||||||
mkdir(argv[optind], 0777);
|
mkdir(argv[0], 0777);
|
||||||
/* Crude existence check:
|
/* Crude existence check:
|
||||||
* close(xopen(argv[optind], O_RDONLY | O_DIRECTORY));
|
* close(xopen(argv[0], O_RDONLY | O_DIRECTORY));
|
||||||
* We can also xopen, fstat, IS_DIR, later fchdir.
|
* We can also xopen, fstat, IS_DIR, later fchdir.
|
||||||
* This would check for existence earlier and cleaner.
|
* This would check for existence earlier and cleaner.
|
||||||
* As it stands now, if we fail xchdir later,
|
* As it stands now, if we fail xchdir later,
|
||||||
@ -335,14 +336,14 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
#else
|
#else
|
||||||
xpiped_pair(pp);
|
xpiped_pair(pp);
|
||||||
#endif
|
#endif
|
||||||
pid = fork_or_rexec(argv);
|
pid = fork_or_rexec(argv - optind);
|
||||||
if (pid == 0) { /* child */
|
if (pid == 0) { /* child */
|
||||||
close(pp.rd);
|
close(pp.rd);
|
||||||
xmove_fd(pp.wr, STDOUT_FILENO);
|
xmove_fd(pp.wr, STDOUT_FILENO);
|
||||||
goto dump;
|
goto dump;
|
||||||
}
|
}
|
||||||
/* parent */
|
/* parent */
|
||||||
xchdir(argv[optind++]);
|
xchdir(*argv++);
|
||||||
close(pp.wr);
|
close(pp.wr);
|
||||||
xmove_fd(pp.rd, STDIN_FILENO);
|
xmove_fd(pp.rd, STDIN_FILENO);
|
||||||
opt &= ~CPIO_OPT_PASSTHROUGH;
|
opt &= ~CPIO_OPT_PASSTHROUGH;
|
||||||
@ -361,7 +362,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
skip:
|
skip:
|
||||||
#endif
|
#endif
|
||||||
argv += optind;
|
|
||||||
|
|
||||||
archive_handle = init_handle();
|
archive_handle = init_handle();
|
||||||
archive_handle->src_fd = STDIN_FILENO;
|
archive_handle->src_fd = STDIN_FILENO;
|
||||||
@ -407,7 +407,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
while (*argv) {
|
while (*argv) {
|
||||||
archive_handle->filter = filter_accept_list;
|
archive_handle->filter = filter_accept_list;
|
||||||
llist_add_to(&(archive_handle->accept), *argv);
|
llist_add_to(&archive_handle->accept, *argv);
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user