diff options
author | Ron Yorston <rmy@pobox.com> | 2017-01-08 08:56:43 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2017-01-08 08:56:43 +0000 |
commit | 3ef86d069577b8a44ebe3aa890c6e97ea31d0d56 (patch) | |
tree | 064587c9b2080dba963bf8d93861b8019cb306ed /shell | |
parent | c66975af0b5335b9cdd156206767756237bd814b (diff) | |
parent | 86584e134eec1a81298149f8c04c77727f6dccb9 (diff) | |
download | busybox-w32-3ef86d069577b8a44ebe3aa890c6e97ea31d0d56.tar.gz busybox-w32-3ef86d069577b8a44ebe3aa890c6e97ea31d0d56.tar.bz2 busybox-w32-3ef86d069577b8a44ebe3aa890c6e97ea31d0d56.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'shell')
-rw-r--r-- | shell/Config.src | 27 | ||||
-rw-r--r-- | shell/ash.c | 18 | ||||
-rw-r--r-- | shell/ash_test/ash-redir/redir_leak.right | 6 | ||||
-rwxr-xr-x | shell/ash_test/ash-redir/redir_leak.tests | 10 | ||||
-rw-r--r-- | shell/hush_test/hush-redir/redir_leak.right | 6 | ||||
-rwxr-xr-x | shell/hush_test/hush-redir/redir_leak.tests | 10 |
6 files changed, 72 insertions, 5 deletions
diff --git a/shell/Config.src b/shell/Config.src index 7f5f67050..3545f05dd 100644 --- a/shell/Config.src +++ b/shell/Config.src | |||
@@ -17,9 +17,19 @@ choice | |||
17 | config SH_IS_ASH | 17 | config SH_IS_ASH |
18 | depends on !NOMMU | 18 | depends on !NOMMU |
19 | bool "ash" | 19 | bool "ash" |
20 | help | ||
21 | Choose ash to be the shell executed by 'sh' name. | ||
22 | The ash code will be built into busybox. If you don't select | ||
23 | "ash" choice (CONFIG_ASH), this shell may only be invoked by | ||
24 | the name 'sh' (and not 'ash'). | ||
20 | 25 | ||
21 | config SH_IS_HUSH | 26 | config SH_IS_HUSH |
22 | bool "hush" | 27 | bool "hush" |
28 | help | ||
29 | Choose hush to be the shell executed by 'sh' name. | ||
30 | The hush code will be built into busybox. If you don't select | ||
31 | "hush" choice (CONFIG_HUSH), this shell may only be invoked by | ||
32 | the name 'sh' (and not 'hush'). | ||
23 | 33 | ||
24 | config SH_IS_NONE | 34 | config SH_IS_NONE |
25 | bool "none" | 35 | bool "none" |
@@ -31,7 +41,8 @@ choice | |||
31 | default BASH_IS_NONE | 41 | default BASH_IS_NONE |
32 | help | 42 | help |
33 | Choose which shell you want to be executed by 'bash' alias. | 43 | Choose which shell you want to be executed by 'bash' alias. |
34 | The ash shell is the most bash compatible and full featured one. | 44 | The ash shell is the most bash compatible and full featured one, |
45 | although compatibility is far from being complete. | ||
35 | 46 | ||
36 | Note that selecting this option does not switch on any bash | 47 | Note that selecting this option does not switch on any bash |
37 | compatibility code. It merely makes it possible to install | 48 | compatibility code. It merely makes it possible to install |
@@ -46,9 +57,19 @@ choice | |||
46 | config BASH_IS_ASH | 57 | config BASH_IS_ASH |
47 | depends on !NOMMU | 58 | depends on !NOMMU |
48 | bool "ash" | 59 | bool "ash" |
60 | help | ||
61 | Choose ash to be the shell executed by 'bash' name. | ||
62 | The ash code will be built into busybox. If you don't select | ||
63 | "ash" choice (CONFIG_ASH), this shell may only be invoked by | ||
64 | the name 'bash' (and not 'ash'). | ||
49 | 65 | ||
50 | config BASH_IS_HUSH | 66 | config BASH_IS_HUSH |
51 | bool "hush" | 67 | bool "hush" |
68 | help | ||
69 | Choose hush to be the shell executed by 'bash' name. | ||
70 | The hush code will be built into busybox. If you don't select | ||
71 | "hush" choice (CONFIG_HUSH), this shell may only be invoked by | ||
72 | the name 'bash' (and not 'hush'). | ||
52 | 73 | ||
53 | config BASH_IS_NONE | 74 | config BASH_IS_NONE |
54 | bool "none" | 75 | bool "none" |
@@ -59,6 +80,9 @@ endchoice | |||
59 | INSERT | 80 | INSERT |
60 | 81 | ||
61 | 82 | ||
83 | comment "Options common to all shells" | ||
84 | if ASH || HUSH || SH_IS_ASH || BASH_IS_ASH || SH_IS_HUSH || BASH_IS_HUSH | ||
85 | |||
62 | config FEATURE_SH_MATH | 86 | config FEATURE_SH_MATH |
63 | bool "POSIX math support" | 87 | bool "POSIX math support" |
64 | default y | 88 | default y |
@@ -142,5 +166,6 @@ config FEATURE_SH_HISTFILESIZE | |||
142 | to set shell history size. Note that its max value is capped | 166 | to set shell history size. Note that its max value is capped |
143 | by "History size" setting in library tuning section. | 167 | by "History size" setting in library tuning section. |
144 | 168 | ||
169 | endif # Options common to all shells | ||
145 | 170 | ||
146 | endmenu | 171 | endmenu |
diff --git a/shell/ash.c b/shell/ash.c index 35618937a..fe185f5d9 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -41,6 +41,11 @@ | |||
41 | //config: shell (by Herbert Xu), which was created by porting the 'ash' shell | 41 | //config: shell (by Herbert Xu), which was created by porting the 'ash' shell |
42 | //config: (written by Kenneth Almquist) from NetBSD. | 42 | //config: (written by Kenneth Almquist) from NetBSD. |
43 | //config: | 43 | //config: |
44 | //config:# ash options | ||
45 | //config:# note: Don't remove !NOMMU part in the next line; it would break | ||
46 | //config:# menuconfig's indenting. | ||
47 | //config:if !NOMMU && (ASH || SH_IS_ASH || BASH_IS_ASH) | ||
48 | //config: | ||
44 | //config:config ASH_OPTIMIZE_FOR_SIZE | 49 | //config:config ASH_OPTIMIZE_FOR_SIZE |
45 | //config: bool "Optimize for size instead of speed" | 50 | //config: bool "Optimize for size instead of speed" |
46 | //config: default y | 51 | //config: default y |
@@ -155,6 +160,8 @@ | |||
155 | //config: depends on ASH || SH_IS_ASH || BASH_IS_ASH | 160 | //config: depends on ASH || SH_IS_ASH || BASH_IS_ASH |
156 | //config: help | 161 | //config: help |
157 | //config: Enable "check for new mail" function in the ash shell. | 162 | //config: Enable "check for new mail" function in the ash shell. |
163 | //config: | ||
164 | //config:endif # ash options | ||
158 | 165 | ||
159 | //applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP)) | 166 | //applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP)) |
160 | //applet:IF_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, ash)) | 167 | //applet:IF_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, ash)) |
@@ -5778,11 +5785,11 @@ redirect(union node *redir, int flags) | |||
5778 | /* Careful to not accidentally "save" | 5785 | /* Careful to not accidentally "save" |
5779 | * to the same fd as right side fd in N>&M */ | 5786 | * to the same fd as right side fd in N>&M */ |
5780 | int minfd = right_fd < 10 ? 10 : right_fd + 1; | 5787 | int minfd = right_fd < 10 ? 10 : right_fd + 1; |
5788 | #if defined(F_DUPFD_CLOEXEC) | ||
5789 | i = fcntl(fd, F_DUPFD_CLOEXEC, minfd); | ||
5790 | #else | ||
5781 | i = fcntl(fd, F_DUPFD, minfd); | 5791 | i = fcntl(fd, F_DUPFD, minfd); |
5782 | /* You'd expect copy to be CLOEXECed. Currently these extra "saved" fds | 5792 | #endif |
5783 | * are closed in popredir() in the child, preventing them from leaking | ||
5784 | * into child. (popredir() also cleans up the mess in case of failures) | ||
5785 | */ | ||
5786 | if (i == -1) { | 5793 | if (i == -1) { |
5787 | i = errno; | 5794 | i = errno; |
5788 | if (i != EBADF) { | 5795 | if (i != EBADF) { |
@@ -5797,6 +5804,9 @@ redirect(union node *redir, int flags) | |||
5797 | remember_to_close: | 5804 | remember_to_close: |
5798 | i = CLOSED; | 5805 | i = CLOSED; |
5799 | } else { /* fd is open, save its copy */ | 5806 | } else { /* fd is open, save its copy */ |
5807 | #if !defined(F_DUPFD_CLOEXEC) | ||
5808 | fcntl(i, F_SETFD, FD_CLOEXEC); | ||
5809 | #endif | ||
5800 | /* "exec fd>&-" should not close fds | 5810 | /* "exec fd>&-" should not close fds |
5801 | * which point to script file(s). | 5811 | * which point to script file(s). |
5802 | * Force them to be restored afterwards */ | 5812 | * Force them to be restored afterwards */ |
diff --git a/shell/ash_test/ash-redir/redir_leak.right b/shell/ash_test/ash-redir/redir_leak.right new file mode 100644 index 000000000..b1c48292b --- /dev/null +++ b/shell/ash_test/ash-redir/redir_leak.right | |||
@@ -0,0 +1,6 @@ | |||
1 | 4 | ||
2 | 4 | ||
3 | 4 | ||
4 | 4 | ||
5 | 4 | ||
6 | 4 | ||
diff --git a/shell/ash_test/ash-redir/redir_leak.tests b/shell/ash_test/ash-redir/redir_leak.tests new file mode 100755 index 000000000..c8a9c6343 --- /dev/null +++ b/shell/ash_test/ash-redir/redir_leak.tests | |||
@@ -0,0 +1,10 @@ | |||
1 | # Each of these should show only four lines: | ||
2 | # fds 0,1,2 are stdio; fd 3 is open by opendir() in ls. | ||
3 | # This test detects bugs where redirects leave stray open fds. | ||
4 | |||
5 | ls -1 /proc/self/fd | wc -l | ||
6 | ls -1 /proc/self/fd >/proc/self/fd/1 | wc -l | ||
7 | ls -1 /proc/self/fd >/proc/self/fd/1 2>&1 | wc -l | ||
8 | echo "`ls -1 /proc/self/fd `" | wc -l | ||
9 | echo "`ls -1 /proc/self/fd >/proc/self/fd/1 `" | wc -l | ||
10 | echo "`ls -1 /proc/self/fd >/proc/self/fd/1 2>&1 `" | wc -l | ||
diff --git a/shell/hush_test/hush-redir/redir_leak.right b/shell/hush_test/hush-redir/redir_leak.right new file mode 100644 index 000000000..b1c48292b --- /dev/null +++ b/shell/hush_test/hush-redir/redir_leak.right | |||
@@ -0,0 +1,6 @@ | |||
1 | 4 | ||
2 | 4 | ||
3 | 4 | ||
4 | 4 | ||
5 | 4 | ||
6 | 4 | ||
diff --git a/shell/hush_test/hush-redir/redir_leak.tests b/shell/hush_test/hush-redir/redir_leak.tests new file mode 100755 index 000000000..c8a9c6343 --- /dev/null +++ b/shell/hush_test/hush-redir/redir_leak.tests | |||
@@ -0,0 +1,10 @@ | |||
1 | # Each of these should show only four lines: | ||
2 | # fds 0,1,2 are stdio; fd 3 is open by opendir() in ls. | ||
3 | # This test detects bugs where redirects leave stray open fds. | ||
4 | |||
5 | ls -1 /proc/self/fd | wc -l | ||
6 | ls -1 /proc/self/fd >/proc/self/fd/1 | wc -l | ||
7 | ls -1 /proc/self/fd >/proc/self/fd/1 2>&1 | wc -l | ||
8 | echo "`ls -1 /proc/self/fd `" | wc -l | ||
9 | echo "`ls -1 /proc/self/fd >/proc/self/fd/1 `" | wc -l | ||
10 | echo "`ls -1 /proc/self/fd >/proc/self/fd/1 2>&1 `" | wc -l | ||