summary refs log tree commit diff
path: root/src/expand.c (follow)
Commit message (Collapse)AuthorAge
* [EXPAND] Optimise nulonly away and just use quoted as beforeHerbert Xu2014-10-08
| | | | | | | | This patch makes a small optimisation by using the same value for quoted between evalvar and varvalue by eliminating nulonly and passing along quoted instead. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Do not split quoted VSLENGTH and VSTRIMHerbert Xu2014-10-08
| | | | | | | Currently VSLENGTH and VSTRIM* are field-split even within quotes. This is obviously wrong. This patch fixes that. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Split unquoted $@/$* correctly when IFS is set but emptyHerbert Xu2014-10-08
| | | | | | | Currently we do not field-split $@/$* when it isn't quoted and IFS is set but empty. This is obviously wrong. This patch fixes this. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Propagate EXP_QPAT in subevalvarHerbert Xu2013-08-23
| | | | | | | | | | | | | | | | | | | | | | | On Tue, Aug 28, 2012 at 01:27:24PM +0000, Todor Vlaev wrote: > > While playing around with parameter expansion I noticed that the > following didn't work in dash (dash 0.5.5.1-7.4ubuntu1) as compared > to bash even though I believe it should be POSIX-compliant: > > my_str=swan; last_char="${my_str#${my_str%?}}"; echo ${last_char} > > If the double quotes are removed, the last character is printed correctly. > > At a quick glance through the commits after the 0.5.5.1 release I saw > the following bug fix. Could it be related? > > 0d7d66039b614b642c775432fd64aa8c11f9a64d > [EXPAND] Fix quoted pattern patch breakage We need to propagate EXP_QPAT in subevalvar as otherwise a nested parameter expansion within subevalvar may be expanded incorrectly. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Free IFS state after here document expansionJonathan Nieder2011-03-15
| | | | | | | | | | | | | | | | | | | | | | | Here's another bug bisecting to f42e443bb ([EXPAND] Fix ifsfirst/ifslastp leak, 2010-09-08). It was found with the following test case, based on the configure script for Tracker: dash -x -c ' <<-_ACEOF $@ _ACEOF exec ' - abcdefgh + + exec �a exec: 1: : Permission denied The missing ifsfree call is in expandarg when it returns to openhere during here document expansion. Reported-by: Aurelien Jarno <aurel32@debian.org> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [SHELL] Port to SolarisBrian Koropoff2011-03-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Solaris lacks paths.h and the various _PATH_* #defines. Check for them in configure.ac and fall back on the usual suspects when they are missing. - Older Solaris lacks isblank(), and versions that have it use a macro. Check for the declaration in configure.ac and fall back on a naive version when missing. - Older Solaris does not support %jd (intmax_t) in format strings, but it does support the PRIdMAX macro from inttypes.h. Do a configure check for PRIdMAX and use it in the code. If it doesn't exist, define it to "lld" when sizeof(long long) equals sizeof(intmax_t) as this is more likely to work on older systems. Otherwise, use "jd" and hope for the best. - Older Solaris lacks stdint.h, but inttypes.h provides the same types and works on all platforms I've tried dash on, so just use it instead. - Older Solaris doesn't like it when vsnprintf() is passed a NULL buffer (in violation of the POSIX spec, of course). Pass a 1-byte dummy buffer instead. - Solaris lacks tempfile and mktemp programs. Fall back on a "good-enough" custom function in mkbuiltins. Signed-off-by: Brian Koropoff <bkoropoff@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Fix backslash handling in read(1)Herbert Xu2011-03-11
| | | | | | | | | | | | The new read(1) implementation incorrectly assumes that ifsbreakup ignores characters escaped by CTLESC. As such it fails to handle backslashes except for escaping newlines. This patch makes it use recordregion for every part that isn't escaped by a backslash. Reported-by: Jilles Tjoelker <jilles@stack.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Do not split the result of tilde expansionJilles Tjoelker2011-03-10
| | | | | | | | | | | | | | | A tilde expansion generates a valid pathname. Splitting it using IFS either leaves it unchanged or changes it to something unintended. This fixes FreeBSD sh test expansion/tilde1.0 and does not change the outcome of the other tests. This fixes Debian bug #601096. Example: IFS=m HOME=/tmp; printf "%s\n" ~ Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Fix ifsfirst/ifslastp leak in casematchHerbert Xu2010-10-18
| | | | | | | | | | | | | The commit f42e443bb511ed3224f09b4fcf0772438ebdbbfa [EXPAND] Fix ifsfirst/ifslastp leak revealed yet another ifsfirst/ifslastp leak in casematch. Previously it was hidden because ifsfirst/ifslastp was cleared unconditionally on entry (which caused the leakage of those entries). Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Fix ifsfirst/ifslastp leakHerbert Xu2010-09-08
| | | | | | | | | | | | | | | | As it stands expandarg may return with a non-NULL ifslastp which then confuses any subsequent ifsbreakup user that doesn't clear it directly. What's worse, if we get interrupted before we hit ifsfree in expandarg we will leak memory. This patch fixes this by always calling ifsfree in expandarg thus ensuring that ifslastp is always NULL on the normal path. It also adds an ifsfree call to the RESET path to ensure that memory isn't leaked. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Fix corruption of redirections with byte 0x81Jilles Tjoelker2010-05-27
| | | | | | | | | | | | | | | | | | In other ash variants, a partial implementation of ksh-like cmd >file* adds and removes CTLESC bytes ('\x81') in redirection filenames, preserving 8-bit transparency. Long ago, dash removed the code to add the CTLESC bytes, but not the code to remove them, causing corruption of filenames containing CTLESC. This commit removes the code to remove the CTLESC bytes. The CTLESC byte occurs frequently in UTF-8 encoded non-Latin text. This bug has been reported various times to Ubuntu and Debian (e.g. Launchpad Ubuntu #422298). This patch is the same as the one submitted by Alexander Korolkov in Ubuntu #422298. Signed-off-by: Jilles Tjoelker <jilles@stack.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Honor tab as IFS whitespace when splitting fields in readcmdStefan Potyra2009-08-11
| | | | | | | | | | | | | | | | | | | When I try to split fields by tabs, dash doesn't honour multiple tabs between fields as whitespace (at least that's how I interpret [1], please correct me if I'm wrong). #!/bin/sh # "1\t2\t\t3" TESTSTRING="1 2 3" # only "\t" IFS=" " echo "$TESTSTRING" | while read p1 p2 p3; do echo "p1=${p1}, p2=${p2}, p3=${p3}" done Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Fix quoted pattern patch breakageHerbert Xu2009-06-27
| | | | | | | | | | | | | | The change [EXPAND] Do not quote back slashes in parameter expansions outside quotes broke quote removal after parameter expansion. This is because its effecte extended beyond that of quoted patterns. This patch fixes this by limiting the change to just quoted patterns. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Fixed non-leading slash treatment in expmetaHerbert Xu2008-05-19
| | | | | | | | | | | | | | | | | | | | | | | | | | Back in January an attempt was made to fix the interpretation of quoted slashes in expmeta. However, this only fixed those cases where the quoted slash is at the front of the word. The case of non-leading slashes caused the previous directory part to gain a back slash suffix which causes subsequent pattern matches to fail. This patch fixes this by removing the back slash in that case. Thanks to Romain Tartière fox reporting this bug. Test case: echo /*"/null" Old result: /*/null New result: /dev/null Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [SHELL] Fixed klibc/klcc build problemsDan McGee2008-05-03
| | | | | | | | | | | | klibc does not have mempcpy, so system.h must be included where this is used to provide the replacement. glob.h doesn't exist, so we need to guard this include with the HAVE_GLOB definition. Finally, klcc didn't like the syntax of the main definition in mksignames, and the resulting program segfaulted when trying to dereference any part of the argv array. Updating the main function definition solved the problem. Signed-off-by: Dan McGee <dpmcgee@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Fix slash treatment in expmetaHerbert Xu2008-05-02
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The change [EXPAND] Do not quote back slashes in parameter expansions outside quotes triggered a latent bug in expmeta where the forward slashes when preceded by a blackslash weren't recognised as directory separators. This was hidden because a work-around was put in place for glob(3) which meant that we never had any backslashes immediately before forward slashes. This patch fixes the metaflag loop to recognise forward slashes even when they follow a backslash. Thanks to Daniel Hahler for reporting this problem. Test case: echo "/"root* Old result: /root* New result: /root Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Expand here-documents in the current shell environmentHerbert Xu2007-11-11
| | | | | | | | | | | | | | | | | | | | | | | | | | Previously we always expanded here-documents in a subshell. This is contrary to the POSIX specification and how other shells behave. What's more this slows down many expansions due to the extra fork (however, it must be said that it is possible for it speed up certain expansions by running it simultaneously with the command on two CPUs). This patch move the expansion into the current shell environment. Test case: unset a cat <<- EOF > /dev/null ${a=NOT} EOF echo ${a}BAD Old result: BAD New result: NOTBAD
* [EXPAND] Removed herefd hackHerbert Xu2007-11-11
| | | | | | | | | | | The herefd hack goes back more than a decade. it limits the amount of memory we have to allocate when expanding here-documents by writing the result out from time to time. However, it's no longer safe because the stack is used to place intermediate results too and there we certainly don't want to write them out should we be short on memory. In any case, with today's computers we can afford to keep the entire result in memory and write them out at the end.
* [EXPAND] Added configure --enable-glob and --enable-fnmatch optionsHerbert Xu2007-10-20
| | | | | | | | Debian's libc6 as of 2.6.1-6 has working glob(3)/fnmatch(3) support. This patch adds the options --enable-glob and --enable-fnmatch to the configure script. By default glob(3) and fnmatch(3) are still unused. However, on distros where the glibc is known to work you may enable these options.
* [EXPAND] Add likely flags in expariHerbert Xu2007-10-11
| | | | The case where the expansion isn't quoted is the norm.
* [ARITH] Add assignment and intmax_t supportHerbert Xu2007-10-11
| | | | | This patch adds assignment operator support in arithmetic expansions. It also changes the type used to intmax_t.
* [PARSER] Report substition errors at expansion timeHerbert Xu2007-10-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Wed, Apr 11, 2007 at 01:24:21PM -0700, Micah Cowan wrote: > Package: dash > Version: 0.5.3-3 > > Bug first reported against Ubuntu at > https://bugs.launchpad.net/ubuntu/+source/dash/+bug/105634 > by Paul Smith > > The description and some comments from that bug report follow. > > ----- > > This operation fails on Ubuntu: > > $ /bin/sh -c 'if false; then d="${foo/bar}"; fi' > /bin/sh: Syntax error: Bad substitution > > When used with other POSIX shells it succeeds. While semantically the > variable reference ${foo/bar} is not valid, this is not a syntax error > according to POSIX, and since the variable assignment expression is > never invoked (because it's within an "if false") it should not be seen > as an error. > > I ran into this because after restarting my system I could no longer log > in. It turns out that the problem was (a) I had edited .gnomerc to > source my .bashrc file so that my environment would be set properly, and > (b) I had added some new code to my .bashrc WITHIN A CHECK FOR BASH! > that used bash's ${var/match/sub} feature. Even though this code was > within a "case $BASH_VERSION; in *[0-9]*) ... esac (so dash would never > execute it since that variable is not set), it still caused dash to > throw up. > > ----- > > FYI, some relevant details from POSIX: > > Section 2.3, Token Recognition: > > 5. If the current character is an unquoted '$' or '`', the shell shall > identify the start of any candidates for parameter expansion ( Parameter > Expansion), command substitution ( Command Substitution), or arithmetic > expansion ( Arithmetic Expansion) from their introductory unquoted > character sequences: '$' or "${", "$(" or '`', and "$((", respectively. > The shell shall read sufficient input to determine the end of the unit > to be expanded (as explained in the cited sections). > > Section 2.6.2, Parameter Expansion: > > The format for parameter expansion is as follows: > > ${expression} > > where expression consists of all characters until the matching '}'. Any > '}' escaped by a backslash or within a quoted string, and characters in > embedded arithmetic expansions, command substitutions, and variable > expansions, shall not be examined in determining the matching '}'. > > [...] > > The parameter name or symbol can be enclosed in braces, which are > optional except for positional parameters with more than one digit or > when parameter is followed by a character that could be interpreted as > part of the name. The matching closing brace shall be determined by > counting brace levels, skipping over enclosed quoted strings, and > command substitutions. > > --- > > In addition to bash I've checked Solaris /bin/sh and ksh and they don't > report an error. > > ----- > Micah Cowan: > > The applicable portion of POSIX is in XCU 2.10.1: > > "The WORD tokens shall have the word expansion rules applied to them > immediately before the associated command is executed, not at the time > the command is parsed." > > This seems fairly clear to me. This patch moves the error detection to expansion time. Test case: if false; then echo ${a!7} fi echo OK Old result: dash: Syntax error: Bad substitution New result: OK
* [MEMALLOC] Add pushstackmarkHerbert Xu2007-10-06
| | | | | | | | This patch gets rid of the stack mark tracking hack by allocating a little bit of stack memory if we're at risk of planting a stack mark which may be grown later. To do this a new function pushstackmark is added which lets the user pick a bigger amount to allocate since some users do that anyway after setting a stack mark.
* [EXPAND] Refresh stack pointers after makestrspace in _rmescapesRoy Marples2007-09-26
| | | | | | | | | | | | | | | | | | | | | | | | | | | dash-0.5.3 has an issue reading some line lengths [1]. This is reproducable on amd64, but not on other arches for some reason. $ cat bug.sh (read line; echo "${line%%=*}") <<EOF TITLE=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx EOF printf "\ TITLE=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " | (read line; echo "${line%%=*}") $ bash bug.sh TITLE TITLE $ dash bug.sh TITLE=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TITLE Attahced is a patch to fix the issue Thanks Roy [1] http://bugs.gentoo.org/show_bug.cgi?id=180680
* [EXPAND] Move parse-time quote flag detection to run-timeHerbert Xu2007-09-25
| | | | | | | | | | | | | | | | | | | | Because the parser does not recursively parse parameter expansion with respect to quotes, we can't accurately determine quote status at parse time. This patch works around this by moving the quote detection to run-time where we do interpret it recursively. Test case: foo=\\ echo "<${foo#[\\]}>" Old result: <\> New result: <>
* [EXPAND] Do not expand tilde in parameter expansion within quotesHerbert Xu2007-09-25
| | | | | | | | | | | | | | | | | | | | | | | Previously code was added so that tilde expansion was carried out parameter expansions within double quotes. This change was made with reference the behaviour of bash at the time. Bash has since be fixed so that this behaviour no longer occurs which is in line with most other POSIX shells. So this patch removes that behaviour in dash as well. Test case: unset a echo "${a:-~root}" Old result: /root New result: ~root
* [EXPAND] Perform tilde expansion in all parameter expansion wordsHerbert Xu2007-09-24
| | | | | | | | | | | | | | | | | | Previously tilde expansion was not carried out for =?#% expansion words. This is contrary to the POSIX specification. Test case: a=~root:~root echo ${a#~root} Old result: /root:/root New result: :/root
* [EXPAND] Do not quote back slashes in parameter expansions outside quotesHerbert Xu2007-09-24
| | | | | | | | | | | | | | | | Test case: a=/b/c/* b=\\ echo ${a%$b*} Old result: /b/c/* New result: /b/c/
* [EXPAND] Fixed inverted char class matchingHerbert Xu2006-10-04
| | | | | | | | The return value of ccmatch was being treated as 0 or 1 but it's actually zero or non-zero. This broke inverted character class matching. Reported by Alexander Skwar.
* [PARSER] Only use signed char for syntax arraysHerbert Xu2006-04-23
| | | | | | | | | The existing scheme of using the native char for syntax array indicies makes cross-compiling difficult. Therefore it makes sense to choose one specific sign for everyone. Since signed chars are native to most platforms and i386, it makes more sense to use that if we are to choose one type for everyone.
* Added missing system.h inclusion for mempcpyHerbert Xu2005-10-29
| | | | All users of mempcpy must include system.h.
* Fixed gcc 4.0 compilation problemsHerbert Xu2005-10-29
| | | | | | | | Removed obsolete extern declaration on funcnest. This conflits with the correct static definition. Changed memtodest prototype to use char * instead of unsigned char *. Perform the unsigned char cast inside memtodest instead.
* [EXPAND] Added getpwhome as a wrapper for getpwnamHerbert Xu2005-10-29
| | | | | klibc doesn't have and doesn't need getpwnam. This change creates getpwhome which always returns NULL if getpwnam doesn't exist.
* Copyright/licence updates and remove all traces of sys/cdefs.hHerbert Xu2005-10-29
| | | | | | | | | | | This change updates the BSD licence to the three-clause version since NetBSD has already done so. This makes dash GPL-compatible. It also adds Christos Zoulas (NetBSD ash maintainer) to the COPYING file. I've added "copyright by Herbert Xu" to most files. Finally all CVS IDs and inclusion of sys/cdefs.h have been removed. The latter is needed for support of klibc.
* Removed some unnecessary inclusions of input.h.herbert2005-09-26
|
* Renamed error to sh_error.herbert2005-09-26
|
* Fixed signed char promotion in src/expand.c.herbert2005-09-26
|
* Size optimisations around varvalue() in src/expand.c.herbert2005-09-26
|
* Fixed expansion when leading argument is null in src/expand.c.herbert2005-09-26
|
* Initial import.Herbert Xu2005-09-26