diff options
author | Stefan Krah <stefan@bytereef.org> | 2010-07-13 19:17:08 (GMT) |
---|---|---|
committer | Stefan Krah <stefan@bytereef.org> | 2010-07-13 19:17:08 (GMT) |
commit | 182ae64235c510c7b40f7b26a1490d3f2163d00d (patch) | |
tree | 3550cad403a9f785791d3055e6c9bfb309057c13 /Modules | |
parent | 320477e4db8fb2484d920db2c888eab46eef7692 (diff) | |
download | cpython-182ae64235c510c7b40f7b26a1490d3f2163d00d.zip cpython-182ae64235c510c7b40f7b26a1490d3f2163d00d.tar.gz cpython-182ae64235c510c7b40f7b26a1490d3f2163d00d.tar.bz2 |
Issue #9185: On Solaris and OpenBSD, posix_getcwd() could loop indefinitely
if the path length exceeded PATH_MAX.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/posixmodule.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 8a23e65..17af508 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1957,6 +1957,28 @@ 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 +#if defined(PYOS_OS2) && defined(PYCC_GCC) + res = _getcwd2(buf, sizeof buf); +#else + res = getcwd(buf, sizeof buf); +#endif + Py_END_ALLOW_THREADS + + if (res == NULL) + return posix_error(); + + return PyString_FromString(buf); +} +#else static PyObject * posix_getcwd(PyObject *self, PyObject *noargs) { @@ -1993,6 +2015,7 @@ posix_getcwd(PyObject *self, PyObject *noargs) return dynamic_return; } +#endif /* getcwd() NULL/ERANGE workaround. */ #ifdef Py_USING_UNICODE PyDoc_STRVAR(posix_getcwdu__doc__, |