DASH Shell discussions
 help / color / mirror / Atom feed
From: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Jesper Bengtsson <jesper.bengtsson@axis.com>, dash@vger.kernel.org
Subject: Re: Parameter expansion fails when assigning a local variable
Date: Tue, 30 Jun 2009 18:17:50 +0200 (CEST)	[thread overview]
Message-ID: <0906301817190.14361@somehost> (raw)
In-Reply-To: <20090630013807.GA13339@gondor.apana.org.au>

On Tue, 30 Jun 2009, Herbert Xu wrote:

> On Mon, Jun 29, 2009 at 07:10:29PM +0200, Cristian Ionescu-Idbohrn wrote:
> >
> > Please consider this example script:
> >
> > ---8<---
> > #!/bin/dash
> >
> > set -e
> > #set -x
> >
> > func() {
> > 	local i=0 v xx="$@"
> >
> > 	for v; do
> > 		i=$(($i + 1))
> > 		echo "func arg. $i: '$v'"
> > 	done
> > 	echo "inside func: NOONE_SHOULD_TOUCH_THIS=$NOONE_SHOULD_TOUCH_THIS"
> > }
> >
> > NOONE_SHOULD_TOUCH_THIS=protected
> > echo "main, bef. func: NOONE_SHOULD_TOUCH_THIS=$NOONE_SHOULD_TOUCH_THIS"
> > func "$@"
> > echo "main, aft. func: NOONE_SHOULD_TOUCH_THIS=$NOONE_SHOULD_TOUCH_THIS"
> >
> > exit 0
> > ---8<---
> >
> > and run the script like this:
> >
> > 	$ <script path> abc NOONE_SHOULD_TOUCH_THIS=overwritten
> >
> > Is it the intended behaviour?  Should one be able to overwrite script
> > function variables from command line?
>
> As I said, you should be using "$*" instead of "$@" which is
> designed exactly for this purpose and is completely portable.

Sure I will.  But that won't make the misfeature go away :(

And, by the way, I think the bug should probably be classified as a design
flaw and a security bug.  Reason is it has undesired side effects which
may lead to overwriting unrelated local variables and may have other
serious implications.


Cheers,

-- 
Cristian

  reply	other threads:[~2009-06-30 16:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-22  8:13 Parameter expansion fails when assigning a local variable Jesper Bengtsson
2009-06-22  8:57 ` Herbert Xu
2009-06-28 21:39   ` Cristian Ionescu-Idbohrn
2009-06-29  0:47     ` Herbert Xu
2009-06-29 17:10       ` Cristian Ionescu-Idbohrn
2009-06-30  1:38         ` Herbert Xu
2009-06-30 16:17           ` Cristian Ionescu-Idbohrn [this message]
2009-07-01  7:42             ` Oleg Verych
2009-07-02 16:53               ` Cristian Ionescu-Idbohrn
2009-07-03 21:14                 ` Oleg Verych

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0906301817190.14361@somehost \
    --to=cristian.ionescu-idbohrn@axis.com \
    --cc=dash@vger.kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=jesper.bengtsson@axis.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox