message = "You need to specify an expression."
else:
try:
- message = repr(eval(" ".join(arguments[1:])))
+ # there is no other option than to use eval() for this, since
+ # its purpose is to evaluate arbitrary expressions, so do what
+ # we can to secure it and whitelist it for bandit analysis
+ message = repr(eval( # nosec
+ " ".join(arguments[1:]),
+ {"mudpy": mudpy, "universe": actor.universe}))
except Exception as e:
message = ("$(red)Your expression raised an exception...$(eol)"
"$(eol)$(bld)%s$(nrm)" % e)
test_show_result = (
(2, "> ", "show result 12345*67890"),
(2, r"\r\n838102050\r\n.*> ", "show result 1/0"),
- (2, r"Your expression raised an exception.*division by zero.*> ", ""),
+ (2, r"Your expression raised an exception.*division by zero.*> ",
+ "show result mudpy"),
+ (2, r"<module 'mudpy' from .*> ", "show result re"),
+ (2, r"Your expression raised an exception.*name 're' is not defined.*> ",
+ "show result universe"),
+ (2, r"<mudpy.misc.Universe object at 0x.*> ", "show result actor"),
+ (2, r"Your expression raised an exception.*name 'actor' is not "
+ r"defined.*> ", ""),
)
test_show_log = (