]> granicus.if.org Git - python/commitdiff
Fix #1521375. When running with root priviledges, 'gcc -o /dev/null'
authorThomas Heller <theller@ctypes.org>
Thu, 13 Jul 2006 17:01:14 +0000 (17:01 +0000)
committerThomas Heller <theller@ctypes.org>
Thu, 13 Jul 2006 17:01:14 +0000 (17:01 +0000)
did overwrite /dev/null.  Use a temporary file instead of /dev/null.

Lib/ctypes/util.py
Misc/NEWS

index d4e314a6a066e0adbb51fcba9fb416c3734a5cf8..2ee2968d910b7cd89f0a6448feec8c22476b234a 100644 (file)
@@ -47,10 +47,13 @@ elif os.name == "posix":
 
     def _findLib_gcc(name):
         expr = '[^\(\)\s]*lib%s\.[^\(\)\s]*' % name
+        fdout, ccout = tempfile.mkstemp()
+        os.close(fdout)
         cmd = 'if type gcc &>/dev/null; then CC=gcc; else CC=cc; fi;' \
-              '$CC -Wl,-t -o /dev/null 2>&1 -l' + name
+              '$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
         try:
             fdout, outfile =  tempfile.mkstemp()
+            os.close(fdout)
             fd = os.popen(cmd)
             trace = fd.read()
             err = fd.close()
@@ -60,6 +63,11 @@ elif os.name == "posix":
             except OSError, e:
                 if e.errno != errno.ENOENT:
                     raise
+            try:
+                os.unlink(ccout)
+            except OSError, e:
+                if e.errno != errno.ENOENT:
+                    raise
         res = re.search(expr, trace)
         if not res:
             return None
index 516e84ccf4d8a9f9b26a07927861c2fa229fff6b..c44227b8f3684b5c82fb5edce837f8ffbabb3d3d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -25,6 +25,10 @@ Library
 Extension Modules
 -----------------
 
+- Bug #1521375: The code in ctypes.util.find_library was
+  run with root priviledges, it could overwrite or delete
+  /dev/null in certain cases; this is now fixed.
+
 - Bug #1467450: On Mac OS X 10.3, RTLD_GLOBAL is now used as the
   default mode for loading shared libraries in ctypes.