Am 24.05.2013 02:34, schrieb Aaron Meurer:
> I don't think it can be made safe either (if anyone has any ideas,
> feel free to discuss them, though).
It's possible if you do it the way that many JSON libraries have
defanged their input: Replacing any eval call with a parser+evaluator,
and making the evaluator call only known-to-be-safe functions.
Determining a set of safe functions would be easier than for, say, a
Javascript engine, because we could restrict it to side-effect-free
functions.
We'd have to forbid calls to unknown-to-us third-party code, so that
would be a compatibility-breaking change. The workaround for the user
would be to rewrite his code to evaluate the third-party call, and stuff
the result into a Sympy or Python variable before using sympify. This
wouldn't work for those who use some code to generate Python code and
stuff that into sympify - such an approach would be rather insane from
my perspective, but non-CS engineers do insane stuff from a CS
engineer's perspective all day and get away with it, so I don't know
whether such a thing was done or not.
tl;dr: It could be done but would require a lot of work, and it might
break some rare code.
If sandboxing the Python interpreter is easy to do, it's not worth even
considering that.
Regards,
Jo