summaryrefslogtreecommitdiffstats
path: root/bin/sh/parser.h
Commit message (Collapse)AuthorAgeFilesLines
* wordexp: Rewrite to make WRDE_NOCMD reliable.jilles2015-09-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* sh: Allow aliases to force alias substitution on the following word.jilles2014-01-261-0/+1
| | | | | | | | If an alias's value ends with a space or tab, the next word is also checked for aliases. This is a POSIX feature. It is useful with utilities like command and nohup (alias them to themselves followed by a space).
* sh: Cast -1 to pointer rather than pointer to variable of wrong type.jilles2013-08-301-4/+2
| | | | | | | | | | NEOF needs to be a non-null pointer distinct from valid union node pointers. It is not dereferenced. The new NEOF is much like SIG_ERR except that it is an object pointer instead of a function pointer. The variable tokpushback can now be static.
* sh: Remove unnecessary reset functions.jilles2013-08-161-1/+0
| | | | These are already handled by exception handlers.
* sh: Remove mkinit.jilles2013-07-251-0/+1
| | | | | | | | | | | | | | Replace the RESET blocks with regular functions and a reset() function that calls them all. This code generation tool is unusual and does not appear to provide much benefit. I do not think isolating the knowledge about which modules need to be reset is worth an almost 500-line build tool and wider scope for variables used by the reset functions. Also, relying on reset functions is often wrong: the cleanup should be done in exception handlers so that no stale state remains after 'command eval' and the like.
* sh: Fix various compiler warnings.jilles2013-04-011-1/+1
| | | | | | | It now passes WARNS=7 with clang on i386. GCC 4.2.1 does not understand setjmp() properly so will always trigger -Wuninitialized. I will not add the volatile keywords to suppress this.
* sh: Fix a comment.jilles2013-02-071-1/+1
|
* sh: Do parameter expansion before printing PS4 (set -x).jilles2011-06-091-0/+1
| | | | | | | | | | | | | | | | The function name expandstr() and the general idea of doing this kind of expansion by treating the text as a here document without end marker is from dash. All variants of parameter expansion and arithmetic expansion also work (the latter is not required by POSIX but it does not take extra code and many other shells also allow it). Command substitution is prevented because I think it causes too much code to be re-entered (for example creating an unbounded recursion of trace lines). Unfortunately, our LINENO is somewhat crude, otherwise PS4='$LINENO+ ' would be quite useful.
* sh: Expand aliases after assignments and redirections.jilles2011-05-211-0/+1
|
* sh: Change the CTL* bytes to ones invalid in UTF-8.jilles2011-05-061-8/+8
| | | | | | | | | | | | | This ensures that mbrtowc(3) can be used directly once it has been verified that there is no CTL* byte. Dealing with a CTLESC byte within a multibyte character would be complicated. The new values do occur in iso-8859-* encodings. This decreases efficiency slightly but should not affect correctness. Caveat: Updating across this change and rebuilding without cleaning may yield a subtly broken sh binary. By default, make buildworld will clean and avoid problems.
* sh: Do IFS splitting on word in ${v+word} and ${v-word}.jilles2010-10-291-0/+1
| | | | | | | | | | | | | | | | | The code is inspired by NetBSD sh somewhat, but different because we preserve the old Almquist/Bourne/Korn ability to have an unquoted part in a quoted ${v+word}. For example, "${v-"*"}" expands to $v as a single field if v is set, but generates filenames otherwise. Note that this is the only place where we split text literally from the script (the similar ${v=word} assigns to v and then expands $v). The parser must now add additional markers to allow the expansion code to know whether arbitrary characters in substitutions are quoted. Example: for i in ${$+a b c}; do echo $i; done Exp-run done by: pav (with some other sh(1) changes)
* sh: Various warning fixes (from WARNS=6 NO_WERROR=1):jilles2009-12-271-0/+1
| | | | | | | - const - initializations to silence -Wuninitialized (it was safe anyway) - remove nested extern declarations - rename "index" locals to "idx"
* sh: Constify various strings.jilles2009-12-241-1/+1
| | | | | Most of this is adding const keywords, but setvar() in var.c had to be changed somewhat more.
* Expand $LINENO to the current line number. This is required by SUSv3's "Userstefanf2008-05-151-3/+5
| | | | | | | | | Portability Utilities" option. Often configure scripts generated by the autotools test if $LINENO works and refuse to use /bin/sh if not. Package test run by: pav
* When parsing an invalid parameter expansion (eg. ${} or ${foo@bar}) do notstefanf2006-11-051-0/+1
| | | | | | | | | | | issue a syntax error immediately but save the information that it is erroneous for later when the parameter expansion is actually done. This means eg. "false && ${}" will not generate an error which seems to be required by POSIX. Include the invalid parameter expansion in the error message (sometimes abbreviated with ... because recovering it would require a lot of code). PR: 105078 Submitted by: emaste
* Remove clause 3 from the UCB licenses.markm2004-04-061-4/+0
| | | | OK'ed by: imp, core
* o __P has been reovedimp2002-02-021-4/+4
| | | | | | | | | | | | | | | | | | o Old-style K&R declarations have been converted to new C89 style o register has been removed o prototype for main() has been removed (gcc3 makes it an error) o int main(int argc, char *argv[]) is the preferred main definition. o Attempt to not break style(9) conformance for declarations more than they already are. o Change int foo() { ... to int foo(void) { ...
* $Id$ -> $FreeBSD$peter1999-08-271-1/+1
|
* Better handling of word splitting. Don't record the same regiontegge1998-09-061-1/+2
| | | | | | multiple times when performing nested variable expansion, and preserve some quoting information in order to avoid removing apparently empty expansion result.
* Revert $FreeBSD$ to $Id$peter1997-02-221-1/+1
|
* Make the long-awaited change from $Id$ to $FreeBSD$jkh1997-01-141-1/+1
| | | | | | | | This will make a number of things easier in the future, as well as (finally!) avoiding the Id-smashing problem which has plagued developers for so long. Boy, I'm glad we're not using sup anymore. This update would have been insane otherwise.
* Merge in NetBSD mods and -Wall cleaning.steve1996-12-141-2/+2
| | | | Obtained from: NetBSD, me
* Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is apeter1996-09-011-19/+19
| | | | | | | | | | | | | | merge of parallel duplicate work by Steve Price and myself. :-] There are some changes to the build that are my fault... mkinit.c was trying (poorly) to duplicate some of the work that make(1) is designed to do. The Makefile hackery is my fault too, the depend list was incomplete because of some explicit OBJS+= entries, so mkdep wasn't picking up their source file #includes. This closes a pile of /bin/sh PR's, but not all of them.. Submitted by: Steve Price <steve@bonsai.hiwaay.net>, peter
* Added $Id$dg1994-09-241-0/+1
|
* BSD 4.4 Lite bin Sourcesrgrimes1994-05-261-0/+80
OpenPOWER on IntegriCloud