Bug 1264482 - Fake an arbitrary __name__ in sandboxed global. r?ted draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 06 Apr 2016 09:35:40 +0900
changeset 350671 028c946bc4bb2b11e592e1758940bfc9cb669c3e
parent 350670 f8cf0fe7c810ee49bcb4efb27405073ae6156971
child 350672 7cd796912c3a6f73b2ec176ee44e7ab68f6ddcdd
push id15385
push userbmo:mh+mozilla@glandium.org
push dateThu, 14 Apr 2016 04:41:28 +0000
reviewersted
bugs1264482
milestone48.0a1
Bug 1264482 - Fake an arbitrary __name__ in sandboxed global. r?ted
build/moz.configure/checks.configure
python/mozbuild/mozbuild/configure/__init__.py
--- a/build/moz.configure/checks.configure
+++ b/build/moz.configure/checks.configure
@@ -8,17 +8,16 @@
 # ==============================================================
 
 # Declare some exceptions. This is cumbersome, but since we shouldn't need a
 # lot of them, let's stack them all here. When adding a new one, put it in the
 # _declare_exceptions template, and add it to the return statement. Then
 # destructure in the assignment below the function declaration.
 @template
 @imports(_from='__builtin__', _import='Exception')
-@imports(_from='__builtin__', _import='__name__')
 def _declare_exceptions():
     class FatalCheckError(Exception):
         '''An exception to throw from a function decorated with @checking.
         It will result in calling die() with the given message.
         Debugging messages emitted from the decorated function will also be
         printed out.'''
     return (FatalCheckError,)
 
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -685,16 +685,17 @@ class ConfigureSandbox(dict):
         glob = SandboxedGlobal(
             (k, v) for k, v in func.func_globals.iteritems()
             if (inspect.isfunction(v) and v not in self._templates) or (
                 inspect.isclass(v) and issubclass(v, Exception))
         )
         glob.update(
             __builtins__=self.BUILTINS,
             __file__=self._paths[-1] if self._paths else '',
+            __name__=self._paths[-1] if self._paths else '',
             os=self.OS,
             log=self.log_impl,
         )
         self._apply_imports(func, glob)
 
         # The execution model in the sandbox doesn't guarantee the execution
         # order will always be the same for a given function, and if it uses
         # variables from a closure that are changed after the function is