aboutsummaryrefslogtreecommitdiff
path: root/shell (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* | ash: enforce ';' separator in CDPATH and MANPATH variablesRon Yorston2019-03-161-11/+23
| | | | | | | | | | | | | | | | | | | | Commit a23624237 (win32: special treatment for PATH) required the PATH variable to use ';' as the separator between components and enforced this by intercepting attempts to update it. Do the same for the CDPATH and MANPATH variables. Also, fix a case in cdcmd() where the wrong separator was used.
* | ash: set current working directory on startupRon Yorston2019-03-151-0/+7
| | | | | | | | | | | | | | | | | | | | | | When the shell starts behave as though the user had manually changed to the current working directory of the process, but only if it's an interactive, non-login shell and the '-d' flag isn't present. This gives more consistent behaviour when the shell is started in a drive mapped to a network share or a symlinked directory. This completes the changes requested in GitHub issue #148.
* | win32: add function to convert slashes to backslashesRon Yorston2019-03-151-2/+2
| | | | | | | | | | | | | | | | | | There are now two places where slashes are converted to backslashes throughout a string so it makes sense to create a function to do this. To avoid confusion rename convert_slashes() to bs_to_slash() and call the new function slash_to_bs().
* | Merge branch 'busybox' into mergeRon Yorston2019-03-121-10/+4
|\|
| * ash: eval: avoid leaking memory associated with redirections. Closes 7748Ron Yorston2019-02-251-10/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following constructs result in ever-increasing memory usage: while true; do { true; } </dev/null; done while true; do ( true; ) </dev/null; done For comparison, bash displays static memory usage in both cases. This has been fixed in dash by commit 2bc6caa. The maintainer writes: I have simplified evaltree so that it simply sets the stack mark unconditionally. This allows us to remove the stack marks in the functions called by evaltree. Closes BusyBox bug 7748. function old new delta evaltree 606 632 +26 evalcommand 1724 1696 -28 evalcase 382 351 -31 evalfor 230 196 -34 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 26/-93) Total: -67 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: improve handling of UNC pathsRon Yorston2019-03-111-8/+35
| | | | | | | | | | | | | | | | | | | | | | Rework the code in updatepwd() which processes UNC paths so that the root of a share is properly identified. This fixes problems when: - the current directory is a share and the user changes to '/'; - the current directory is the root of a share and the user tries to change to '..'.
* | win32: changes to user idsRon Yorston2019-03-101-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Formalise the use of 0 as the uid of a process running with elevated privileges: - Rewrite getuid(2) to return DEFAULT_UID by default and 0 if the process has elevated privileges. - geteuid(2) and the corresponding functions for groups are aliases for getuid(2). - Change root's home directory to be whatever GetSystemDirectory() returns, probably C:/Windows/System32 in most cases. - Remove the special handling of geteuid(2) in the line editing code. With these changes the shell started by 'su' is a lot more like a *nix root shell.
* | su: change title of console windowRon Yorston2019-03-091-1/+13
| |
* | ash, su: add -d flag to set directory in ash, use it in suRon Yorston2019-03-081-3/+30
| | | | | | | | | | | | | | | | When busybox-w32 is installed in C:/Windows/System32 su doesn't run in the same directory as its parent as intended. Work around this by adding a flag to the shell to set the working directory.
* | ash: add an option to enable case-insensitive filename globbingRon Yorston2019-03-011-4/+26
| | | | | | | | | | The 'nocaseglob' shell option enables case-insensitive filename globbing. By default globbing is case-sensitive.
* | win32: fix POSIX buildRon Yorston2019-02-171-0/+14
| | | | | | | | | | | | There were a few places where changes intended for the WIN32 build also affected the POSIX build. Fix these so the result of 'make defconfig; make' for busybox-w32 is identical to upstream BusyBox.
* | ash: updated support for hiding consoleRon Yorston2019-02-171-9/+3
| | | | | | | | | | | | | | | | Move the code to hide the console to a separate function in win32/mingw.c. Use lazy loading to avoid problems on platforms where the require APIs aren't supported (PR #70). Enable console hiding in the default 64-bit configuration.
* | ash: tidy up handling of -X optionRon Yorston2019-02-171-8/+7
| |
* | win32: add a function to remove CRs from a text bufferRon Yorston2019-02-141-10/+1
| |
* | ash: improve handling of 'read -t 0'Ron Yorston2019-02-081-4/+12
| | | | | | | | | | | | | | | | | | | | Instead of always returning that no input is available: - for a disk file return 'available'; - for the console return 'not available'; - for anything else (e.g. pipe) return whatever poll says. This fixes the test ash-read/read_t0.tests.
* | ash: make spawn_forkshell more like forkshellRon Yorston2019-02-061-8/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | These are cosmetic changes only. Make the arguments to spawn_forkshell more like those of forkshell. Since job control isn't currently supported in busybox-w32 the node argument isn't actually used. The node passed in the forkshell structure is used in the child code. It may be different from the node passed as an argument to spawn_forkshell which, in the upstream code, is forwarded to forkparent and forkchild.
* | win32: add support for the euro currency symbolRon Yorston2019-02-021-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The euro currency symbol was added to some OEM code pages. See: https://www.aivosto.com/articles/charsets-codepages-dos.html Add a configuration option (enabled by default) to support this. When enabled: - The read_key() function requests wide character key events. This allows the euro symbol to be entered regardless of the console OEM code page, though it needs to be available in the ANSI code page. - Conversions between OEM and ANSI code pages in winansi.c are modified to work around a bug in the Microsoft routines. - If the OEM code page is 850 when BusyBox starts it's changed to 858. This is the only currently supported OEM code page. Also, the shell read builtin is modified to use read_key() whenever input is being taken from the console.
* | ash: remove carriage returns from strings to be evaluatedRon Yorston2019-01-261-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The shell could fail to evaluate strings containing carriage returns. For example: awk 'BEGIN { "set -ex\r\npwd\r\n" | getline }' </dev/null The string is passed as an argument to "sh -c". The "set" built-in fails because it attempts to treat the carriage return as an option. Although this is correct behaviour on Unix it may be unhelpful on Microsoft Windows. See GitHub issue #138.
* | Merge branch 'busybox' into mergeRon Yorston2019-01-103-6/+6
|\|
| * config: update size informationDenys Vlasenko2018-12-283-3/+3
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * randomconfig fixesDenys Vlasenko2018-12-271-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * inetd: suppress aliasing warningDenys Vlasenko2018-12-082-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta sigprocmask2 - 8 +8 wait_for_child_or_signal 213 218 +5 dowait 424 429 +5 block_CHLD_HUP_ALRM 62 59 -3 sigprocmask_SIG_SETMASK 16 - -16 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 2/1 up/down: 18/-19) Total: -1 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * suppress gcc 8 aliasing warningsDenys Vlasenko2018-12-082-2/+2
| | | | | | | | | | | | | | | | | | function old new delta sigprocmask_SIG_SETMASK - 16 +16 wait_for_child_or_signal 221 213 -8 dowait 432 424 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ps: add support for the args columnRon Yorston2019-01-081-1/+0
| | | | | | | | | | | | | | | | | | Implement read_cmdline() for WIN32 by storing the command line in the same way as the applet name. The applet name is actually used for the comm column which is truncated to COMM_LEN. Using this as the size of the bb_comm array avoids the need to calculate MAX_APPLET_NAME_LEN.
* | win32: implement umask(2)Ron Yorston2019-01-071-0/+3
| | | | | | | | | | | | | | | | | | umask() in the Microsoft C runtime takes different arguments to umask(2). Implement a fake umask(2) that remembers the mask and calls the Microsoft umask() with an appropriate value. Since the mask won't be inherited by children use an environment variable to pass any value set by the shell built-in umask.
* | ash: fix local PATH assignmentsRon Yorston2018-12-151-7/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous commit included code to use PATH values assigned to local variables: PATH=/new/path:$PATH new_binary It didn't work in the case when no fork was needed, for example: (PATH=/new/path:$PATH new_binary) because the call to listsetvar() freed the PATH value that was passed to shellexec(). The forking case only worked because the spawn_forkshell() mechanism in busybox-w32 didn't allow the PATH value to be freed. Rewrite the code so it works whether or not a fork is needed. The code would also work on POSIX systems. A cleaner solution could be extracted from dash commit cbb71a8 'eval: Add assignment built-in support again' but neither that nor the current patch are suitable for submission to upstream BusyBox. This one is preferred because it requires fewer changes from upstream.
* | win32: special treatment for PATHRon Yorston2018-12-141-25/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The PATH shell variable is a special case. It can be exported to the environment where it might be interpreted by native applications which assume the separator is ';'. Hence: - require that the separator used in PATH is ';' - enforce this by intercepting calls to setvareq() that set PATH and adjusting its value if necessary. As a result of this the code to parse PATH can be simplified by replacing the hardcoded Unix ':' path separator by the platform- dependent macro PATH_SEP. The MANPATH variable is also required to use ';' as its separator but since it's less likely to be used this isn't enforced.
* | ash: move code from setup_environment()Ron Yorston2018-12-141-3/+6
| | | | | | | | | | | | | | ash calls setup_environment() but only uses a small amount of its functionality. Moving the code into ash itself means we don't need to customise setup_environment() for WIN32 and can remove it from the build.
* | ash: prevent ctrl-c from killing background processesRon Yorston2018-12-131-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | spawn_forkshell() was missing some code that would normally have been run from forkchild when a background process was started: - the ctrl-c handler wasn't disabled; - standard input wasn't connected to /dev/null. Using ctrl-c to kill a foreground process also killed background processes. Fixing this requires passing the forkshell mode and the number of processes associated with the forkshell job to the child process.
* | ash: fix ctrl-c handling for pipelinesRon Yorston2018-12-131-43/+57
| | | | | | | | | | | | | | | | | | | | | | There were two flaws in the implementation of ctrl-c handling in waitpid_child(): - processes associated with all jobs were killed; - all processes in a pipeline were killed but only the status of one was updated. As a result of the latter ctrl-c didn't reliably stop a pipeline.
* | win32: emulate SIGPIPERon Yorston2018-12-111-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code to check whether a write error is due to a broken pipe can now either: - return with error EPIPE; - cause the process to exit with code 128+SIGPIPE. The default is the latter but the behaviour can be changed by issuing signal(SIGPIPE, SIG_IGN) and signal(SIGPIPE, SIG_DFL) calls. No actual signal is involved so kill can't send SIGPIPE and handlers other than SIG_IGN and SIG_DFL aren't supported. This does, however, avoid unsightly 'broken pipe' errors from commands like the example in GitHub issue #99: dd if=/dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
* | ash: use auto_win32_extension() in tryexec()Ron Yorston2018-12-091-6/+3
| |
* | win32: rework adding of extensions to filenamesRon Yorston2018-12-061-52/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously there was one function to handle adding extensions to executable filenames, add_win32_extension(). Refactor this into three functions: add_win32_extension() appends the suffix to the argument string in-place. The argument must be long enough to cope with this, as is the case in ash where path_advance() adds 4 bytes to each filename for just this reason. alloc_win32_extension() is equivalent to the old add_win32_extension(). It allocates a string to hold the new filename then calls the new add_win32_extension() function. The caller is responsible for managing the returned string. auto_win32_extension() calls alloc_win32_extension() and saves the resulting string using auto_string(). It's used where the new filename is consumed immediately or the actual value isn't needed. Rewrite code to use the most appropriate function. Also reorder some code in find_executable() and find_command().
* | ash: fix 'type' and 'command -v'Ron Yorston2018-12-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The 'type' and 'command -v' builtins could return incorrect information when their argument included a file separator. For example: $ command -v cmd C:/Windows/system32/cmd.exe $ command -v C:/Windows/system32/cmd.exe $ echo $? 127 Fix the faulty logic causing this.
* | ash: fix a couple of test casesRon Yorston2018-12-041-10/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The ash tests exitcode_EACCES and exitcode_ENOENT both failed. In commit 92dbd3c09 a test was added to tryexec to check that the file being run existed and was executable. The error codes returned by this test were incorrect. The slightly later commit f5783ef14 added a similar test in spawnveq which got the error codes right. Remove the test from tryexec and some superfluous error messages from spawnveq.
* | ash: forkshell tweaksRon Yorston2018-12-041-12/+13
| | | | | | | | | | | | | | | | Make it explicit that the nodeptr array contains pointers to pointers. In debug output show both the location of pointers to be fixed and their contents.
* | ash: more clean upRon Yorston2018-12-031-5/+5
| |
* | ash: code clean upRon Yorston2018-12-031-6/+1
| |
* | ash: improvements to forkshell debugRon Yorston2018-12-031-5/+23
| | | | | | | | | | | | | | | | If forkshell_print is passed a NULL file pointer it opens and closes a local one. Add the pid to the output file name so forkshell_print can be called from both parent and child.
* | ash: annotate pointers in forkshell debugRon Yorston2018-12-021-42/+130
| | | | | | | | | | | | | | Add some text to indicate the purpose of each pointer in the forkshell data block. The code isn't very efficient but it's only used for debug.
* | ash: redefine SAVE_PTR macros to remove testRon Yorston2018-12-021-2/+10
| | | | | | | | | | | | | | | | | | | | | | The SAVE_PTR macros are used to identify pointers that need to be fixed after forkshell. They're initially used in contexts where the nodeptr variable may be NULL, so have a test for this condition. Later uses are in places where nodeptr is known to have a non-NULL value so the macros can be redefined to remove the test. Saves over 100 bytes.
* | ash: consolidate tests for variables not to convertRon Yorston2018-11-291-8/+5
| | | | | | | | | | | | | | We usually convert backslashes to slashes when importing environment variables into the shell. Exceptions are if the user has set the -X option, SYSTEMROOT and COMSPEC. Perform these tests all at once rather than separately.
* | ash: fixes to spawn_forkshellRon Yorston2018-11-291-16/+10
| | | | | | | | | | | | | | If spawn fails: - raise an error in spawn_forkshell, not at each call site; - free the job by calling freejob, not free.
* | Merge branch 'busybox' into mergeRon Yorston2018-11-283-5/+56
|\|
| * hush: allow hush to run embedded scriptsRon Yorston2018-11-273-15/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | Embedded scripts require a shell to be present in the BusyBox binary. Allow either ash or hush to be used for this purpose. If both are enabled ash takes precedence. The size of the binary is unchanged in the default configuration: both ash and hush are present but support for embedded scripts isn't compiled into hush. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: reset tokpushback before prompting while parsing heredocChristoph Schulz2018-11-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The parser reads from an already freed memory location, thereby causing unpredictable results, in the following situation: - ENABLE_ASH_EXPAND_PRMT is enabled - heredoc is being parsed - command substitution is used within heredoc Examples where this bug crops up are (PS2 is set to "> "): $ cat <<EOF > `echo abc` > EOF -sh: O: not found $ cat <<EOF > $(echo abc) > EOF -sh: {garbage}: not found The presumable reason is that setprompt_if() causes a nested expansion when ENABLE_ASH_EXPAND_PRMT is enabled, therefore leaving "wordtext" in an unusable state. However, when parseheredoc() is called, "tokpushback" is non-zero, which causes the next call to xxreadtoken() to return TWORD, causing the caller to use the invalid "wordtoken" instead of reading the next valid token. The call chain is: list() -> peektoken() [sets tokpushback to 1] -> parseheredoc() -> setprompt_if() -> pushstackmark() -> expandstr() -> readtoken1() [sets lasttoken to TWORD, wordtoken points to expanded prompt] -> popstackmark() [invalidates wordtoken, leaves lasttoken as is] -> readtoken1() -> ...parsebackq -> list() -> andor() -> pipeline() -> readtoken() -> xxreadtoken() [tokpushback non-zero, reuse lasttoken and wordtext] Note that in almost all other contexts, each call to setprompt_if() is preceded by setting "tokpushback" to zero. One exception is "oldstyle" backquote parsing in readtoken1(), but there "tokpushback" is reset afterwards. The other exception is nlprompt(), but this function is only used within readtoken1() (but in contexts where no nested calls to xxreadtoken() occur) and xxreadtoken() (where "tokpushback" is guaranteed to be zero). function old new delta parseheredoc 124 131 +7 Signed-off-by: Christoph Schulz <develop@kristov.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * Treat custom and applet scripts as appletsRon Yorston2018-11-171-15/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | BusyBox has support for embedded shell scripts. Two types can be distinguished: custom scripts and scripts implementing applets. Custom scripts should be placed in the 'embed' directory at build time. They are given a default applet configuration and appear as applets to the user but no further configuration is possible. Applet scripts are integrated with the BusyBox build system and are intended to be used to ship standard applets that just happen to be implemented as scripts. They can be configured at build time and appear just like native applets. Such scripts should be placed in the 'applets_sh' directory. A stub C program should be written to provide the usual applet configuration details and placed in a suitable subsystem directory. It may be helpful to have a configuration option to enable any dependencies the script requires: see the 'nologin' applet for an example. function old new delta scripted_main - 41 +41 applet_names 2773 2781 +8 applet_main 1600 1604 +4 i2cdetect_main 672 674 +2 applet_suid 100 101 +1 applet_install_loc 200 201 +1 applet_flags 100 101 +1 packed_usage 33180 33179 -1 tryexec 159 152 -7 evalcommand 1661 1653 -8 script_names 9 - -9 packed_scripts 123 114 -9 complete_cmd_dir_file 826 811 -15 shellexec 271 254 -17 find_command 1007 990 -17 busybox_main 642 624 -18 run_applet_and_exit 100 78 -22 find_script_by_name 51 - -51 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 6/9 up/down: 58/-174) Total: -116 bytes text data bss dec hex filename 950034 477 7296 957807 e9d6f busybox_old 949918 477 7296 957691 e9cfb busybox_unstripped Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: ensure variables are fully initialised when unsetRon Yorston2018-11-161-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a variable is unset by calling setvar(name, NULL, 0) the code to initialise the new, empty variable fails to initialise the last character of the string. Attempts to read the contents of the unset variable will result in the uninitialised character at the end of the string being accessed. For example, running BusyBox under Valgrind and unsetting PATH: $ valgrind ./busybox_unstripped sh ==21249== Memcheck, a memory error detector ==21249== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==21249== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info ==21249== Command: ./busybox_unstripped sh ==21249== /data2/git/build_fix_8721 $ unset PATH /data2/git/build_fix_8721 $ 0 ==21249== Conditional jump or move depends on uninitialised value(s) ==21249== at 0x451371: path_advance (ash.c:2555) ==21249== by 0x456E22: find_command (ash.c:13407) ==21249== by 0x458425: evalcommand (ash.c:10139) ==21249== by 0x454CBC: evaltree (ash.c:9131) ==21249== by 0x456C80: cmdloop (ash.c:13164) Closes https://bugs.busybox.net/show_bug.cgi?id=8721 v2: On the dash mailing list Harald van Dijk was kind enough to point out a flaw in my reasoning and provide an alternative patch. Sadly his patch adds 2 bytes of bloat. Using xzalloc to zero the whole string gives a bloat of -3 bytes. function old new delta setvar 172 169 -3 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: correct description for HUSH_TICK config optionRon Yorston2018-11-141-1/+1
| | | | | | | | | | | | | | | | The HUSH_TICK configuration option enables command substitution, not process substitution. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: minor fixesRon Yorston2018-11-061-1/+5
| | | | | | | | | | | | | | | | | | | | | | Ensure that login_sh is initialised in procargs even when running an embedded script. The argc argument to ash_main isn't unused when embedded scripts are present. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>