aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/gen/wordexp.c
Commit message (Collapse)AuthorAgeFilesLines
* libc: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-251-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using mis-identified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326193
* libc: provide some bounds-checking through reallocarray(3).Pedro F. Giffuni2017-03-121-2/+2
| | | | | | | | | | | | reallocarray(3) is a non portable extension that originated in OpenBSD. Given that it is already in FreeBSD's libc it is useful for the cases where reallocation involves a multiplication. MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D9955 Notes: svn path=/head/; revision=315162
* wordexp: Rewrite to make WRDE_NOCMD reliable.Jilles Tjoelker2015-09-301-80/+132
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Shell syntax is too complicated to detect command substitution and unquoted operators reliably without implementing much of sh's parser. Therefore, have sh do this detection. While changing sh's support anyway, also read input from a pipe instead of arguments to avoid {ARG_MAX} limits and improve privacy, and output count and length using 16 instead of 8 digits. The basic concept is: execl("/bin/sh", "sh", "-c", "freebsd_wordexp ${1:+\"$1\"} -f "$2", "", flags & WRDE_NOCMD ? "-p" : "", <pipe with words>); The WRDE_BADCHAR error is still implemented in libc. POSIX requires us to fail strings containing unquoted braces with code WRDE_BADCHAR. Since this is normally not a syntax error in sh, there is still a need for checking code in libc, we_check(). The new we_check() is an optimistic check that all the characters <newline> | & ; < > ( ) { } are quoted. To avoid duplicating too much sh logic, such characters are permitted when quoting characters are seen, even if the quoting characters may themselves be quoted. This code reports all WRDE_BADCHAR errors; bad characters that get past it and are a syntax error in sh return WRDE_SYNTAX. Although many implementations of WRDE_NOCMD erroneously allow some command substitutions (and ours even documented this), there appears to be code that relies on its security (codesearch.debian.net shows quite a few uses). Passing untrusted data to wordexp() still exposes a denial of service possibility and a fairly large attack surface. Reviewed by: wblock (man page only) MFC after: 2 weeks Relnotes: yes Security: fixes command execution with wordexp(untrusted, WRDE_NOCMD) Notes: svn path=/head/; revision=288430
* Switch libc from using _sig{procmask,action,suspend} symbols, whichKonstantin Belousov2015-08-291-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | are aliases for the syscall stubs and are plt-interposed, to the libc-private aliases of internally interposed sigprocmask() etc. Since e.g. _sigaction is not interposed by libthr, calling signal() removes thr_sighandler() from the handler slot etc. The result was breaking signal semantic and rtld locking. The added __libc_sigprocmask and other symbols are hidden, they are not exported and cannot be called through PLT. The setjmp/longjmp functions for x86 were changed to use direct calls, and since PIC_PROLOGUE only needed for functional PLT indirection on i386, it is removed as well. The PowerPC bug of calling the syscall directly in the setjmp/longjmp implementation is kept as is. Reported by: Pete French <petefrench@ingresso.co.uk> Tested by: Michiel Boland <boland37@xs4all.nl> Reviewed by: jilles (previous version) Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=287292
* wordexp(): Improve some error codes.Jilles Tjoelker2015-08-191-15/+26
| | | | | | | | | | Distinguish between WRDE_BADVAL and WRDE_SYNTAX based on when the error occurred (parsing or execution), not based on whether WRDE_UNDEF was passed. Also, return WRDE_NOSPACE for a few more unexpected results from sh. Notes: svn path=/head/; revision=286941
* wordexp(): Stop using the undocumented wordexp builtin.Jilles Tjoelker2015-08-161-3/+4
| | | | | | | | | | | | The functionality of the wordexp builtin is easily replaced using normal shell code, although performance is slightly worse. This does not mean that wordexp() will remain shell-independent -- a fully reliable implementation of WRDE_NOCMD is really only possible using extensions to the shell, or by adding much of the shell's code to libc. Notes: svn path=/head/; revision=286830
* wordexp: Explicitly pass along IFS.Jilles Tjoelker2015-03-311-1/+4
| | | | | | | | | | | | | | Per Austin group issue #884, sh should not import IFS from the environment but always set it to $' \t\n'. For wordexp(), however, it is documented and useful for it to use IFS from the environment. Since sh currently imports IFS from the environment, this change has no functional effect. MFC after: 1 week Notes: svn path=/head/; revision=280919
* wordexp(): Avoid leaking the pipe file descriptors to a parallel fork/exec.Jilles Tjoelker2013-08-271-4/+4
| | | | | | | This uses the new pipe2() system call added on May 1 (r250159). Notes: svn path=/head/; revision=254977
* wordexp(): Fix syntax validation for backslashes in single-quotes.Jilles Tjoelker2013-07-231-1/+2
| | | | Notes: svn path=/head/; revision=253581
* wordexp(): Simplify code by deferring work to sh.Jilles Tjoelker2013-05-091-13/+3
| | | | Notes: svn path=/head/; revision=250406
* wordexp(): Remove wrong IFS usage.Jilles Tjoelker2013-04-011-4/+1
| | | | | | | | | | | | | | Words in shell script are separated by spaces or tabs independent of the value of IFS. The value of IFS is only relevant for the result of substitutions. Therefore, there should be a space between 'wordexp' and the words to be expanded, not an IFS character. Paranoia might dictate that the shell ignore IFS from the environment (even though our sh currently uses it), so do not depend on it in the new test case. Notes: svn path=/head/; revision=248987
* Eliminate more dead stores.Garrett Wollman2009-11-251-1/+1
| | | | | | | | Found by: Clang static analyzer MFC after: 7 days Notes: svn path=/head/; revision=199784
* wordexp(3): fix some bugs with signals and long outputsJilles Tjoelker2009-10-231-19/+57
| | | | | | | | | | | | | | | * retry various system calls on EINTR * retry the rest after a short read (common if there is more than about 1K of output) * block SIGCHLD like system(3) does (note that this does not and cannot work fully in threaded programs, they will need to be careful with wait functions) PR: 90580 MFC after: 1 month Notes: svn path=/head/; revision=198406
* Fix typo: WRDE_DOOFS -> WRDE_DOOFFS.Tim J. Robbins2004-06-301-3/+3
| | | | | | | Noticed by: Stoned Elipot Notes: svn path=/head/; revision=131331
* Terminate execl()'s argument list with a null pointer instead of aTim J. Robbins2004-04-091-1/+1
| | | | | | | | | | null pointer constant. (The latter may be an integer constant, which is not correct here.) Submitted by: Stefan Farfeleder Notes: svn path=/head/; revision=128050
* Use hidden names (_close, _dup2, _waitpid, etc.) where appropriate.Tim J. Robbins2003-01-071-22/+22
| | | | Notes: svn path=/head/; revision=108865
* Fix a number of bugs noticed by more extensive testing:Tim J. Robbins2003-01-041-7/+15
| | | | | | | | | | | | | o Call waitpid() if an error occurs after forking the child process to avoid leaving zombies around. o Handle the WRDE_DOOFS|WRDE_APPEND combination correctly o Do not confuse $( substitution with $(( shell arithmetic (noticed by wollman) o Handle backslash escaping properly o Allow $( and ${ to be quoted Notes: svn path=/head/; revision=108641
* Be more consistent with "static".Tim J. Robbins2002-12-271-1/+1
| | | | Notes: svn path=/head/; revision=108299
* Add an implementation of the POSIX wordexp() and wordfree() functions,Tim J. Robbins2002-12-261-0/+308
which perform shell-style word expansion on strings. This is still a little rough around the edges. PR: 13420 Notes: svn path=/head/; revision=108288