[issue9185] os.getcwd causes infinite loop on solaris
report at bugs.python.org
Wed Jul 7 10:56:37 CEST 2010
New submission from Zsolt Cserna <zsolt.cserna at morganstanley.com>:
os.getcwd() causes infinite loop on solaris10 when the length of the current directory is greater than 1024 (them limit of the maximum absolute path).
os.getcwd is implemented by a while loop in python, see the function posix_getcwd in posixmodule.c. That while loop loops forever because on solaris it sets errno to ERANGE and res to NULL - even if there will be no positive results from getcwd due to the extra long path.
This infinite while cycle also causes eating up the memory.
I think the solution would be implementing a hard limit for this while loop. It could be either fixed (16k for example), or dymanic: comparing the MAXPATHLEN macro to the size of the allocated buffer and if the size of the buffer is greater than MAXLPATHLEN then raise an OSError exception with the current errno.
That bug was triggered by test_posix unittest.
components: Library (Lib)
title: os.getcwd causes infinite loop on solaris
versions: Python 2.7
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list