Skip to content

Commit 48174fa

Browse files
authored
gh-96005: Handle WASI ENOTCAPABLE in getpath (GH-96006)
- On WASI `ENOTCAPABLE` is now mapped to `PermissionError`. - The `errno` modules exposes the new error number. - `getpath.py` now ignores `PermissionError` when it cannot open landmark files `pybuilddir.txt` and `pyenv.cfg`.
1 parent f215d7c commit 48174fa

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

Doc/library/errno.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,3 +657,12 @@ defined by the module. The specific list of defined symbols is available as
657657
Interface output queue is full
658658

659659
.. versionadded:: 3.11
660+
661+
.. data:: ENOTCAPABLE
662+
663+
Capabilities insufficient. This error is mapped to the exception
664+
:exc:`PermissionError`.
665+
666+
.. availability:: WASI
667+
668+
.. versionadded:: 3.11.1

Doc/library/exceptions.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,12 @@ depending on the system error code.
746746

747747
Raised when trying to run an operation without the adequate access
748748
rights - for example filesystem permissions.
749-
Corresponds to :c:data:`errno` :py:data:`~errno.EACCES` and :py:data:`~errno.EPERM`.
749+
Corresponds to :c:data:`errno` :py:data:`~errno.EACCES`,
750+
:py:data:`~errno.EPERM`, and :py:data:`~errno.ENOTCAPABLE`.
751+
752+
.. versionchanged:: 3.11.1
753+
WASI's :py:data:`~errno.ENOTCAPABLE` is now mapped to
754+
:exc:`PermissionError`.
750755

751756
.. exception:: ProcessLookupError
752757

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
On WASI :data:`~errno.ENOTCAPABLE` is now mapped to :exc:`PermissionError`.
2+
The :mod:`errno` modules exposes the new error number. ``getpath.py`` now
3+
ignores :exc:`PermissionError` when it cannot open landmark files
4+
``pybuilddir.txt`` and ``pyenv.cfg``.

Modules/errnomodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,10 @@ errno_exec(PyObject *module)
927927
#ifdef EQFULL
928928
add_errcode("EQFULL", EQFULL, "Interface output queue is full");
929929
#endif
930+
#ifdef ENOTCAPABLE
931+
// WASI extension
932+
add_errcode("ENOTCAPABLE", ENOTCAPABLE, "Capabilities insufficient");
933+
#endif
930934

931935
Py_DECREF(error_dict);
932936
return 0;

Modules/getpath.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,11 @@ def search_up(prefix, *landmarks, test=isfile):
351351
try:
352352
# Read pyvenv.cfg from one level above executable
353353
pyvenvcfg = readlines(joinpath(venv_prefix, VENV_LANDMARK))
354-
except FileNotFoundError:
354+
except (FileNotFoundError, PermissionError):
355355
# Try the same directory as executable
356356
pyvenvcfg = readlines(joinpath(venv_prefix2, VENV_LANDMARK))
357357
venv_prefix = venv_prefix2
358-
except FileNotFoundError:
358+
except (FileNotFoundError, PermissionError):
359359
venv_prefix = None
360360
pyvenvcfg = []
361361

@@ -475,7 +475,7 @@ def search_up(prefix, *landmarks, test=isfile):
475475
# File exists but is empty
476476
platstdlib_dir = real_executable_dir
477477
build_prefix = joinpath(real_executable_dir, VPATH)
478-
except FileNotFoundError:
478+
except (FileNotFoundError, PermissionError):
479479
if isfile(joinpath(real_executable_dir, BUILD_LANDMARK)):
480480
build_prefix = joinpath(real_executable_dir, VPATH)
481481
if os_name == 'nt':

Objects/exceptions.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3635,6 +3635,11 @@ _PyExc_InitState(PyInterpreterState *interp)
36353635
ADD_ERRNO(InterruptedError, EINTR);
36363636
ADD_ERRNO(PermissionError, EACCES);
36373637
ADD_ERRNO(PermissionError, EPERM);
3638+
#ifdef ENOTCAPABLE
3639+
// Extension for WASI capability-based security. Process lacks
3640+
// capability to access a resource.
3641+
ADD_ERRNO(PermissionError, ENOTCAPABLE);
3642+
#endif
36383643
ADD_ERRNO(ProcessLookupError, ESRCH);
36393644
ADD_ERRNO(TimeoutError, ETIMEDOUT);
36403645

0 commit comments

Comments
 (0)