Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'expressions': 0.07; 'problem?': 0.07; 'dict': 0.09; 'globals': 0.09; 'def': 0.10; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message-id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'string': 0.17; 'wrote:': 0.17; 'integer': 0.17; 'raise': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'prevent': 0.27; 'definition': 0.29; 'symbol': 0.33; 'values.': 0.33; 'to:addr:python-list': 0.33; 'skip:{ 10': 0.36; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'things': 0.38; 'to:addr:python.org': 0.39; 'access?': 0.84; 'blowing': 0.84; 'locals': 0.84; 'received:50.22': 0.84; 'edwards': 0.91 Date: Thu, 03 Jan 2013 19:11:18 -0600 From: Tim Chase User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Yet another attempt at a safe eval() call References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357265052 news.xs4all.nl 6921 [2001:888:2000:d::a6]:34667 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36097 On 01/03/13 17:25, Grant Edwards wrote: > def lessDangerousEval(expr): > global symbolTable > if 'import' in expr: > raise ParseError("operand expressions are not allowed to contain the string 'import'") > globals = {'__builtins__': None} > locals = symbolTable > return eval(expr, globals, locals) > > I can guarantee that symbolTable is a dict that maps a set of string > symbol names to integer values. For what definition of "safe"? Are CPython segfaults a problem? Blowing the stack? Do you aim to prevent exploitable things like system calls or network/file access? -tkc