Commit 34c581a3 by Victor M. Alvarez

Fix segmentation fault when the value of some external variable can't be converted to string.

See: https://github.com/VirusTotal/yara/issues/990
parent 17ebaeb7
......@@ -813,6 +813,10 @@ class TestYara(unittest.TestCase):
r = yara.compile(source='rule test { condition: ext_str matches /ssi$/ }', externals={'ext_str': 'mississippi'})
self.assertFalse(r.match(data='dummy'))
self.assertRaises(UnicodeEncodeError, yara.compile,
source="rule test { condition: true}",
externals={'foo': u'\u6765\u6613\u7f51\u7edc\u79d1' })
def testCallbackAll(self):
global rule_data
rule_data = []
......
......@@ -1002,10 +1002,13 @@ int process_compile_externals(
}
else if (PY_STRING_CHECK(value))
{
char* str = PY_STRING_TO_C(value);
if (str == NULL)
return ERROR_INVALID_ARGUMENT;
result = yr_compiler_define_string_variable(
compiler,
identifier,
PY_STRING_TO_C(value));
compiler, identifier, str);
}
else
{
......@@ -1069,10 +1072,13 @@ int process_match_externals(
}
else if (PY_STRING_CHECK(value))
{
char* str = PY_STRING_TO_C(value);
if (str == NULL)
return ERROR_INVALID_ARGUMENT;
result = yr_rules_define_string_variable(
rules,
identifier,
PY_STRING_TO_C(value));
rules, identifier, str);
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment