Skip to content

Commit f86414a

Browse files
committed
gh-149473: Emit audit event on calling os.environ.clear()
1 parent b546cc1 commit f86414a

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

Doc/library/os.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ process and user.
219219
:data:`os.environ`, and when one of the :meth:`~dict.pop` or
220220
:meth:`~dict.clear` methods is called.
221221

222+
.. audit-event:: os.unsetenv key os.unsetenv
223+
224+
.. audit-event:: os._clearenv "" os._clearenv
225+
222226
.. seealso::
223227

224228
The :func:`os.reload_environ` function.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Calling ``os.environ.clear()`` now emits ``os._clearenv`` auditing event.
2+
Patch by Victor Stinner.

Modules/posixmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13663,6 +13663,10 @@ static PyObject *
1366313663
os__clearenv_impl(PyObject *module)
1366413664
/*[clinic end generated code: output=2d6705d62c014b51 input=47d2fa7f323c43ca]*/
1366513665
{
13666+
if (PySys_Audit("os._clearenv", NULL) < 0) {
13667+
return NULL;
13668+
}
13669+
1366613670
errno = 0;
1366713671
int err = clearenv();
1366813672
if (err) {

0 commit comments

Comments
 (0)