|
63 | 63 | # (beware that this is NOT foolproof at all ... there are known flaws!) |
64 | 64 | # |
65 | 65 | # ALWAYS use defense-in-depth and don't just rely on these simple mechanisms |
66 | | -import resource |
| 66 | +try: |
| 67 | + import resource |
| 68 | + resource_module_loaded = True |
| 69 | +except ImportError: |
| 70 | + # Google App Engine doesn't seem to have the 'resource' module |
| 71 | + resource_module_loaded = False |
67 | 72 |
|
68 | 73 |
|
69 | 74 | # ugh, I can't figure out why in Python 2, __builtins__ seems to |
@@ -671,12 +676,14 @@ def _runscript(self, script_str): |
671 | 676 | # memory bombs such as: |
672 | 677 | # x = 2 |
673 | 678 | # while True: x = x*x |
674 | | - resource.setrlimit(resource.RLIMIT_AS, (200000000, 200000000)) |
675 | | - resource.setrlimit(resource.RLIMIT_CPU, (5, 5)) |
| 679 | + if resource_module_loaded: |
| 680 | + resource.setrlimit(resource.RLIMIT_AS, (200000000, 200000000)) |
| 681 | + resource.setrlimit(resource.RLIMIT_CPU, (5, 5)) |
| 682 | + |
| 683 | + # protect against unauthorized filesystem accesses ... |
| 684 | + resource.setrlimit(resource.RLIMIT_NOFILE, (0, 0)) # no opened files allowed |
| 685 | + resource.setrlimit(resource.RLIMIT_FSIZE, (0, 0)) # (redundancy for paranoia) |
676 | 686 |
|
677 | | - # protect against unauthorized filesystem accesses ... |
678 | | - resource.setrlimit(resource.RLIMIT_NOFILE, (0, 0)) # no opened files allowed |
679 | | - resource.setrlimit(resource.RLIMIT_FSIZE, (0, 0)) # (redundancy for paranoia) |
680 | 687 | self.run(script_str, user_globals, user_globals) |
681 | 688 | # sys.exit ... |
682 | 689 | except SystemExit: |
|
0 commit comments