Introduction

Almost all extensions I (PascalBauermeister) wrote are using eval to parse parameters.

I know that it is a potentially (very) dangerous thing to do, but on the other hand it unleashs a great deal of flexibility.

As I was expecting, some feedback came. FlorianFesti wrote about ProcessorMarket/if.py:

See my feedback below.

Security measures

The Python eval function is described there: http://docs.python.org/lib/built-in-funcs.html#l2h-23

The code uses eval this way (example of ProcessorMarket/if.py):

So there are 3 things cared for:

  1. no builtin functions allowed (solves issue described in MacroMarket/SearchInPagesAndSort/SecurityHole)

  2. access to well-defined objects, one variable and one function in the above example
  3. enclosed in a try-except statement

When applied to ProcessorMarket/if.py, this:

But there are certainly other issues I don't see now...

This simply run for long time, without memory error:

eval('10 ** 10000000000000000000000')

These also seems to run forever, consuming all memory (1.5G installed), trashing, no error:

eval('zip(["x" * 10000000] * 100000000, ["x" * 10000000] * 100000000)')
eval('dict([("x" * 100000000, "x" * 1000000000)] * 100000000)')
eval('dict([((None, None) * 100000000, (None, None) * 100000000)] * 100000000)')

eval is lot of fun, do use it :-)

Comments and discussion

Even if you set builtins to an empty list, there are still lots of things the code can do in a single expression. This is from a post I sent to the Python mailing list:

MoinMoin: UsingEval (last edited 2010-01-09 16:55:06 by PascalBauermeister)