Skip to content

Commit 3c616fe

Browse files
authored
fix: check key type in externals dict (#270)
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.
1 parent df256bc commit 3c616fe

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

yara-python.c

+14
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,13 @@ int process_compile_externals(
15221522

15231523
while (PyDict_Next(externals, &pos, &key, &value))
15241524
{
1525+
if (!PY_STRING_CHECK(key)) {
1526+
PyErr_Format(
1527+
PyExc_TypeError,
1528+
"keys of externals dict must be strings");
1529+
1530+
return ERROR_INVALID_ARGUMENT;
1531+
}
15251532
identifier = PY_STRING_TO_C(key);
15261533

15271534
if (PyBool_Check(value))
@@ -1592,6 +1599,13 @@ int process_match_externals(
15921599

15931600
while (PyDict_Next(externals, &pos, &key, &value))
15941601
{
1602+
if (!PY_STRING_CHECK(key)) {
1603+
PyErr_Format(
1604+
PyExc_TypeError,
1605+
"keys of externals dict must be strings");
1606+
1607+
return ERROR_INVALID_ARGUMENT;
1608+
}
15951609
identifier = PY_STRING_TO_C(key);
15961610

15971611
if (PyBool_Check(value))

0 commit comments

Comments
 (0)