[Forensics-changes] [yara] 18/368: Return error instead of aborting when regular expression is too large
Hilko Bengen
bengen at moszumanska.debian.org
Sat Jul 1 10:30:06 UTC 2017
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag v3.5.0
in repository yara.
commit b1106adfa8f891711309f5cb71333aacebcef62a
Author: Victor M. Alvarez <plusvic at gmail.com>
Date: Thu Jul 2 15:13:46 2015 +0200
Return error instead of aborting when regular expression is too large
---
libyara/compiler.c | 7 +++++++
libyara/include/yara/error.h | 1 +
libyara/re.c | 6 ++++--
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/libyara/compiler.c b/libyara/compiler.c
index 1863925..76cfbb1 100644
--- a/libyara/compiler.c
+++ b/libyara/compiler.c
@@ -877,6 +877,13 @@ YR_API char* yr_compiler_get_error_message(
buffer_size,
"division by zero");
break;
+ case ERROR_REGULAR_EXPRESSION_TOO_LARGE:
+ snprintf(
+ buffer,
+ buffer_size,
+ "regular expression is too large");
+ break;
+
}
return buffer;
diff --git a/libyara/include/yara/error.h b/libyara/include/yara/error.h
index 0ab3982..e52e2f9 100644
--- a/libyara/include/yara/error.h
+++ b/libyara/include/yara/error.h
@@ -66,6 +66,7 @@ limitations under the License.
#define ERROR_DUPLICATED_STRUCTURE_MEMBER 42
#define ERROR_EMPTY_STRING 43
#define ERROR_DIVISION_BY_ZERO 44
+#define ERROR_REGULAR_EXPRESSION_TOO_LARGE 45
#define FAIL_ON_ERROR(x) { \
diff --git a/libyara/re.c b/libyara/re.c
index 485b5c8..2bac25f 100644
--- a/libyara/re.c
+++ b/libyara/re.c
@@ -1148,7 +1148,8 @@ int yr_re_emit_code(
total_size += code_size;
- assert(total_size < RE_MAX_CODE_SIZE);
+ if (total_size > RE_MAX_CODE_SIZE)
+ return ERROR_REGULAR_EXPRESSION_TOO_LARGE;
yr_arena_reserve_memory(arena, RE_MAX_CODE_SIZE);
@@ -1173,7 +1174,8 @@ int yr_re_emit_code(
total_size += code_size;
- assert(total_size < RE_MAX_CODE_SIZE);
+ if (total_size > RE_MAX_CODE_SIZE)
+ return ERROR_REGULAR_EXPRESSION_TOO_LARGE;
return ERROR_SUCCESS;
}
--
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