summaryrefslogtreecommitdiff
path: root/numpy/f2py
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2014-02-05 23:01:47 +0100
committerJulian Taylor <jtaylor.debian@googlemail.com>2014-02-06 00:54:24 +0100
commit0bb46c1448b0d3f5453d5182a17ea7ac5854ee15 (patch)
tree761f4c2441ca1695b797048bda8d2c83a31e063c /numpy/f2py
parentb7850701a31127cad8c7399cea6be9cd5f71bec5 (diff)
downloadnumpy-0bb46c1448b0d3f5453d5182a17ea7ac5854ee15.tar.gz
ENH: remove insecure mktemp use
mktemp only returns a filename, a malicous user could replace it before it gets used.
Diffstat (limited to 'numpy/f2py')
-rw-r--r--numpy/f2py/__init__.py26
-rwxr-xr-xnumpy/f2py/f2py2e.py4
2 files changed, 15 insertions, 15 deletions
diff --git a/numpy/f2py/__init__.py b/numpy/f2py/__init__.py
index ccdbd4e0b..fcfd1853e 100644
--- a/numpy/f2py/__init__.py
+++ b/numpy/f2py/__init__.py
@@ -28,20 +28,20 @@ def compile(source,
from numpy.distutils.exec_command import exec_command
import tempfile
if source_fn is None:
- fname = os.path.join(tempfile.mktemp()+'.f')
+ f = tempfile.NamedTemporaryFile(suffix='.f')
else:
- fname = source_fn
-
- f = open(fname, 'w')
- f.write(source)
- f.close()
-
- args = ' -c -m %s %s %s'%(modulename, fname, extra_args)
- c = '%s -c "import numpy.f2py as f2py2e;f2py2e.main()" %s' %(sys.executable, args)
- s, o = exec_command(c)
- if source_fn is None:
- try: os.remove(fname)
- except OSError: pass
+ f = open(source_fn, 'w')
+
+ try:
+ f.write(source)
+ f.flush()
+
+ args = ' -c -m %s %s %s'%(modulename, f.name, extra_args)
+ c = '%s -c "import numpy.f2py as f2py2e;f2py2e.main()" %s' % \
+ (sys.executable, args)
+ s, o = exec_command(c)
+ finally:
+ f.close()
return s
from numpy.testing import Tester
diff --git a/numpy/f2py/f2py2e.py b/numpy/f2py/f2py2e.py
index ff9d19e9d..25407d421 100755
--- a/numpy/f2py/f2py2e.py
+++ b/numpy/f2py/f2py2e.py
@@ -91,7 +91,7 @@ Options:
--lower is assumed with -h key, and --no-lower without -h key.
--build-dir <dirname> All f2py generated files are created in <dirname>.
- Default is tempfile.mktemp().
+ Default is tempfile.mkdtemp().
--overwrite-signature Overwrite existing signature file.
@@ -424,7 +424,7 @@ def run_compile():
del sys.argv[i]
else:
remove_build_dir = 1
- build_dir = os.path.join(tempfile.mktemp())
+ build_dir = tempfile.mkdtemp()
_reg1 = re.compile(r'[-][-]link[-]')
sysinfo_flags = [_m for _m in sys.argv[1:] if _reg1.match(_m)]