[Forensics-changes] [yara] 398/407: Fix issue #237

Hilko Bengen bengen at moszumanska.debian.org
Sat Jul 1 10:28:49 UTC 2017


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

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

commit 7af17060ab516e9af82a69a91715b36080a62472
Author: Victor M. Alvarez <plusvic at gmail.com>
Date:   Mon Feb 9 12:44:53 2015 +0100

    Fix issue #237
---
 libyara/re.c   | 25 ++++++++++++++++++++-----
 libyara/scan.c | 32 +++++++++++++++++++++++++-------
 2 files changed, 45 insertions(+), 12 deletions(-)

diff --git a/libyara/re.c b/libyara/re.c
index c647610..644e935 100644
--- a/libyara/re.c
+++ b/libyara/re.c
@@ -1519,7 +1519,9 @@ int _yr_re_fiber_sync(
 //    Integer indicating the number of matching bytes, including 0 when
 //    matching an empty regexp. Negative values indicate:
 //      -1  No match
-//      -2  An error ocurred
+//      -2  Not enough memory
+//      -3  Too many matches
+//      -4  Unknown fatal error
 
 int yr_re_exec(
     RE_CODE re_code,
@@ -1758,12 +1760,25 @@ int yr_re_exec(
           {
             if (callback != NULL)
             {
+              int cb_result;
+
               if (flags & RE_FLAGS_BACKWARDS)
-                callback(input + character_size, count,
-                         flags, callback_args);
+                cb_result = callback(
+                    input + character_size, count, flags, callback_args);
               else
-                callback(input_data, count,
-                         flags, callback_args);
+                cb_result = callback(
+                    input_data, count, flags, callback_args);
+
+              switch(cb_result)
+              {
+                case ERROR_INSUFICIENT_MEMORY:
+                  return -2;
+                case ERROR_TOO_MANY_MATCHES:
+                  return -3;
+                default:
+                  if (cb_result != ERROR_SUCCESS)
+                    return -4;
+              }
             }
 
             action = ACTION_KILL;
diff --git a/libyara/scan.c b/libyara/scan.c
index 0065ed1..a5179ec 100644
--- a/libyara/scan.c
+++ b/libyara/scan.c
@@ -202,11 +202,23 @@ int _yr_scan_fast_hex_re_exec(
       {
         if (flags & RE_FLAGS_EXHAUSTIVE)
         {
-            callback(
+            int cb_result = callback(
                flags & RE_FLAGS_BACKWARDS ? current_input + 1 : input,
                matches,
                flags,
                callback_args);
+
+            switch(cb_result)
+            {
+              case ERROR_INSUFICIENT_MEMORY:
+                return -2;
+              case ERROR_TOO_MANY_MATCHES:
+                return -3;
+              default:
+                if (cb_result != ERROR_SUCCESS)
+                  return -4;
+            }
+
             break;
         }
         else
@@ -285,7 +297,7 @@ int _yr_scan_fast_hex_re_exec(
               assert(sp < MAX_FAST_HEX_RE_STACK);
 
               if (sp >= MAX_FAST_HEX_RE_STACK)
-                return -3;
+                return -4;
 
               code_stack[sp] = ip + 11;
               input_stack[sp] = next_input;
@@ -683,6 +695,8 @@ int _yr_scan_verify_re_match(
     case -2:
       return ERROR_INSUFICIENT_MEMORY;
     case -3:
+      return ERROR_TOO_MANY_MATCHES;
+    case -4:
       return ERROR_INTERNAL_FATAL_ERROR;
   }
 
@@ -708,11 +722,15 @@ int _yr_scan_verify_re_match(
         _yr_scan_match_callback,
         (void*) &callback_args);
 
-    if (backward_matches == -2)
-      return ERROR_INSUFICIENT_MEMORY;
-
-    if (backward_matches == -3)
-      return ERROR_INTERNAL_FATAL_ERROR;
+    switch(backward_matches)
+    {
+      case -2:
+        return ERROR_INSUFICIENT_MEMORY;
+      case -3:
+        return ERROR_TOO_MANY_MATCHES;
+      case -4:
+        return ERROR_INTERNAL_FATAL_ERROR;
+    }
   }
   else
   {

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