summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-04-03 15:39:40 (GMT)
committerGitHub <noreply@github.com>2024-04-03 15:39:40 (GMT)
commit345194de8cb3ceaa40d19353d30ba6e23b6e6edb (patch)
tree916f0777eb98cc840c15296e9a577099eb3b9f50 /Modules
parent03f7aaf953f00bf2953c21a057d8e6e88db659c8 (diff)
downloadcpython-345194de8cb3ceaa40d19353d30ba6e23b6e6edb.zip
cpython-345194de8cb3ceaa40d19353d30ba6e23b6e6edb.tar.gz
cpython-345194de8cb3ceaa40d19353d30ba6e23b6e6edb.tar.bz2
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>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index a4b635e..fcac3db 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4106,6 +4106,20 @@ posix_getcwd(int use_bytes)
else {
obj = PyUnicode_DecodeFSDefault(buf);
}
+#ifdef __linux__
+ if (buf[0] != '/') {
+ /*
+ * 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 newer glibc behaviour.
+ */
+ errno = ENOENT;
+ path_object_error(obj);
+ PyMem_RawFree(buf);
+ return NULL;
+ }
+#endif
+ assert(buf[0] == '/');
PyMem_RawFree(buf);
return obj;