bug-bash
[Top][All Lists]
Advanced

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

Re: Arbitrary command execution from test on a quoted string


From: Greg Wooledge
Subject: Re: Arbitrary command execution from test on a quoted string
Date: Sun, 31 Oct 2021 09:15:44 -0400

On Sun, Oct 31, 2021 at 09:05:22AM +0100, felix wrote:
> Unfortunely, this won't be useable with associative array, like:
> 
>    declare -A AssocVar='([Some string.]=foo)'
>    test -v AssocVar['Some string.'] && echo yes || echo no
>    yes
>    isvar AssocVar['Some string.']  && echo yes || echo no
>    no

You snipped the part where I explicitly said that it doesn't accept
indexed array elements like 'x[1]'.

But I think we're deep into an X-Y problem now.  If you want to use
an associative array for set membership testing, you don't NEED this.
You just assign a non-zero-length string to each element, and then
check the exit status of [[ ${myarray[$key]} ]].

You don't NEED all that -v stuff.  It's just a red herring.  An exploding
red herring.[1]

unicorn:~$ declare -A seen
unicorn:~$ key='some string.'
unicorn:~$ seen[$key]=y
unicorn:~$ [[ ${seen[$key]} ]] ; echo $?
0
unicorn:~$ [[ ${seen[xyz$key]} ]] ; echo $?
1

Don't over-complicate things.

[1] 
https://mywiki.wooledge.org/BashProgramming/05#Associative_Array_Index_Multiple_Expansions



reply via email to

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