]> granicus.if.org Git - python/commitdiff
Merged revisions 82853-82854 via svnmerge from
authorStefan Krah <stefan@bytereef.org>
Mon, 19 Jul 2010 15:43:23 +0000 (15:43 +0000)
committerStefan Krah <stefan@bytereef.org>
Mon, 19 Jul 2010 15:43:23 +0000 (15:43 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/release27-maint

........
  r82853 | stefan.krah | 2010-07-13 21:17:08 +0200 (Tue, 13 Jul 2010) | 4 lines

  Issue #9185: On Solaris and OpenBSD, posix_getcwd() could loop indefinitely
  if the path length exceeded PATH_MAX.
........
  r82854 | stefan.krah | 2010-07-13 21:40:00 +0200 (Tue, 13 Jul 2010) | 3 lines

  Remove PYOS_OS2 special cases from the Solaris/OpenBSD section.
........

Lib/test/test_posix.py
Modules/posixmodule.c

index 88d298bce6536bf36bd44937b7ae3b2258d3e8ea..ac3dbb832d7315ff551e9e7bfaf52989aede6955 100644 (file)
@@ -11,6 +11,7 @@ import time
 import os
 import pwd
 import shutil
+import sys
 import unittest
 import warnings
 warnings.filterwarnings('ignore', '.* potential security risk .*',
@@ -287,8 +288,13 @@ class PosixTester(unittest.TestCase):
                     os.chdir(dirname)
                     try:
                         os.getcwd()
-                        if current_path_length < 1027:
+                        if current_path_length < 4099:
                             _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1)
+                    except OSError as e:
+                        expected_errno = errno.ENAMETOOLONG
+                        if 'sunos' in sys.platform or 'openbsd' in sys.platform:
+                            expected_errno = errno.ERANGE # Issue 9185
+                        self.assertEqual(e.errno, expected_errno)
                     finally:
                         os.chdir('..')
                         os.rmdir(dirname)
index 46ee716494761f1bef76cf3172ca6eaa1d6ae34e..a7f738256774e0b7e76975ec96d6640ff3cea3bd 100644 (file)
@@ -1970,6 +1970,24 @@ PyDoc_STRVAR(posix_getcwd__doc__,
 "getcwd() -> path\n\n\
 Return a string representing the current working directory.");
 
+#if (defined(__sun) && defined(__SVR4)) || defined(__OpenBSD__)
+/* Issue 9185: getcwd() returns NULL/ERANGE indefinitely. */
+static PyObject *
+posix_getcwd(PyObject *self, PyObject *noargs)
+{
+    char buf[PATH_MAX+2];
+    char *res;
+
+    Py_BEGIN_ALLOW_THREADS
+    res = getcwd(buf, sizeof buf);
+    Py_END_ALLOW_THREADS
+
+    if (res == NULL)
+        return posix_error();
+
+    return PyString_FromString(buf);
+}
+#else
 static PyObject *
 posix_getcwd(PyObject *self, PyObject *noargs)
 {
@@ -2006,6 +2024,7 @@ posix_getcwd(PyObject *self, PyObject *noargs)
 
     return dynamic_return;
 }
+#endif /* getcwd() NULL/ERANGE workaround. */
 
 #ifdef Py_USING_UNICODE
 PyDoc_STRVAR(posix_getcwdu__doc__,