oss-sec mailing list archives

More parser odities


From: "Kobrin, Eric" <ekobrin () akamai com>
Date: Wed, 1 Oct 2014 16:35:49 -0500

Using bash from the GNU git, subsequently patched to level 28:

$ env $'BASH_FUNC_#badname%%'=$'() { :; }\nfoo () { echo wrongfunc; } ' ./bash -c 'foo'
./bash: error importing function definition for `#badname'
wrongfunc


This is an artifact of the name and value being passed directly to parse_and_execute, separated by a space. Structures 
started in the name such as comments, quoted strings, etc. are allowed to continue into the body. Some of the existing 
safety checks stop the obvious attacks, but things like this can still get through.


I don't know of a safe way to pass the contents of an environment variable to parse_and_execute. Has anyone worked on a 
simplified grammar which could be more rigorously checked?

If there were one, with a parser called bash-simple-parse in following example, this problem would be easier to manage.

This way `function f() {...}' can be parsed, but `export -f f' could store a version of the function readable by 
bash-simple-parse. The function importer can then call bash-simple-parse and extract a function definition, knowing 
that nothing other than a function definition (not even the name) will be returned. That result can then be bound to 
the name provided, directly in the variable setup function without ever invoking the general parser.

Thoughts?

-- Eric Kobrin



Current thread: