Why should exec() and eval() be avoided?

后端 未结 11 2116
Happy的楠姐
Happy的楠姐 2020-11-22 00:16

I\'ve seen this multiple times in multiple places, but never have found a satisfying explanation as to why this should be the case.

So, hopefully, one will be prese

11条回答
  •  轮回少年
    2020-11-22 00:55

    s = "import shutil; shutil.rmtree('/nonexisting')"
    eval(s)
    

    Now assume somebody can control s from a web application, for example.

    Don't try to do this on your computer

提交回复
热议问题