mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
bpo-37363: Add audit events on startup for the run commands (GH-14524)
This commit is contained in:
parent
0f4e813282
commit
e226e83d36
7 changed files with 190 additions and 13 deletions
|
@ -247,6 +247,10 @@ pymain_run_command(wchar_t *command, PyCompilerFlags *cf)
|
|||
goto error;
|
||||
}
|
||||
|
||||
if (PySys_Audit("cpython.run_command", "O", unicode) < 0) {
|
||||
return pymain_exit_err_print();
|
||||
}
|
||||
|
||||
bytes = PyUnicode_AsUTF8String(unicode);
|
||||
Py_DECREF(unicode);
|
||||
if (bytes == NULL) {
|
||||
|
@ -267,6 +271,9 @@ static int
|
|||
pymain_run_module(const wchar_t *modname, int set_argv0)
|
||||
{
|
||||
PyObject *module, *runpy, *runmodule, *runargs, *result;
|
||||
if (PySys_Audit("cpython.run_module", "u", modname) < 0) {
|
||||
return pymain_exit_err_print();
|
||||
}
|
||||
runpy = PyImport_ImportModule("runpy");
|
||||
if (runpy == NULL) {
|
||||
fprintf(stderr, "Could not import runpy module\n");
|
||||
|
@ -311,6 +318,9 @@ static int
|
|||
pymain_run_file(PyConfig *config, PyCompilerFlags *cf)
|
||||
{
|
||||
const wchar_t *filename = config->run_filename;
|
||||
if (PySys_Audit("cpython.run_file", "u", filename) < 0) {
|
||||
return pymain_exit_err_print();
|
||||
}
|
||||
FILE *fp = _Py_wfopen(filename, L"rb");
|
||||
if (fp == NULL) {
|
||||
char *cfilename_buffer;
|
||||
|
@ -383,6 +393,9 @@ pymain_run_startup(PyConfig *config, PyCompilerFlags *cf, int *exitcode)
|
|||
if (startup == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (PySys_Audit("cpython.run_startup", "s", startup) < 0) {
|
||||
return pymain_err_print(exitcode);
|
||||
}
|
||||
|
||||
FILE *fp = _Py_fopen(startup, "r");
|
||||
if (fp == NULL) {
|
||||
|
@ -420,6 +433,10 @@ pymain_run_interactive_hook(int *exitcode)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (PySys_Audit("cpython.run_interactivehook", "O", hook) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
result = _PyObject_CallNoArg(hook);
|
||||
Py_DECREF(hook);
|
||||
if (result == NULL) {
|
||||
|
@ -457,6 +474,10 @@ pymain_run_stdin(PyConfig *config, PyCompilerFlags *cf)
|
|||
return pymain_exit_err_print();
|
||||
}
|
||||
|
||||
if (PySys_Audit("cpython.run_stdin", NULL) < 0) {
|
||||
return pymain_exit_err_print();
|
||||
}
|
||||
|
||||
int run = PyRun_AnyFileExFlags(stdin, "<stdin>", 0, cf);
|
||||
return (run != 0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue