On Mon, Feb 8, 2010 at 5:51 PM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steven@remove.this.cybersource.com.au">steven@remove.this.cybersource.com.au</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Mon, 08 Feb 2010 14:43:46 -0800, Aahz wrote:<br>
<br>
>>> WARNING: eval() is almost always the wrong answer to any question<br>
>><br>
>>warning : it works !<br>
><br>
> Works for what?<br>
<br>
</div>Code injection security bugs, of course.<br>
<br>
<a href="http://en.wikipedia.org/wiki/Code_injection" target="_blank">http://en.wikipedia.org/wiki/Code_injection</a><br>
<br>
It is surprisingly difficult to sanitize strings in Python to make them<br>
safe to pass to eval. Unless you are prepared to trust the input data<br>
explicitly, it's best to just avoid eval.<br></blockquote><div><br></div><div>I'd make it a bit stronger: unless you are prepared to trust the input data explicitly, and forever-- and extending that trust to whomever might in the future be hired to work along, beside, under, or instead of you-- including the fact that they may use your system or code in a different or new way to get the data-- or how you may in the future decide to grow your system in ways you're not today prepared for and are committed to do a complete review of your entire codebase on every such change to ensure you don't leak some potentially bad data down into such a place-- then you can use eval. Otherwise, other solutions are better.</div>
<div><br></div><div>--S</div><div> </div></div>