You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible segfault if globals dict is NULL in run_eval_code_obj #116180
For my understanding the globals dict should always be present and it is an error condition, when it is NULL.
And no one encounted with such faults, so the patch will have cosmetic effect (is on the way).
This looks pretty trivially reproducible - just pass globals=NULL to PyRun_FileExFlags or any of the functions that wrap it up. They all just pass through without checking.
Prior to d6c33fb there was a NULL check deeper in that raised an error. The place where it was no longer exists, but we should probably add the check closer to where it's being used.
Make the code working with globals = NULL. The part of the code already supports this case, you should add workarounds for other parts.
If this case should not be supported, make the code raising an exception with clear and precise error message. Why globals is NULL? If it is passed by the user of the C API, the arguments should be validated and SystemError should be passed. If it is the result of other operations, it should be checked after performing these operations, and the error message should be more specific.
You perhaps need to try both ways to determine what way is more correct.
After working on the proposed PR and tests, I think that it is not a bug. The lack of the validation in the C API is not a bug. You are supposed to pass valid arguments, and if it fails for invalid arguments, it is your fault.
Of course, it would be nice to handle the user error and raise a SystemError, but this is a new feature, not a bug fix. This API is high-level, so adding few new checks will not add much overhead.
Activity
erlend-aasland commentedon Mar 12, 2024
It would be nice if you could come up with a reproducer, either in Python, the C API, or both.
zooba commentedon Apr 2, 2024
This looks pretty trivially reproducible - just pass
globals=NULLtoPyRun_FileExFlagsor any of the functions that wrap it up. They all just pass through without checking.Prior to d6c33fb there was a NULL check deeper in that raised an error. The place where it was no longer exists, but we should probably add the check closer to where it's being used.
serhiy-storchaka commentedon Apr 3, 2024
There are two ways to fix this issue:
globals = NULL. The part of the code already supports this case, you should add workarounds for other parts.globalsis NULL? If it is passed by the user of the C API, the arguments should be validated and SystemError should be passed. If it is the result of other operations, it should be checked after performing these operations, and the error message should be more specific.You perhaps need to try both ways to determine what way is more correct.
zooba commentedon Apr 3, 2024
The fix is to bring back the null check that Mark deleted in his refactoring. It used to be in
_PyEval_EvalCode:(See lines 4386-4390 of ceval.c in d6c33fb - sorry Github won't let me link directly for some reason)
serhiy-storchaka commentedon Apr 17, 2024
After working on the proposed PR and tests, I think that it is not a bug. The lack of the validation in the C API is not a bug. You are supposed to pass valid arguments, and if it fails for invalid arguments, it is your fault.
Of course, it would be nice to handle the user error and raise a SystemError, but this is a new feature, not a bug fix. This API is high-level, so adding few new checks will not add much overhead.
gh-116180: Check the globals argument in PyRun_* C API (GH-116637)
pythongh-116180: Check the globals argument in PyRun_* C API (pythonG…