[Forensics-changes] [yara] 170/415: Fix bug causing segmentation fault when _yr_compiler_compile_rules fails
Hilko Bengen
bengen at moszumanska.debian.org
Thu Apr 3 05:43:01 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch debian
in repository yara.
commit 71999763598a75e23cf648431f7be895613e22a4
Author: Victor M. Alvarez <plusvic at gmail.com>
Date: Fri May 31 09:29:29 2013 +0000
Fix bug causing segmentation fault when _yr_compiler_compile_rules fails
---
libyara/compiler.c | 9 +++++----
yara-python/yara-python.c | 36 +++++++++++++++++++++++-------------
2 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/libyara/compiler.c b/libyara/compiler.c
index 88d3996..7389c81 100644
--- a/libyara/compiler.c
+++ b/libyara/compiler.c
@@ -451,11 +451,12 @@ int yr_compiler_get_rules(
return ERROR_INSUFICIENT_MEMORY;
if (compiler->compiled_rules_arena == NULL)
- _yr_compiler_compile_rules(compiler);
+ result = _yr_compiler_compile_rules(compiler);
- result = yr_arena_duplicate(
- compiler->compiled_rules_arena,
- &yara_rules->arena);
+ if (result == ERROR_SUCCESS)
+ result = yr_arena_duplicate(
+ compiler->compiled_rules_arena,
+ &yara_rules->arena);
if (result == ERROR_SUCCESS)
{
diff --git a/yara-python/yara-python.c b/yara-python/yara-python.c
index a2acf21..9853aee 100644
--- a/yara-python/yara-python.c
+++ b/yara-python/yara-python.c
@@ -941,7 +941,7 @@ static PyObject * yara_compile(
FILE* fh;
int fd;
- int compile_result = 0;
+ int error = 0;
int error_line;
char error_message[256];
@@ -1023,7 +1023,7 @@ static PyObject * yara_compile(
{
Py_BEGIN_ALLOW_THREADS
yr_compiler_push_file_name(compiler, filepath);
- compile_result = yr_compiler_add_file(compiler, fh, NULL);
+ error = yr_compiler_add_file(compiler, fh, NULL);
fclose(fh);
Py_END_ALLOW_THREADS
}
@@ -1035,7 +1035,7 @@ static PyObject * yara_compile(
else if (source != NULL)
{
Py_BEGIN_ALLOW_THREADS
- compile_result = yr_compiler_add_string(compiler, source, NULL);
+ error = yr_compiler_add_string(compiler, source, NULL);
Py_END_ALLOW_THREADS
}
else if (file != NULL)
@@ -1044,7 +1044,7 @@ static PyObject * yara_compile(
Py_BEGIN_ALLOW_THREADS
fh = fdopen(fd, "r");
- compile_result = yr_compiler_add_file(compiler, fh, NULL);
+ error = yr_compiler_add_file(compiler, fh, NULL);
fclose(fh);
Py_END_ALLOW_THREADS
}
@@ -1060,10 +1060,10 @@ static PyObject * yara_compile(
if (source != NULL && ns != NULL)
{
Py_BEGIN_ALLOW_THREADS
- compile_result = yr_compiler_add_string(compiler, source, ns);
+ error = yr_compiler_add_string(compiler, source, ns);
Py_END_ALLOW_THREADS
- if (compile_result > 0)
+ if (error > 0)
break;
}
else
@@ -1099,11 +1099,11 @@ static PyObject * yara_compile(
{
Py_BEGIN_ALLOW_THREADS
yr_compiler_push_file_name(compiler, filepath);
- compile_result = yr_compiler_add_file(compiler, fh, ns);
+ error = yr_compiler_add_file(compiler, fh, ns);
fclose(fh);
Py_END_ALLOW_THREADS
- if (compile_result > 0)
+ if (error > 0)
break;
}
else
@@ -1137,7 +1137,7 @@ static PyObject * yara_compile(
if (PyErr_Occurred() == NULL)
{
- if (compile_result > 0)
+ if (error > 0)
{
error_line = compiler->last_error_line;
@@ -1159,13 +1159,23 @@ static PyObject * yara_compile(
if (rules != NULL)
{
Py_BEGIN_ALLOW_THREADS
- yr_compiler_get_rules(compiler, &yara_rules);
+ error = yr_compiler_get_rules(compiler, &yara_rules);
Py_END_ALLOW_THREADS
- rules->rules = yara_rules;
+ if (error == ERROR_SUCCESS)
+ {
+ rules->rules = yara_rules;
+ result = (PyObject*) rules;
+ }
+ else
+ {
+ result = handle_error(error, NULL);
+ }
+ }
+ else
+ {
+ result = handle_error(ERROR_INSUFICIENT_MEMORY, NULL);
}
-
- result = (PyObject*) rules;
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/forensics/yara.git
More information about the forensics-changes
mailing list