[Forensics-changes] [yara] 287/368: Fix issues in 32-bits mode introduced in 0db16d3639140c0b6a7a6d0de06e5e2622e90c04

Hilko Bengen bengen at moszumanska.debian.org
Sat Jul 1 10:30:49 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 a834857e3dbc93963e2bfb67fa608b5d9c6b031a
Author: plusvic <plusvic at gmail.com>
Date:   Tue May 31 13:29:35 2016 +0200

    Fix issues in 32-bits mode introduced in 0db16d3639140c0b6a7a6d0de06e5e2622e90c04
---
 libyara/ahocorasick.c              | 25 ++++++++++++++-----------
 libyara/include/yara/ahocorasick.h |  4 ++--
 libyara/include/yara/types.h       | 13 ++++++++++---
 libyara/rules.c                    |  4 ++--
 4 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/libyara/ahocorasick.c b/libyara/ahocorasick.c
index 453fdc3..9e77964 100644
--- a/libyara/ahocorasick.c
+++ b/libyara/ahocorasick.c
@@ -458,12 +458,15 @@ int _yr_ac_find_suitable_transition_table_slot(
 
     if (automaton->tables_size - i < 257)
     {
-      size_t t_bytes_size = automaton->tables_size * sizeof(YR_AC_TRANSITION);
-      size_t m_bytes_size = automaton->tables_size * sizeof(YR_AC_MATCH*);
+      size_t t_bytes_size = automaton->tables_size *
+          sizeof(YR_AC_TRANSITION);
+
+      size_t m_bytes_size = automaton->tables_size * 
+          sizeof(YR_AC_MATCH_TABLE_ENTRY);
 
       automaton->t_table = (YR_AC_TRANSITION_TABLE) yr_realloc(
           automaton->t_table, t_bytes_size * 2);
-      
+
 	  automaton->m_table = (YR_AC_MATCH_TABLE) yr_realloc(
           automaton->m_table, m_bytes_size * 2);
 
@@ -582,7 +585,7 @@ int _yr_ac_build_transition_table(
       automaton->tables_size * sizeof(YR_AC_TRANSITION));
 
   automaton->m_table = (YR_AC_MATCH_TABLE) yr_malloc(
-      automaton->tables_size * sizeof(YR_AC_MATCH*));
+      automaton->tables_size * sizeof(YR_AC_MATCH_TABLE_ENTRY));
 
   if (automaton->t_table == NULL || automaton->t_table == NULL)
   {
@@ -596,10 +599,10 @@ int _yr_ac_build_transition_table(
       automaton->tables_size * sizeof(YR_AC_TRANSITION));
 
   memset(automaton->m_table, 0,
-      automaton->tables_size * sizeof(YR_AC_MATCH*));
+      automaton->tables_size * sizeof(YR_AC_MATCH_TABLE_ENTRY));
 
   automaton->t_table[0] = YR_AC_MAKE_TRANSITION(0, 0, YR_AC_USED_FLAG);
-  automaton->m_table[0] = root_state->matches;
+  automaton->m_table[0].match = root_state->matches;
 
   // Index 0 is for root node. Unused indexes start at 1.
   automaton->t_table_unused_candidate = 1;
@@ -632,7 +635,7 @@ int _yr_ac_build_transition_table(
     automaton->t_table[slot] = YR_AC_MAKE_TRANSITION(
         state->failure->t_table_slot, 0, YR_AC_USED_FLAG);
 
-    automaton->m_table[slot] = state->matches;
+    automaton->m_table[slot].match = state->matches;
 
     // Push childrens of current_state
 
@@ -909,13 +912,13 @@ int yr_ac_compile(
   FAIL_ON_ERROR(yr_arena_write_data(
       arena,
       automaton->m_table,
-      sizeof(YR_AC_MATCH*),
+      sizeof(YR_AC_MATCH_TABLE_ENTRY),
       (void**) &tables->matches));
 
   FAIL_ON_ERROR(yr_arena_make_relocatable(
       arena,
       tables->matches,
-      0,
+      offsetof(YR_AC_MATCH_TABLE_ENTRY, match),
       EOL));
 
   for (i = 1; i < automaton->tables_size; i++)
@@ -925,13 +928,13 @@ int yr_ac_compile(
     FAIL_ON_ERROR(yr_arena_write_data(
         arena,
         automaton->m_table + i,
-        sizeof(YR_AC_MATCH*),
+        sizeof(YR_AC_MATCH_TABLE_ENTRY),
         (void**) &ptr));
 
     FAIL_ON_ERROR(yr_arena_make_relocatable(
         arena,
         ptr,
-        0,
+        offsetof(YR_AC_MATCH_TABLE_ENTRY, match),
         EOL));
   }
 
diff --git a/libyara/include/yara/ahocorasick.h b/libyara/include/yara/ahocorasick.h
index 1e497e4..276fa03 100644
--- a/libyara/include/yara/ahocorasick.h
+++ b/libyara/include/yara/ahocorasick.h
@@ -35,10 +35,10 @@ limitations under the License.
 #define YR_AC_UNUSED_TRANSITION_SLOT(x) (!YR_AC_USED_TRANSITION_SLOT(x))
 
 
-typedef struct ac_tables
+typedef struct _YR_AC_TABLES
 {
   YR_AC_TRANSITION* transitions;
-  YR_AC_MATCH** matches;
+  YR_AC_MATCH_TABLE_ENTRY* matches;
 
 } YR_AC_TABLES;
 
diff --git a/libyara/include/yara/types.h b/libyara/include/yara/types.h
index 0cf8241..4f86556 100644
--- a/libyara/include/yara/types.h
+++ b/libyara/include/yara/types.h
@@ -278,9 +278,16 @@ typedef struct _YR_AC_MATCH
 } YR_AC_MATCH;
 
 
-typedef uint64_t            YR_AC_TRANSITION;
-typedef YR_AC_TRANSITION*   YR_AC_TRANSITION_TABLE;
-typedef YR_AC_MATCH**       YR_AC_MATCH_TABLE;
+typedef struct _YR_AC_MATCH_TABLE_ENTRY
+{
+  DECLARE_REFERENCE(YR_AC_MATCH*, match);
+
+} YR_AC_MATCH_TABLE_ENTRY;
+
+
+typedef uint64_t                  YR_AC_TRANSITION;
+typedef YR_AC_TRANSITION*         YR_AC_TRANSITION_TABLE;
+typedef YR_AC_MATCH_TABLE_ENTRY*  YR_AC_MATCH_TABLE;
 
 
 typedef struct _YARA_RULES_FILE_HEADER
diff --git a/libyara/rules.c b/libyara/rules.c
index e40d9df..517a7c0 100644
--- a/libyara/rules.c
+++ b/libyara/rules.c
@@ -232,7 +232,7 @@ int _yr_rules_scan_mem_block(
 
   while (i < block->size)
   {
-    match = match_table[state];
+    match = match_table[state].match;
 
     while (match != NULL)
     {
@@ -278,7 +278,7 @@ int _yr_rules_scan_mem_block(
   }
 
 
-  match = match_table[state];
+  match = match_table[state].match;
 
   while (match != NULL)
   {

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