[Forensics-changes] [yara] 142/368: Fixes the array issue with #388

Hilko Bengen bengen at moszumanska.debian.org
Sat Jul 1 10:30:21 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 8456dd140cb268593d8c0cd23ed76ef14b32c69b
Author: AB <AB at null.com>
Date:   Sat Jan 9 20:36:32 2016 -0800

    Fixes the array issue with #388
---
 libyara/exec.c   |  1 +
 libyara/object.c | 28 +++++++++++++++++++++++++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/libyara/exec.c b/libyara/exec.c
index 29e562e..45e0a32 100644
--- a/libyara/exec.c
+++ b/libyara/exec.c
@@ -489,6 +489,7 @@ int yr_execute_code(
         pop(r2);  // array
 
         ensure_defined(r1);
+        ensure_defined(r2);
         assert(r2.o->type == OBJECT_TYPE_ARRAY);
 
         r1.o = yr_object_array_get_item(r2.o, 0, (int) r1.i);
diff --git a/libyara/object.c b/libyara/object.c
index 3fe38ea..c375e19 100644
--- a/libyara/object.c
+++ b/libyara/object.c
@@ -609,6 +609,28 @@ int yr_object_copy(
       break;
 
     case OBJECT_TYPE_ARRAY:
+      ;
+      YR_OBJECT_ARRAY *array = (YR_OBJECT_ARRAY *) object;
+      YR_OBJECT *array_prototype_item;
+
+      yr_object_copy(array->prototype_item, &array_prototype_item);
+
+      ((YR_OBJECT_ARRAY *)copy)->prototype_item = array_prototype_item;
+
+      if (array->items == NULL)
+      {
+        uint8_t init_size = 64;
+
+        array->items = (YR_ARRAY_ITEMS*) yr_malloc(
+            sizeof(YR_ARRAY_ITEMS) + init_size * sizeof(YR_OBJECT*));
+
+        if (array->items == NULL)
+          return ERROR_INSUFICIENT_MEMORY;
+
+        memset(array->items->objects, 0, init_size * sizeof(YR_OBJECT*));
+
+        array->items->count = 0;
+      }
 
       array_items = ((YR_OBJECT_ARRAY*) object)->items;
 
@@ -632,11 +654,11 @@ int yr_object_copy(
     case OBJECT_TYPE_DICTIONARY:
       ;
       YR_OBJECT_DICTIONARY *dict = (YR_OBJECT_DICTIONARY *) object;
-      YR_OBJECT *prototype_item;
+      YR_OBJECT *dictionary_prototype_item;
 
-      yr_object_copy(dict->prototype_item, &prototype_item);
+      yr_object_copy(dict->prototype_item, &dictionary_prototype_item);
 
-      ((YR_OBJECT_DICTIONARY *)copy)->prototype_item = prototype_item;
+      ((YR_OBJECT_DICTIONARY *)copy)->prototype_item = dictionary_prototype_item;
 
       break;
 

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