Skip to content

Commit b6f1c96

Browse files
committed
Avoid in-place Python code execution
Address https://github.com/quantumlib/Cirq/security/code-scanning/645
1 parent 9550c0d commit b6f1c96

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

dev_tools/modules_test_data/mod1/setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# pylint: disable=wrong-or-nonexistent-copyright-notice
2+
3+
import runpy
4+
15
from setuptools import find_packages, setup
26

3-
# This reads the __version__ variable from cirq/_version.py
4-
__version__ = ''
5-
exec(open('pack1/_version.py').read())
7+
__version__ = runpy.run_path('pack1/_version.py')['__version__']
68

79
name = 'module1'
810

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from setuptools import setup
1+
# pylint: disable=wrong-or-nonexistent-copyright-notice
22

3-
name = 'module2'
3+
import runpy
44

5-
__version__ = ''
5+
from setuptools import setup
66

7+
name = 'module2'
78

8-
exec(open('pack2/_version.py').read())
9+
__version__ = runpy.run_path('pack2/_version.py')['__version__']
910

1011
setup(name=name, version=__version__, packages=['pack2'])
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
# pylint: disable=wrong-or-nonexistent-copyright-notice
2+
3+
import runpy
4+
15
from setuptools import setup
26

37
name = 'parent-module'
48

5-
__version__ = ''
6-
7-
exec(open('mod1/pack1/_version.py').read())
9+
__version__ = runpy.run_path('mod1/pack1/_version.py')['__version__']
810

911
setup(name=name, version=__version__, requirements=[])

0 commit comments

Comments
 (0)