-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Py_DECREF on a non-owned object in _sre #71961
Comments
Thomas E Hybel reports: This vulnerability exists in the function _sre_SRE_Match_groupdict_impl which The problem is that the code calls Py_DECREF(key); without having done a Here's the relevant code: static PyObject *
_sre_SRE_Match_groupdict_impl(MatchObject *self, PyObject *default_value)
{
...
for (index = 0; index < PyList_GET_SIZE(keys); index++) {
...
PyObject* key;
...
key = PyList_GET_ITEM(keys, index);
...
value = match_getslice(self, key, default_value);
if (!value) {
Py_DECREF(key);
goto failed;
}
...
}
...
} We initialize the "key" variable via PyList_GET_ITEM(keys, index) which simply If match_getslice fails, we then call Py_DECREF(key). This is simply wrong. It Here's a script which reproduces this: --- begin script --- import _sre
import time
p = _sre.compile(
"A", # pattern
0, # flags
[1], # code
1, # groups
{0xdeadbeef: 0}, # groupindex
0 # indexgroup
)
m = p.match("AAAA")
for _ in range(5):
# each call to m.groupdict decreases the refcount of 0xdeadbeef once
try:
m.groupdict()
except IndexError:
pass
--- end script Running the script crashes python on my machine: (gdb) r ./poc7.py Program received signal SIGSEGV, Segmentation fault. |
New changeset 4ca84a3e37d7 by Benjamin Peterson in branch '2.7': New changeset cbf2a05648b3 by Benjamin Peterson in branch '3.3': New changeset 2e404ac88e0e by Benjamin Peterson in branch '3.4': New changeset 424cb9482974 by Benjamin Peterson in branch '3.5': New changeset 64b0e0a29874 by Benjamin Peterson in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: