bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: declare a="$b" if $a previously set as array


From: Eduardo A . Bustamante López
Subject: Re: declare a="$b" if $a previously set as array
Date: Sun, 7 Dec 2014 22:16:39 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

On Sun, Dec 07, 2014 at 07:34:53PM -0800, Linda Walsh wrote:
> Only if you properly quote "external input".
Well, that's the whole point, as a script writer, I don't expect to get
arbitrary code execution here:

| address@hidden:~/t$ unset var; value='[$(ls -l)]=1 [2]=2'; declare -a 
var="($value)"; declare -p var
| bash: total 0: syntax error in expression (error token is "0")

Or here:
| address@hidden:~/t$ a=(1 2 3); k='a[$(ls -l)]'; echo "${a[k]}"
| bash: total 0: syntax error in expression (error token is "0")

And I *shouldn't* have to worry about that.


I know that I can do many things to avoid that, but, why? It's tedious, and
error prone. It shouldn't be this painful to write scripts that take arbitrary
user input. We have enough with word-splitting and quote-all-the-things, to
also be worrying about that.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]