-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Possible segfault if globals dict is NULL in run_eval_code_obj #116180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It would be nice if you could come up with a reproducer, either in Python, the C API, or both. |
Yes, this patch has a cosmetic effect, should i mention it somehow in other issues, that will follow? Testcase is difficult for me to offer right now, i'll try to figure it out, but with no guarantees that i succeed. |
This looks pretty trivially reproducible - just pass 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. |
Yes, finally i've figured it out and left comment in PR thread with example and outcome. |
There are two ways to fix this issue:
You perhaps need to try both ways to determine what way is more correct. |
I thought that it's better to check NULL in one place, and there it's hard to figure out where NULL came from. |
The fix is to bring back the null check that Mark deleted in his refactoring. It used to be in
(See lines 4386-4390 of ceval.c in d6c33fb - sorry Github won't let me link directly for some reason) |
It seems you should check discussion in PR. Unfortunately it forked |
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. |
I've logged-in to check PR status and sync sources. And found out, that our changes were merged through #117968. It ruined somehow my branch with changes to run_eval_code_obj(), but finally I managed to restore changes. |
It used to crash when passing NULL or non-dict as globals. Now it sets a SystemError.
…H-116637) It used to crash when passing NULL or non-dict as globals. Now it sets a SystemError.
Bug report
Bug description:
Possible interpreter crash condition was found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.
run_eval_code_obj is called with globals dict passed as pointer without NULL check and that may cause segmentation fault in
PyEval_EvalCode->_PyEval_BuiltinsFromGlobals->PyDict_GetItemWithError line 2272 in PyDict_Check(op).
Some functions, for example, _run_script or builtin_eval_impl have globals NULL check.
Other, like PyRun_SimpleStringFlags,
PyRun_InteractiveOneObjectEx or PyRun_FileExFlags just use the pointer from the PyObject struct.
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).
CPython versions tested on:
3.10
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: