Skip to content

safe use of exec function #133

@test-fullautomation

Description

@test-fullautomation

The exec function shall be used with a limited scope, according to the concrete needs.

Uses shall look similar to this:

   def _bExecuteEvalCode(self,sEvalCode,sErrorMsg=''):
       #bResult=False
       bResultTmp = False
       dLocals = {"self": self, "bResult": False} # self to access dInParams
       try:
          #print sEvalCode
          #Execute the assembled code snipplet
          exec(sEvalCode, {}, dLocals)
       except Exception as reason:
          sMsg="eval code"
          if sErrorMsg!='':
             sMsg=sErrorMsg
          raise Exception(sMsg +" can't be executed: %s \r\nReason: '%s'" % ( str(sEvalCode) , str(reason)))
       finally:
          pass

       return dLocals['bResult']

Metadata

Metadata

Assignees

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions