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
NULL + 1 in _PyFunction_FastCallDict(), PyEval_EvalCodeEx() #74825
In _PyFunction_FastCallDict() if nk == 0, k is set to NULL. After that k + 1 is passed to _PyEval_EvalCodeWithName(). NULL + 1 is an undefined behavior.
Even if _PyEval_EvalCodeWithName() ignores that value, this still is an undefined behavior. For example the compiler can decide that since NULL+1 is not valid, then k never is NULL, and ignore the branch that sets k to NULL. It can also not generate the code in _PyEval_EvalCodeWithName() for handling the case kwcount == 0.
ZackerySpytz commented on Jul 31, 2017
ZackerySpytzmannequin
Mannequin
More actions
As mentioned in PR 2919, this is an issue in PyEval_EvalCodeEx() as well.
New changeset c6ea897 by Serhiy Storchaka (Zackery Spytz) in branch 'master': bpo-30640: Fix undefined behavior in _PyFunction_FastCallDict() and PyEval_EvalCodeEx() (bpo-2919) c6ea897
New changeset f032e92 by Victor Stinner (Zackery Spytz) in branch '3.6':
[3.6] bpo-30640: Fix undefined behavior in _PyFunction_FastCallDict() and PyEval_EvalCodeEx() (GH-2919) (bpo-2964) f032e92
Activity
serhiy-storchaka commentedon Jun 12, 2017
In _PyFunction_FastCallDict() if nk == 0, k is set to NULL. After that k + 1 is passed to _PyEval_EvalCodeWithName(). NULL + 1 is an undefined behavior.
[-]NULL + 1[/-][+]NULL + 1 in _PyFunction_FastCallDict()[/+]vstinner commentedon Jun 12, 2017
Can you please show me the line doing NULL+1? I don't see it. Or do you mean the "k + 1" with k=NULL?
_PyEval_EvalCodeWithName() ignores kwnames and kwargs when kwcount is zero. So I don't think that the value of NULL+1 matters here :-)
serhiy-storchaka commentedon Jun 12, 2017
Yes, I mean the "k + 1" with k=NULL.
Even if _PyEval_EvalCodeWithName() ignores that value, this still is an undefined behavior. For example the compiler can decide that since NULL+1 is not valid, then k never is NULL, and ignore the branch that sets k to NULL. It can also not generate the code in _PyEval_EvalCodeWithName() for handling the case kwcount == 0.
ZackerySpytz commentedon Jul 31, 2017
As mentioned in PR 2919, this is an issue in PyEval_EvalCodeEx() as well.
[-]NULL + 1 in _PyFunction_FastCallDict()[/-][+]NULL + 1 in _PyFunction_FastCallDict(), PyEval_EvalCodeEx()[/+]serhiy-storchaka commentedon Jul 31, 2017
New changeset c6ea897 by Serhiy Storchaka (Zackery Spytz) in branch 'master':
bpo-30640: Fix undefined behavior in _PyFunction_FastCallDict() and PyEval_EvalCodeEx() (bpo-2919)
c6ea897
vstinner commentedon Sep 8, 2017
New changeset f032e92 by Victor Stinner (Zackery Spytz) in branch '3.6':
[3.6] bpo-30640: Fix undefined behavior in _PyFunction_FastCallDict() and PyEval_EvalCodeEx() (GH-2919) (bpo-2964)
f032e92
vstinner commentedon Sep 8, 2017
It's now fixed in Python 3.6 and master (3.7).
FYI this issue was also detected by Coverity as CID 1415964.