Skip to content

Commit

Permalink
PySys_Audit() checks arguments
Browse files Browse the repository at this point in the history
* Reject NULL event argument with ValueError.
* Reject "N" format in the format argument with ValueError.
  • Loading branch information
vstinner committed Sep 19, 2023
1 parent 579731b commit 5b2f66c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,6 @@ static int
sys_audit_tstate(PyThreadState *ts, const char *event,
const char *argFormat, va_list vargs)
{
/* N format is inappropriate, because you do not know
whether the reference is consumed by the call.
Assert rather than exception for perf reasons */
assert(!argFormat || !strchr(argFormat, 'N'));

if (!ts) {
/* Audit hooks cannot be called with a NULL thread state */
return 0;
Expand All @@ -209,6 +204,21 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
return 0;
}

if (event == NULL) {
_PyErr_SetString(ts, PyExc_ValueError,
"event argument must not be NULL");
return -1;
}

/* N format is inappropriate, because you do not know
whether the reference is consumed by the call.
Assert rather than exception for perf reasons */
if (argFormat != NULL && strchr(argFormat, 'N')) {
_PyErr_SetString(ts, PyExc_ValueError,
"N format must not be used in the format argument");
return -1;
}

PyObject *eventName = NULL;
PyObject *eventArgs = NULL;
PyObject *hooks = NULL;
Expand Down

0 comments on commit 5b2f66c

Please sign in to comment.