diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-08-19 18:23:56 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-08-19 18:43:06 +0200 |
commit | 215b0ca6e4fe466c6942d21a1bba62d97f2d5e5d (patch) | |
tree | 4fbb9563d870ce8a5f8f08015424e358a1462677 /libbb/appletlib.c | |
parent | aedc3fe19fac368dc363050e0387d263b7e01cc6 (diff) | |
download | busybox-w32-215b0ca6e4fe466c6942d21a1bba62d97f2d5e5d.tar.gz busybox-w32-215b0ca6e4fe466c6942d21a1bba62d97f2d5e5d.tar.bz2 busybox-w32-215b0ca6e4fe466c6942d21a1bba62d97f2d5e5d.zip |
hush: fix a bug in FEATURE_SH_STANDALONE=y config. Closes 9186
Run this in a "sh SCRIPT":
sha256sum /dev/null
echo END
sha256sum is a NOEXEC applet. It runs in a forked child. Then child exit()s.
By this time, entire script is read, and buffered in a FILE object
from fopen("SCRIPT"). But fgetc() did not consume entire input.
exit() lseeks back by -9 bytes, from <eof> to 'e' in 'echo'.
(this may be libc-specific).
This change of fd position *is shared with the parent*!
Now parent can read more, and it thinks there is another "echo END".
End result: two "echo END"s are run.
Fix this by _exit()ing instead.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r-- | libbb/appletlib.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index c341817e2..f760af2cb 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -877,7 +877,9 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) | |||
877 | } | 877 | } |
878 | if (ENABLE_FEATURE_SUID) | 878 | if (ENABLE_FEATURE_SUID) |
879 | check_suid(applet_no); | 879 | check_suid(applet_no); |
880 | exit(applet_main[applet_no](argc, argv)); | 880 | xfunc_error_retval = applet_main[applet_no](argc, argv); |
881 | /* Note: applet_main() may also not return (die on a xfunc or such) */ | ||
882 | xfunc_die(); | ||
881 | } | 883 | } |
882 | # endif /* NUM_APPLETS > 0 */ | 884 | # endif /* NUM_APPLETS > 0 */ |
883 | 885 | ||