Skip to content

Commit

Permalink
fix: check key type in externals dict
Browse files Browse the repository at this point in the history
The type of the key for the externals dict in both the compile and the
match function was not checked. Providing a dict with non string keys
leads to a segfault.
  • Loading branch information
vthib committed Mar 9, 2025
1 parent 03c802e commit b33104e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions yara-python.c
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,13 @@ int process_compile_externals(

while (PyDict_Next(externals, &pos, &key, &value))
{
if (!PY_STRING_CHECK(key)) {
PyErr_Format(
PyExc_TypeError,
"keys of externals dict must be strings");

return ERROR_INVALID_ARGUMENT;
}
identifier = PY_STRING_TO_C(key);

if (PyBool_Check(value))
Expand Down Expand Up @@ -1592,6 +1599,13 @@ int process_match_externals(

while (PyDict_Next(externals, &pos, &key, &value))
{
if (!PY_STRING_CHECK(key)) {
PyErr_Format(
PyExc_TypeError,
"keys of externals dict must be strings");

return ERROR_INVALID_ARGUMENT;
}
identifier = PY_STRING_TO_C(key);

if (PyBool_Check(value))
Expand Down

0 comments on commit b33104e

Please sign in to comment.