Compare commits

...
10 Commits
Author SHA1 Message Date
Denys Vlasenko 509f987e16 Bump version to 1.28.4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-22 17:53:09 +02:00
Euan Harris d591256a5c nsenter: fix parsing of -t, -S and -G options
-t, -S and -G each take mandatory integer arguments.   getopt32long()'s
option string syntax for this type of argument is 'c:+', however nsenter's
opt_str uses 'c+', which specifies two options 'c' and '+' which do not
take arguments.   This means that giving a target PID causes nsenter to
exit and print the usage string:

  # nsenter -t1 sh
  nsenter: unrecognized option: 1
  BusyBox v1.27.2 (2017-12-12 10:41:50 GMT) multi-call binary.
  ...

The long form options are also broken:

  # nsenter --setuid=1000 --setgid=1000 sh
  BusyBox v1.29.0.git (2018-05-04 13:56:49 UTC) multi-call binary.
  ...

`nsenter --target=<pid> sh` parses correctly and appears to work, but
<pid> is ignored and set to 0.   This doesn't raise an error unless one
of the namespace arguments is also given:

  # ./busybox_unstripped nsenter --target=42 sh
  # exit

  # ./busybox_unstripped nsenter -n --target=42 sh
  BusyBox v1.29.0.git (2018-05-04 13:56:49 UTC) multi-call binary.
  ...

This has caused problems in a couple of places:

  https://github.com/linuxkit/linuxkit/issues/567
  https://github.com/gliderlabs/docker-alpine/issues/359
  https://github.com/kontena/pharos-cluster/pull/81

Signed-off-by: Euan Harris <euan.harris@docker.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-22 17:52:51 +02:00
Euan Harris adb69765e5 nsenter: Rename --network option to --net
In nsenter from util-linux, the long version of the -n option is
--net=<path>.   BusyBox's version expects --network=<path>, so scripts
and examples written for util-linux's version cause BusyBox's version
to exit with the usage message.

Confusingly, until commit 036585a911, the usage message erroneously
claimed that the long option was indeed called --net; after that commit
long options are not listed at all.

Signed-off-by: Euan Harris <euan.harris@docker.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-22 17:52:51 +02:00
Denys Vlasenko 70baf859a6 dpkg: fix symlink creation, closes 10941
function                                             old     new   delta
get_header_ar                                        434     442      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-05-22 17:52:51 +02:00
Denys Vlasenko 2c5ceb6065 Bump version to 1.28.3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 13:04:47 +02:00
Denys Vlasenko e04a38c0c9 hush: fix a signedness bug
Testcase:

set -- a ""; space=" "; printf "<%s>\n" "$@"$space

Before:
<a >
After:
<a>
<>

It usually does not bite since bbox forces -funsigned-char build.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 13:04:11 +02:00
Denys Vlasenko 78ee8fc3e4 ash: fix "char == CTLfoo" comparison signedness bug
It usually does not bite since bbox forces -funsigned-char build.
But for some reason void linux people disabled that.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 13:04:11 +02:00
Natanael Copa 08cbe510dd cpio: extract "unsafe" symlinks the same way tar/unzip does
function                                             old     new   delta
cpio_main                                            588     596      +8

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 13:04:11 +02:00
Denys Vlasenko af874cc63e grep: fix echo "aa" | busybox grep -F -w "a" (should not match)
function                                             old     new   delta
grep_file                                           1461    1470      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 13:04:11 +02:00
Denys Vlasenko b1aa377a3f ash,hush: fix "saved" redirected fds still visible in children
Based on a patch by Mark Marshall <mark.marshall@omicronenergy.com>

