[Top][All Lists]

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

Re: Issues with exported functions

From: Linda Walsh
Subject: Re: Issues with exported functions
Date: Wed, 24 Sep 2014 21:23:52 -0700
User-agent: Thunderbird

lolilolicon wrote:
Obviously, the newly disclosed CVE-2014-6271 is pretty bad.

It's been patched now, but I think it's worthwhile to further discuss
how exported functions are implemented in bash.

I'm no bash expert: before today I didn't even realize bash functions
can be exported. And I certainly wouldn't expect this to work:

    % fun='() { :;}' bash -c 'declare -pf fun'
    fun ()
    declare -fx fun
So Magic!
   ???  It doesn't seem to work for me... what am I missing?

 fun='() { :;}' bash -c 'declare -pf fun'
bash: line 0: declare: fun: not found
Maybe exporting fun?

 export fun='() { :;}'
 bash -c 'declare -pf fun'
bash: line 0: declare: fun: not found
I've never seen functions created with an assignment.  Is this a
new syntax in 4.3?

(still in 4.2.43 here)...

Because bash interprets a variable in the environment that starts with
'() {' as a function, bash cannot import a *variable* whose value
matches that pattern, eg

    % var='() {' bash -c 'declare -p var'
    bash: var: line 1: syntax error: unexpected end of file
    bash: error importing function definition for `var'
    bash: line 0: declare: var: not found

This is an undocumented "feature".

Since the only way for bash to support exporting / importing function
definitions via environment variables is to have some magic token like
'() {', the question comes down to whether bash should support exported
functions at all.

Personally, I have never needed this feature. I would vote for its
removal: It's very surprising, creates bugs, and is not very useful.

Otherwise, if this feature is going to stay (can anyone enlighten me why
it's useful?), please document it explicitly.

As it is currently, this is a real pitfall.

reply via email to

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