[Python-checkins] r51901 - python/branches/bcannon-objcap/Lib/test/security/evil__del__.py
brett.cannon
python-checkins at python.org
Sun Sep 17 20:06:25 CEST 2006
Author: brett.cannon
Date: Sun Sep 17 20:06:24 2006
New Revision: 51901
Modified:
python/branches/bcannon-objcap/Lib/test/security/evil__del__.py
Log:
Another attempt to get at open() through the use of an evil __del__() method.
So far been unable to craft one that uses another interpreter's scope to
resolve the built-in namespace.
Modified: python/branches/bcannon-objcap/Lib/test/security/evil__del__.py
==============================================================================
--- python/branches/bcannon-objcap/Lib/test/security/evil__del__.py (original)
+++ python/branches/bcannon-objcap/Lib/test/security/evil__del__.py Sun Sep 17 20:06:24 2006
@@ -8,6 +8,9 @@
stdout = sys.stdout
NameError = NameError
BaseException = BaseException
+ ImportError = ImportError
+ KeyError = KeyError
+ TypeError = TypeError
def __init__(self, num):
self.num = num
@@ -29,9 +32,23 @@
self.stdout.write("(%s) Second Evil!\n" % self.num)
finally:
self.stdout.flush()
+ try:
+ import __builtin__
+ temp = __builtin__.__dict__['open']
+ except self.ImportError:
+ self.stdout.write("(%s) Third Good!\n" % self.num)
+ except self.KeyError:
+ self.stdout.write("(%s) Third Good!\n" % self.num)
+ except self.TypeError:
+ self.stdout.write("(%s) Third Good!\n" % self.num)
+ except self.BaseException, exc:
+ self.stdout.write("Unexpected exception (2): %r\n" % exc)
+ finally:
+ self.stdout.flush()
+
# Deletion in own scope.
-Evil(0)
+temp = Evil(0)
# Cleanup of interpreter.
__builtin__.__dict__['evil1'] = Evil(1)
@@ -43,12 +60,16 @@
import interpreter
import __builtin__
+import gc
interp = interpreter.Interpreter()
print 'Same builtins?:', ('no' if id(__builtin__.__dict__) !=
id(interp.builtins) else 'yes')
del interp.builtins['open']
+gc.collect()
+if 'open' not in __builtin__.__dict__:
+ print "'open()' missing!"
print 'Running interpreter ...'
interp.execute(evil_str)
@@ -57,8 +78,10 @@
print 'Deleting interpreter ...'
del interp
+gc.collect()
print 'Explicitly deleting locally ...'
del evil2
+gc.collect()
print 'Implicit deletion locally from interpreter teardown ...'
More information about the Python-checkins
mailing list