[Forensics-changes] [yara] 38/160: Increase limits and dynamically allocate stack.

Hilko Bengen bengen at moszumanska.debian.org
Sat Jul 1 10:29:15 UTC 2017


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag v3.4.0
in repository yara.

commit 66229acfb7c1baa583b205193ffde7500b7edeeb
Author: Shane Huntley <shuntley at google.com>
Date:   Wed Mar 11 20:42:01 2015 -0700

    Increase limits and dynamically allocate stack.
---
 libyara/exec.c                | 10 ++++++++--
 libyara/include/yara/limits.h |  2 +-
 libyara/re.c                  |  2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/libyara/exec.c b/libyara/exec.c
index bac0084..918898f 100644
--- a/libyara/exec.c
+++ b/libyara/exec.c
@@ -29,6 +29,7 @@ limitations under the License.
 #include <yara/re.h>
 #include <yara/strutils.h>
 #include <yara/utils.h>
+#include <yara/mem.h>
 
 #include <yara.h>
 
@@ -157,7 +158,7 @@ int yr_execute_code(
   int32_t sp = 0;
   uint8_t* ip = rules->code_start;
 
-  union STACK_ITEM stack[STACK_SIZE];
+  union STACK_ITEM *stack;
   union STACK_ITEM r1;
   union STACK_ITEM r2;
   union STACK_ITEM r3;
@@ -180,6 +181,10 @@ int yr_execute_code(
   clock_t start = clock();
   #endif
 
+  stack = (union STACK_ITEM *) yr_malloc(STACK_SIZE * sizeof(union STACK_ITEM));
+  if (stack == NULL)
+    return ERROR_INSUFICIENT_MEMORY;
+
   while(1)
   {
     switch(*ip)
@@ -188,6 +193,7 @@ int yr_execute_code(
         // When the halt instruction is reached the stack
         // should be empty.
         assert(sp == 0);
+        yr_free(stack);
         return ERROR_SUCCESS;
 
       case OP_PUSH:
@@ -1075,6 +1081,6 @@ int yr_execute_code(
 
   // After executing the code the stack should be empty.
   assert(sp == 0);
-
+  yr_free(stack);
   return ERROR_SUCCESS;
 }
diff --git a/libyara/include/yara/limits.h b/libyara/include/yara/limits.h
index 62ba7d7..6bae815 100644
--- a/libyara/include/yara/limits.h
+++ b/libyara/include/yara/limits.h
@@ -42,7 +42,7 @@ limitations under the License.
 
 #define LOOP_LOCAL_VARS                 4
 #define STRING_CHAINING_THRESHOLD       200
-#define LEX_BUF_SIZE                    1024
+#define LEX_BUF_SIZE                    8192
 
 
 #endif
diff --git a/libyara/re.c b/libyara/re.c
index d279ed3..643bc8f 100644
--- a/libyara/re.c
+++ b/libyara/re.c
@@ -46,7 +46,7 @@ order to avoid confusion with operating system threads.
 
 
 #define RE_MAX_STACK      1024  // Maxium stack size for regexp evaluation
-#define RE_MAX_CODE_SIZE  16384 // Maximum code size for a compiled regexp
+#define RE_MAX_CODE_SIZE  32768 // Maximum code size for a compiled regexp
 #define RE_SCAN_LIMIT     4096  // Maximum input size scanned by yr_re_exec
 
 

-- 
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