8000 GH-114847: Raise FileNotFoundError when getcwd() returns '(unreachabl… · python/cpython@345194d · GitHub
[go: up one dir, main page]

Skip to content

Commit 345194d

Browse files
barneygaleencukou
andauthored
GH-114847: Raise FileNotFoundError when getcwd() returns '(unreachable)' (#117481)
On Linux >= 2.6.36 with glibc < 2.27, `getcwd()` can return a relative pathname starting with '(unreachable)'. We detect this and fail with ENOENT, matching new glibc behaviour. Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent 03f7aaf commit 345194d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Raise :exc:`FileNotFoundError` when ``getcwd()`` returns '(unreachable)',
2+
which can happen on Linux >= 2.6.36 with glibc < 2.27.

Modules/posixmodule.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,6 +4106,20 @@ posix_getcwd(int use_bytes)
41064106
else {
41074107
obj = PyUnicode_DecodeFSDefault(buf);
41084108
}
4109+
#ifdef __linux__
4110+
if (buf[0] != '/') {
4111+
/*
4112+
* On Linux >= 2.6.36 with glibc < 2.27, getcwd() can return a
4113+
* relative pathname starting with '(unreachable)'. We detect this
4114+
* and fail with ENOENT, matching newer glibc behaviour.
4115+
*/
4116+
errno = ENOENT;
4117+
path_object_error(obj);
4118+
PyMem_RawFree(buf);
4119+
return NULL;
4120+
}
4121+
#endif
4122+
assert(buf[0] == '/');
41094123
PyMem_RawFree(buf);
41104124

41114125
return obj;

0 commit comments

Comments
 (0)
0