Commit 3ac51150 authored by Ralf Schmitt's avatar Ralf Schmitt

make 'locals()' not spew out __builtin__.__dict__ in backdoor

__builtins__ may either be the __builtin__ module or
__builtin__.__dict__. in the latter case typing locals() at the
backdoor prompt spews out lots of useless stuff. In the former case it
just prints "{'__builtins__': <module '__builtin__' (built-in)>,..."
parent b5b5d65c
......@@ -65,6 +65,12 @@ class SocketConsole(Greenlet):
try:
try:
console = InteractiveConsole(self.locals)
# __builtins__ may either be the __builtin__ module or
# __builtin__.__dict__ in the latter case typing
# locals() at the backdoor prompt spews out lots of
# useless stuff
import __builtin__
console.locals["__builtins__"] = __builtin__
console.interact(banner=self.banner)
except SystemExit: # raised by quit()
sys.exc_clear()
......
......@@ -68,6 +68,18 @@ class Test(greentest.TestCase):
finally:
server.stop()
def test_builtins(self):
server = backdoor.BackdoorServer(('127.0.0.1', 0))
server.start()
try:
conn = socket.create_connection(('127.0.0.1', server.server_port))
read_until(conn, '>>> ')
conn.sendall('locals()["__builtins__"]\r\n')
response = read_until(conn, '>>> ')
self.assertTrue(len(response) < 300, msg="locals() unusable: %s..." % response[:100])
finally:
server.stop()
if __name__ == '__main__':
greentest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment