Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5ae01a

Browse files
committed
Applying patch
[#636769] Fix for major rexec bugs * Lib/rexec.py (FileBase): Added 'xreadlines' and '__iter__' to allowed file methods. (FileWrapper.__init__): Removed unnecessary self.f variable, which gave direct access to the file object. (RExec): Added 'xreadlines' and '_weakref' to allowed modules. (RExec.r_open): Convert string subclasses to a real string classes before doing comparisons with mode parameter. * Lib/ihooks.py (BasicModuleImporter.import_module/reload/unload): Convert the module name to a real string before working with it. (ModuleImporter.import_module/import_it/reload): Convert the module name to a real strings before working with it. * Misc/NEWS Document the change.
1 parent 822a77f commit d5ae01a

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

Lib/ihooks.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ def set_hooks(self, hooks):
352352
return self.loader.set_hooks(hooks)
353353

354354
def import_module(self, name, globals={}, locals={}, fromlist=[]):
355+
name = str(name)
355356
if name in self.modules:
356357
return self.modules[name] # Fast path
357358
stuff = self.loader.find_module(name)
@@ -360,14 +361,14 @@ def import_module(self, name, globals={}, locals={}, fromlist=[]):
360361
return self.loader.load_module(name, stuff)
361362

362363
def reload(self, module, path = None):
363-
name = module.__name__
364+
name = str(module.__name__)
364365
stuff = self.loader.find_module(name, path)
365366
if not stuff:
366367
raise ImportError, "Module %s not found for reload" % name
367368
return self.loader.load_module(name, stuff)
368369

369370
def unload(self, module):
370-
del self.modules[module.__name__]
371+
del self.modules[str(module.__name__)]
371372
# XXX Should this try to clear the module's namespace?
372373

373374
def install(self):
@@ -394,7 +395,7 @@ class ModuleImporter(BasicModuleImporter):
394395

395396
def import_module(self, name, globals=None, locals=None, fromlist=None):
396397
parent = self.determine_parent(globals)
397-
q, tail = self.find_head_package(parent, name)
398+
q, tail = self.find_head_package(parent, str(name))
398399
m = self.load_tail(q, tail)
399400
if not fromlist:
400401
return q
@@ -480,16 +481,18 @@ def import_it(self, partname, fqname, parent, force_load=0):
480481
path = parent and parent.__path__
481482
except AttributeError:
482483
return None
484+
partname = str(partname)
483485
stuff = self.loader.find_module(partname, path)
484486
if not stuff:
485487
return None
488+
fqname = str(fqname)
486489
m = self.loader.load_module(fqname, stuff)
487490
if parent:
488491
setattr(parent, partname, m)
489492
return m
490493

491494
def reload(self, module):
492-
name = module.__name__
495+
name = str(module.__name__)
493496
if '.' not in name:
494497
return self.import_it(name, name, None, force_load=1)
495498
i = name.rfind('.')

Lib/rexec.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
class FileBase:
3030

3131
ok_file_methods = ('fileno', 'flush', 'isatty', 'read', 'readline',
32-
'readlines', 'seek', 'tell', 'write', 'writelines')
32+
'readlines', 'seek', 'tell', 'write', 'writelines', 'xreadlines',
33+
'__iter__')
3334

3435

3536
class FileWrapper(FileBase):
3637

3738
# XXX This is just like a Bastion -- should use that!
3839

3940
def __init__(self, f):
40-
self.f = f
4141
for m in self.ok_file_methods:
4242
if not hasattr(self, m) and hasattr(f, m):
4343
setattr(self, m, getattr(f, m))
@@ -137,7 +137,8 @@ class RExec(ihooks._Verbose):
137137
'cmath', 'errno', 'imageop',
138138
'marshal', 'math', 'md5', 'operator',
139139
'parser', 'regex', 'pcre', 'rotor', 'select',
140-
'sha', '_sre', 'strop', 'struct', 'time')
140+
'sha', '_sre', 'strop', 'struct', 'time',
141+
'xreadlines', '_weakref')
141142

142143
ok_posix_names = ('error', 'fstat', 'listdir', 'lstat', 'readlink',
143144
'stat', 'times', 'uname', 'getpid', 'getppid',
@@ -515,6 +516,7 @@ def r_open(self, file, mode='r', buf=-1):
515516
used to change the policies enforced by a restricted environment.
516517
517518
"""
519+
mode = str(mode)
518520
if mode not in ('r', 'rb'):
519521
raise IOError, "can't open files for writing in restricted mode"
520522
return open(file, mode, buf)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,9 @@ Library
667667
unix environment even if DISPLAY was not set. Also, support for
668668
skipstone browser was included.
669669

670+
- Fixed bug #636769: rexec would run unallowed code if subclasses of
671+
strings were used as parameters for certain functions.
672+
670673
Tools/Demos
671674
-----------
672675

0 commit comments

Comments
 (0)