summaryrefslogtreecommitdiffstats
path: root/bin
Commit message (Collapse)AuthorAgeFilesLines
* sh: Fix heap-based buffer overflow in pathname generation.jilles2010-08-101-16/+15
| | | | | | | | | | | | | | The buffer for generated pathnames could be too small in some cases. It happened to be always at least PATH_MAX long, so there was never an overflow if the resulting pathnames would be usable. This bug may be abused if a script subjects input from an untrusted source to pathname generation, which a bad idea anyhow. Most shell scripts do not work on untrusted data. secteam@ says no advisory is necessary. PR: bin/148733 Reported by: Changming Sun snnn119 at gmail com MFC after: 10 days
* Remove unnecessary duplicate letters in mksyntax.c,jilles2010-08-081-2/+2
| | | | the table elements would just be overwritten twice.
* sh: Return 0 from eval if no command was given.jilles2010-08-031-1/+7
| | | | | | | | | | | This makes a difference if there is a command substitution. To make this work, evalstring() has been changed to set exitstatus to 0 if no command was executed (the string contained only whitespace). Example: eval $(false); echo $? should print 0.
* Document the new argument parser for sleep(1) and SIGINFO behaviour.kib2010-08-021-6/+7
| | | | | | Remove higlight for the unportability notice. MFC after: 3 weeks
* Simplify argument parser by using sscanf(); simplify usage() by notkib2010-08-021-72/+19
| | | | | | | | | | refusing to use stdio. Reduce nesting level in the sleep loop by returning earlier for negative timeouts. Limit the maximum timeout to INT_MAX seconds. Submitted by: bde MFC after: 3 weeks
* sh: Do not enter consecutive duplicates into the history.jilles2010-08-011-0/+1
| | | | | | | | | | | | This simply sets a flag in libedit. It has a shortcoming in that it does not apply to multi-line commands. Note that a configuration option for this is not going to happen, but always having this seems better than not having it. NetBSD has done the same. PR: bin/54683 Obtained from: NetBSD MFC after: 1 month
* Spelling fixes.joel2010-07-311-1/+1
|
* Deal with proper format for printing time_t.kib2010-07-311-3/+5
| | | | | Reported by: ache MFC after: 3 weeks
* Report the time left for the sleep on SIGINFO.kib2010-07-311-19/+47
| | | | | | | Be stricter in the checking of interval specification. PR: bin/139345 MFC after: 3 weeks
* kill: Stop processing if a syntactically invalid pid is encountered.jilles2010-07-291-4/+3
| | | | | | | | | | | | So a command like kill _HUP 1 now fails without sending SIGTERM to init. The behaviour when kill(2) fails remains unchanged: processing continues. This matches other implementations and POSIX and is useful for killing multiple processes at once when some of them may already be gone. PR: bin/40282
* Typo fix: s/ommited/omittedbcr2010-07-271-2/+2
| | | | MFC after: 4 days
* sh: Fix crash due to uninitialized here-document.jilles2010-07-251-0/+3
| | | | | | | | | | | | | | | If an ; or & token was followed by an EOF token, pending here-documents were left uninitialized. Execution would crash, either in the main shell process for literal here-documents or in a child process for expanded here-documents. In the latter case the problem is hard to detect apart from the core dumps and log messages. Side effect: slightly different retries on inputs where EOF is not persistent. Note that tools/regression/bin/sh/parser/heredoc6.0 still causes a similar crash in a child process. The text passed to eval is malformed and should be rejected.
* Fix alignment for the 'flags' label, and make more room for 'tdev'.trasz2010-07-241-2/+2
| | | | MFC after: 1 month
* Add P_HASTHREADS flag description.trasz2010-07-241-1/+2
|
* sh: Allow a background command consisting solely of redirections.jilles2010-07-181-0/+1
| | | | | | | Example: </dev/null & MFC after: 2 weeks
* sh: There cannot be a TNOT in simplecmd(), remove checks.jilles2010-07-141-19/+3
| | | | | | simplecmd() only handles simple commands and function definitions, neither of which involves the ! keyword. The initial token on entry to simplecmd() is one of the following: TSEMI, TAND, TOR, TNL, TEOF, TWORD, TRP.
* Add -l to the synopsisbrian2010-07-121-1/+1
| | | | | Submitted by: jhell at dataix dot net MFC after: 3 days
* sh: Use $PWD instead of getcwd() for the \w and \W prompt expansions.jilles2010-07-021-12/+11
| | | | | | This ensures that the logical working directory (which may include symlinks) is shown and is similar to the default behaviour of the pwd builtin.
* sh: Forget about terminated background processes sooner.jilles2010-06-294-9/+66
| | | | | | | | | | | | | | | | | | | | | | | | Unless $! has been referenced for a particular job or $! still contains that job's pid, forget about it after it has terminated. If $! has been referenced, remember the job until the wait builtin has reported its completion (either with the pid as parameter or without parameters). In interactive mode, jobs are forgotten after termination has been reported, which happens before primary prompts and through the jobs builtin. Even then, though, remember a job if $! has been referenced. This is similar to what is suggested by POSIX and should fix most memory leaks (which also tend to cause sh to use more CPU time) with long running scripts that start background jobs. Caveats: * Repeatedly referencing $! without ever doing 'wait', like while :; do foo & echo started foo: $!; sleep 60; done will still use a lot of memory and CPU time in the long run. * The jobs and jobid builtins do not cause a job to be remembered for longer like expanding $! does. PR: bin/55346
* Recognise the -l switch with pkill - list kill command(s) used.brian2010-06-202-8/+16
| | | | | | PR: 143558 Submitted by: eitanadlerlist at gmail dot com MFC after: 3 weeks
* sh: Fix compilation with -DNO_HISTORY.jilles2010-06-191-0/+1
| | | | | | | | | | | The LINENO code uses snprintf() and relied on "myhistedit.h" to pull in the necessary <stdio.h>. Compiling with -DNO_HISTORY disables all editing and history support and allows linking without -ledit -ltermcap. This may be useful for embedded systems. MFC after: 2 weeks
* sh: Add filename completion.jilles2010-06-151-0/+4
| | | | | | | | | | | | This uses the new libedit completion function with quoting support. Unlike NetBSD, there is no 'set +o tabcomplete' option to disable completion. I do not see any reason for such a special treatment, as completion is rather useful and it is possible to do bind ^I ed-insert to disable completion and insert a tab character instead. Submitted by: Guy Yur
* More mdoc nitpicking to improve compatibility to mdocmluqs2010-06-111-1/+1
| | | | | | | | - .Nd in section NAME is not optional - .Ed was missing - "indent" is not a flag, but a literal argument for -offset - stop switching font sizes for acronyms - use .Brq instead of rolling our own
* sh: Pass through SIGINT from a child if interactive and job controljilles2010-06-061-0/+6
| | | | | | | | | | | | | | | is enabled. This already worked if without job control. In either case, this depends on it that a process that terminates due to SIGINT exits on it (so not with status 1, or worse, 0). Example: sleep 5; echo continued This does not print "continued" any more if sleep is aborted via ctrl+c. MFC after: 1 month
* Don't try to copy a socket after "xxx is a socket (not copied)." message.trasz2010-06-051-0/+1
| | | | | | | | | Previously, it would either try to copy it anyway and fail (without -R), or create fifo instead of the socket (with -R). Found with: Coverity Prevent CID: 5623 MFC after: 2 weeks
* Explain that setting an absolute day value can fail and that the month shouldbrian2010-06-041-3/+11
| | | | | | | | | | usually be set first when using -v. Adjust an example that sets the day to 30 before setting the month to 3 in accordance with this approach as the example would always fail in February! PR: 147354 MFC after: 2 weeks
* sh: Pass TERM changes to libedit.jilles2010-06-024-0/+22
| | | | | | | | I have changed the patch slightly to ignore TERM changes in subshells. PR: bin/146916 Submitted by: Guy Yur Obtained from: NetBSD
* Zero struct before reading from ituqs2010-06-021-0/+1
| | | | | | PR: 140384 Found by: clang static analyzer MFC after: 3 weeks
* sh: Fix a crash if a heredoc was not properly ended and parsing continued.jilles2010-05-301-0/+1
| | | | | | | | | Example (in interactive mode): cat <<EOF && ) The next command typed caused sh to segfault, because the state for the here document was not reset. Like parser_temp, this uses the fact that the parser is not re-entered.
* sh: Change interaction of command substitution and here documents.jilles2010-05-301-4/+13
| | | | | | | | | | | | | | | | | If a command substitution contains a newline token, this no longer starts here documents of outer commands. This way, we follow POSIX's idea of the command substitution being a separate script more closely. It also matches other shells better and is consistent with newline characters in quotes not starting here documents. The extension tested in parser/heredoc3.0 ($(cat <<EOF)\ntext\nEOF\n) continues to be supported. In particular, this change allows things like cat <<EOF && echo `pwd` (a `` command substitution after a here document) which formerly silently used an empty file as the here document, because the EOF of the inner command "pwd" also forced an empty here document.
* sh: Recognize "--" in . and exec.jilles2010-05-282-2/+14
| | | | | | | | | | | | | | | | | | Although "--" historically has not been required to be recognized for certain special builtins that do not take options in POSIX, some other implementations recognize options for them, requiring scripts to use "--" or avoid operands starting with "-". Operands starting with "-" can be avoided with eval by prepending a space, and cannot occur with break, continue, exit, return and shift as they only take numbers, nor with times as it does not take operands. With . and exec, avoiding "-" is not so easy as it may require reimplementing the PATH search; therefore the current proposal for POSIX is to require recognition of "--" for them. We continue to accept other strings starting with "-" as operands to . and exec, and also "--" if it is alone to . (which would otherwise be invalid anyway).
* sh(1): Rework documentation of shell variables.jilles2010-05-241-87/+118
| | | | | | | | | * Move the "environment variables" that do not need exporting to be effective or that are set by the shell without exporting to a new section "Special Variables". * Add special variables LINENO and PPID. * Add environment variables LANG, LC_* and PWD; also describe ENV under environment variables.
* sh(1): Improve wording of 'Special Parameters' section.jilles2010-05-241-7/+3
|
* sh: Reap any zombies before forking for a background command.jilles2010-05-241-1/+13
| | | | | | | | | | | | | | This prevents accumulating huge amounts of zombies if a script executes many background commands but no external commands or subshells. Note that zombies will not be reaped during long calculations (within the shell process) or read builtins, but those actions do not create more zombies. The terminated background commands will also still be remembered by the shell. PR: bin/55346
* Fix back references in substitute command for pax(1)uqs2010-05-241-4/+4
| | | | | | | | | | pax(1) was trying to copy the back-referenced data from the match pattern, not the matched data. PR: bin/118132 Obtained from: Debian bug #451361 Reviewed by: jilles MFC after: 3 weeks
* Update authors and history.trasz2010-05-131-1/+6
| | | | MFC after: 1 week
* sh: Fix pathname expansion with quoted slashes like *\/.jilles2010-05-111-9/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These are git commits 36f0fa8fcbc8c7b2b194addd29100fb40e73e4e9 and d6d06ff5c2ea0fa44becc5ef4340e5f2f15073e4 in dash. Because this is the first code I'm importing from dash to expand.c, add the Herbert Xu copyright notice which is in dash's expand.c. When pathname expanding *\/, the CTLESC representing the quoted state was erroneously taken as part of the * pathname component. This CTLESC was then seen by the pattern matching code as escaping the '\0' terminating the string. The code is slightly different because dash converts the CTLESC characters to backslashes and removes all the other CTL* characters to allow substituting glob(3). The effect of the bug was also slightly different from dash (where nothing matched at all). Because a CTLESC can escape a '\0' in some way, whether files were included despite the bug depended on memory that should not be read. In particular, on many machines /*\/ expanded to a strict subset of what /*/ expanded to. Example: echo /*"/null" This should print /dev/null, not /*/null. PR: bin/146378 Obtained from: dash
* sh(1): Fix "reserved word" vs "keyword" inconsistency.jilles2010-05-091-9/+9
| | | | | Use "keyword" everywhere, like the output of the 'type' builtin, and only mention "reserved word" once to say it is the same thing.
* sh: Have only one copy of _PATH_STDPATH in the binary.jilles2010-05-081-3/+2
|
* sh: Apply locale vars on builtins, recognize LC_MESSAGES as a locale var.jilles2010-05-053-7/+74
| | | | | | | | | | | | | | | | This allows doing things like LC_ALL=C some_builtin to run a builtin under a different locale, just like is possible with external programs. The immediate reason is that this allows making printf(1) a builtin without breaking things like LC_NUMERIC=C printf '%f\n' 1.2 This change also affects special builtins, as even though the assignment is persistent, the export is only to the builtin (unless the variable was already exported). Note: for this to work for builtins that also exist as external programs such as /bin/test, the setlocale() call must be under #ifndef SHELL. The shell will do the setlocale() calls which may not agree with the environment variables.
* sh: Use stalloc for arith variable names.jilles2010-04-253-24/+10
| | | | | This is simpler than the custom memory tracker I added earlier, and is also needed by the dash arith code I plan to import.
* symlink(7): Add lpathconf(2) and *at system calls.jilles2010-04-251-2/+27
| | | | MFC after: 1 week
* symlink(7): The ownership of symlinks is used by the system,jilles2010-04-251-3/+3
| | | | | | | | | in at least three ways, so do not say it is ignored: * who may delete/rename a symlink in a sticky directory * who may do lchflags(2)/lchown(2)/lchmod(2) * whose inode quota is charged MFC after: 1 week
* ln: Allow a trailing slash when creating a link to a directory.jilles2010-04-211-14/+13
| | | | | | | | | | | | | | | | | | | | In the 'ln source... directory' synopsis, the basename of each source determines the name of the created link. Determine this using basename(3) instead of strrchr(..., '/') which is incorrect if the pathname ends in a slash. The patch is somewhat changed to allow for basename(3) implementations that change the passed pathname, and to fix the -w option's checking also. The code to compare directory entries only applies to hard links, which cannot be created to directories using ln. Example: ln -s /etc/defaults/ /tmp This should create a symlink named defaults. PR: 121568 Submitted by: Ighighi MFC after: 1 week
* ln: Refuse deleting a directory entry by hardlinking it to itself.jilles2010-04-171-2/+59
| | | | | | | | | | | | | | Two pathnames refer to the same directory entry iff the directories match and the final components' names match. Example: (assuming file1 is an existing file) ln -f file1 file1 This now fails while leaving file1 intact. It used to delete file1 and then complain it cannot be linked because it is gone. With -i, this error is detected before the question is asked. MFC after: 2 weeks
* sh: On startup of the shell, use PWD from the environment if it is valid.jilles2010-04-173-10/+24
| | | | | | | | | | | | | | | Unset PWD if it is incorrect and no value for it can be determined. This preserves the logical current directory across shell invocations. Example (assuming /home is a symlink): $ cd $ pwd /home/foo $ sh $ pwd /home/foo Formerly the second pwd would show the physical path (symlinks resolved).
* mdoc: order prologue macros consistently by Dd/Dt/Osuqs2010-04-141-1/+1
| | | | | | | | Although groff_mdoc(7) gives another impression, this is the ordering most widely used and also required by mdocml/mandoc. Reviewed by: ru Approved by: philip, ed (mentors)
* Update the list of the process flags for P_WKILLED.kib2010-04-131-1/+2
| | | | MFC after: 4 weeks
* sh: Partially revert r206146, allowing double-quotes in arithmetic.jilles2010-04-112-1/+5
| | | | | | | | These do pretty much nothing (except that parentheses are ignored), but people seem to use them and allowing them does not hurt much. Single-quotes seem not to be used and cause silently different behaviour with ksh93 character constants.
* sh: Automatically enable -o emacs in interactive shells with terminals.jilles2010-04-052-3/+7
| | | | | | | This makes sh a bit more friendly in single user mode, make buildenv, chroot and the like, and matches other shells. The -o emacs can be overridden on the command line or in the ENV file.
OpenPOWER on IntegriCloud