function                                             old     new   delta
dup_CLOEXEC                                            -      49     +49
fcntl_F_DUPFD                                         46       -     -46

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-01 13:04:11 +02:00
20 changed files with 111 additions and 22 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 28
SUBLEVEL = 1
SUBLEVEL = 4
EXTRAVERSION =
NAME = Unnamed
+2
View File
@@ -508,6 +508,8 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
create_symlinks_from_list(archive_handle->symlink_placeholders);
if (archive_handle->cpio__blocks != (off_t)-1
&& !(opt & OPT_QUIET)
) {
+3 -1
View File
@@ -127,8 +127,10 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
archive_handle->action_header(typed);
#if ENABLE_DPKG || ENABLE_DPKG_DEB
if (archive_handle->dpkg__sub_archive) {
while (archive_handle->dpkg__action_data_subarchive(archive_handle->dpkg__sub_archive) == EXIT_SUCCESS)
struct archive_handle_t *sa = archive_handle->dpkg__sub_archive;
while (archive_handle->dpkg__action_data_subarchive(sa) == EXIT_SUCCESS)
continue;
create_symlinks_from_list(sa->symlink_placeholders);
} else
#endif
archive_handle->action_data(archive_handle);
+1 -1
View File
@@ -352,7 +352,7 @@ static int grep_file(FILE *file)
goto opt_f_not_found;
} else
if (option_mask32 & OPT_w) {
char c = (match != str) ? match[-1] : ' ';
char c = (match != line) ? match[-1] : ' ';
if (!isalnum(c) && c != '_') {
c = match[strlen(gl->pattern)];
if (!c || (!isalnum(c) && c != '_'))
+14 -8
View File
@@ -239,6 +239,9 @@ typedef long arith_t;
# define IF_NOT_FEATURE_SH_STANDALONE(...) __VA_ARGS__
#endif
#ifndef F_DUPFD_CLOEXEC
# define F_DUPFD_CLOEXEC F_DUPFD
#endif
#ifndef PIPE_BUF
# define PIPE_BUF 4096 /* amount of buffering in a pipe */
#endif
@@ -5392,12 +5395,15 @@ dup2_or_raise(int from, int to)
return newfd;
}
static int
fcntl_F_DUPFD(int fd, int avoid_fd)
dup_CLOEXEC(int fd, int avoid_fd)
{
int newfd;
repeat:
newfd = fcntl(fd, F_DUPFD, avoid_fd + 1);
if (newfd < 0) {
newfd = fcntl(fd, F_DUPFD_CLOEXEC, avoid_fd + 1);
if (newfd >= 0) {
if (F_DUPFD_CLOEXEC == F_DUPFD) /* if old libc (w/o F_DUPFD_CLOEXEC) */
fcntl(newfd, F_SETFD, FD_CLOEXEC);
} else { /* newfd < 0 */
if (errno == EBUSY)
goto repeat;
if (errno == EINTR)
@@ -5513,7 +5519,7 @@ save_fd_on_redirect(int fd, int avoid_fd, struct redirtab *sq)
for (i = 0; sq->two_fd[i].orig_fd != EMPTY; i++) {
/* If we collide with an already moved fd... */
if (fd == sq->two_fd[i].moved_to) {
new_fd = fcntl_F_DUPFD(fd, avoid_fd);
new_fd = dup_CLOEXEC(fd, avoid_fd);
sq->two_fd[i].moved_to = new_fd;
TRACE(("redirect_fd %d: already busy, moving to %d\n", fd, new_fd));
if (new_fd < 0) /* what? */
@@ -5528,7 +5534,7 @@ save_fd_on_redirect(int fd, int avoid_fd, struct redirtab *sq)
}
/* If this fd is open, we move and remember it; if it's closed, new_fd = CLOSED (-1) */
new_fd = fcntl_F_DUPFD(fd, avoid_fd);
new_fd = dup_CLOEXEC(fd, avoid_fd);
TRACE(("redirect_fd %d: previous fd is moved to %d (-1 if it was closed)\n", fd, new_fd));
if (new_fd < 0) {
if (errno != EBADF)
@@ -7312,13 +7318,13 @@ hasmeta(const char *p)
p = strpbrk(p, chars);
if (!p)
break;
switch ((unsigned char) *p) {
switch ((unsigned char)*p) {
case CTLQUOTEMARK:
for (;;) {
p++;
if (*p == CTLQUOTEMARK)
if ((unsigned char)*p == CTLQUOTEMARK)
break;
if (*p == CTLESC)
if ((unsigned char)*p == CTLESC)
p++;
if (*p == '\0') /* huh? */
return 0;
@@ -0,0 +1,5 @@
/proc/self/fd
/proc/self/fd/0
/proc/self/fd/1
/proc/self/fd/2
/proc/self/fd/3
@@ -0,0 +1,6 @@
# The "find" should not see "saved" (duplicated) fd #1
# Explicitly use bbox find, since other implementations of "find"
# may open other descriptors as well.
busybox find /proc/self/fd >tmp_$$.out
cat tmp_$$.out
rm -f tmp_$$.out
@@ -0,0 +1,5 @@
/proc/self/fd
/proc/self/fd/0
/proc/self/fd/1
/proc/self/fd/2
/proc/self/fd/3
@@ -0,0 +1,6 @@
# The "find" should not see "saved" (duplicated) fd #1
# Explicitly use bbox find, since other implementations of "find"
# may open other descriptors as well.
{ busybox find /proc/self/fd; } >tmp_$$.out
cat tmp_$$.out
rm -f tmp_$$.out
@@ -0,0 +1,5 @@
/proc/self/fd
/proc/self/fd/0
/proc/self/fd/1
/proc/self/fd/2
/proc/self/fd/3
@@ -0,0 +1,6 @@
# The "find" should not see "saved" (duplicated) fd #1
# Explicitly use bbox find, since other implementations of "find"
# may open other descriptors as well.
{ busybox find /proc/self/fd; true; } >tmp_$$.out
cat tmp_$$.out
rm -f tmp_$$.out
+16 -9
View File
@@ -1478,12 +1478,15 @@ static void free_strings(char **strings)
free(strings);
}
static int fcntl_F_DUPFD(int fd, int avoid_fd)
static int dup_CLOEXEC(int fd, int avoid_fd)
{
int newfd;
repeat:
newfd = fcntl(fd, F_DUPFD, avoid_fd + 1);
if (newfd < 0) {
newfd = fcntl(fd, F_DUPFD_CLOEXEC, avoid_fd + 1);
if (newfd >= 0) {
if (F_DUPFD_CLOEXEC == F_DUPFD) /* if old libc (w/o F_DUPFD_CLOEXEC) */
fcntl(newfd, F_SETFD, FD_CLOEXEC);
} else { /* newfd < 0 */
if (errno == EBUSY)
goto repeat;
if (errno == EINTR)
@@ -6012,7 +6015,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
} else
/* If EXP_FLAG_SINGLEWORD, we handle assignment 'a=....$@.....'
* and in this case should treat it like '$*' - see 'else...' below */
if (first_ch == ('@'|0x80) /* quoted $@ */
if (first_ch == (char)('@'|0x80) /* quoted $@ */
&& !(output->o_expflags & EXP_FLAG_SINGLEWORD) /* not v="$@" case */
) {
while (1) {
@@ -6766,7 +6769,7 @@ static struct squirrel *add_squirrel(struct squirrel *sq, int fd, int avoid_fd)
if (sq) for (; sq[i].orig_fd >= 0; i++) {
/* If we collide with an already moved fd... */
if (fd == sq[i].moved_to) {
sq[i].moved_to = fcntl_F_DUPFD(sq[i].moved_to, avoid_fd);
sq[i].moved_to = dup_CLOEXEC(sq[i].moved_to, avoid_fd);
debug_printf_redir("redirect_fd %d: already busy, moving to %d\n", fd, sq[i].moved_to);
if (sq[i].moved_to < 0) /* what? */
xfunc_die();
@@ -6780,7 +6783,7 @@ static struct squirrel *add_squirrel(struct squirrel *sq, int fd, int avoid_fd)
}
/* If this fd is open, we move and remember it; if it's closed, moved_to = -1 */
moved_to = fcntl_F_DUPFD(fd, avoid_fd);
moved_to = dup_CLOEXEC(fd, avoid_fd);
debug_printf_redir("redirect_fd %d: previous fd is moved to %d (-1 if it was closed)\n", fd, moved_to);
if (moved_to < 0 && errno != EBADF)
xfunc_die();
@@ -7429,6 +7432,10 @@ static NOINLINE void pseudo_exec_argv(nommu_save_t *nommu_save,
*/
close_saved_fds_and_FILE_fds();
//FIXME: should also close saved redir fds
//This casuses test failures in
//redir_children_should_not_see_saved_fd_2.tests
//redir_children_should_not_see_saved_fd_3.tests
//if you replace "busybox find" with just "find" in them
/* Without this, "rm -i FILE" can't be ^C'ed: */
switch_off_special_sigs(G.special_sig_mask);
debug_printf_exec("running applet '%s'\n", argv[0]);
@@ -9133,7 +9140,7 @@ int hush_main(int argc, char **argv)
G_saved_tty_pgrp = 0;
/* try to dup stdin to high fd#, >= 255 */
G_interactive_fd = fcntl_F_DUPFD(STDIN_FILENO, 254);
G_interactive_fd = dup_CLOEXEC(STDIN_FILENO, 254);
if (G_interactive_fd < 0) {
/* try to dup to any fd */
G_interactive_fd = dup(STDIN_FILENO);
@@ -9206,10 +9213,10 @@ int hush_main(int argc, char **argv)
#elif ENABLE_HUSH_INTERACTIVE
/* No job control compiled in, only prompt/line editing */
if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) {
G_interactive_fd = fcntl_F_DUPFD(STDIN_FILENO, 254);
G_interactive_fd = dup_CLOEXEC(STDIN_FILENO, 254);
if (G_interactive_fd < 0) {
/* try to dup to any fd */
G_interactive_fd = dup(STDIN_FILENO);
G_interactive_fd = dup_CLOEXEC(STDIN_FILENO);
if (G_interactive_fd < 0)
/* give up */
G_interactive_fd = 0;
@@ -0,0 +1,5 @@
/proc/self/fd
/proc/self/fd/0
/proc/self/fd/1
/proc/self/fd/2
/proc/self/fd/3
@@ -0,0 +1,6 @@
# The "find" should not see "saved" (duplicated) fd #1
# Explicitly use bbox find, since other implementations of "find"
# may open other descriptors as well.
busybox find /proc/self/fd >tmp_$$.out
cat tmp_$$.out
rm -f tmp_$$.out
@@ -0,0 +1,5 @@
/proc/self/fd
/proc/self/fd/0
/proc/self/fd/1
/proc/self/fd/2
/proc/self/fd/3
@@ -0,0 +1,6 @@
# The "find" should not see "saved" (duplicated) fd #1
# Explicitly use bbox find, since other implementations of "find"
# may open other descriptors as well.
{ busybox find /proc/self/fd; } >tmp_$$.out
cat tmp_$$.out
rm -f tmp_$$.out
@@ -0,0 +1,5 @@
/proc/self/fd
/proc/self/fd/0
/proc/self/fd/1
/proc/self/fd/2
/proc/self/fd/3
@@ -0,0 +1,6 @@
# The "find" should not see "saved" (duplicated) fd #1
# Explicitly use bbox find, since other implementations of "find"
# may open other descriptors as well.
{ busybox find /proc/self/fd; true; } >tmp_$$.out
cat tmp_$$.out
rm -f tmp_$$.out
+6
View File
@@ -165,6 +165,12 @@ testing "grep -w word doesn't match wordword" \
"wordword\n" \
""
testing "grep -F -w w doesn't match ww" \
"grep -F -w w input" \
"" \
"ww\n" \
""
testing "grep -w word match second word" \
"grep -w word input" \
"bword,word\n""wordb,word\n""bwordb,word\n" \
+2 -2
View File
@@ -105,14 +105,14 @@ static const struct namespace_descr ns_list[] = {
/*
* Upstream nsenter doesn't support the short option for --preserve-credentials
*/
static const char opt_str[] ALIGN1 = "U::i::u::n::p::m::""t+S+G+r::w::F";
static const char opt_str[] ALIGN1 = "U::i::u::n::p::m::""t:+S:+G:+r::w::F";
#if ENABLE_LONG_OPTS
static const char nsenter_longopts[] ALIGN1 =
"user\0" Optional_argument "U"
"ipc\0" Optional_argument "i"
"uts\0" Optional_argument "u"
"network\0" Optional_argument "n"
"net\0" Optional_argument "n"
"pid\0" Optional_argument "p"
"mount\0" Optional_argument "m"
"target\0" Required_argument "t"