From ce422fd3b2831ab37de599f40297c6781e5bdfc0 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Fri, 27 Apr 2018 11:53:32 +0200
Subject: Fixed a size overflow in the global register list.

---
 plugins/dalvik/register.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/plugins/dalvik/register.c b/plugins/dalvik/register.c
index 0833650..8374e75 100644
--- a/plugins/dalvik/register.c
+++ b/plugins/dalvik/register.c
@@ -85,7 +85,7 @@ GDalvikRegister *_g_dalvik_register_new(uint16_t);
 
 /* Conservation des registres utilisés */
 static GDalvikRegister **_dalvik_registers = NULL;
-static uint16_t _dreg_count = 0;
+static size_t _dreg_count = 0;
 G_LOCK_DEFINE_STATIC(_dreg_mutex);
 
 
@@ -361,18 +361,21 @@ int g_dalvik_register_compare(const GDalvikRegister *a, const GDalvikRegister *b
 static GDalvikRegister *get_dalvik_register(uint16_t index)
 {
     GDalvikRegister *result;                /* Structure à retourner       */
-    uint16_t i;                             /* Boucle de parcours          */
+    size_t new_count;                       /* Nouvelle taille à considérer*/
+    size_t i;                               /* Boucle de parcours          */
 
     G_LOCK(_dreg_mutex);
 
     if (index >= _dreg_count)
     {
-        _dalvik_registers = realloc(_dalvik_registers, (index + 1) * sizeof(GDalvikRegister *));
+        new_count = index + 1;
 
-        for (i = _dreg_count; i < (index + 1); i++)
+        _dalvik_registers = realloc(_dalvik_registers, new_count * sizeof(GDalvikRegister *));
+
+        for (i = _dreg_count; i < new_count; i++)
             _dalvik_registers[i] = NULL;
 
-        _dreg_count = index + 1;
+        _dreg_count = new_count;
 
     }
 
@@ -404,7 +407,7 @@ static GDalvikRegister *get_dalvik_register(uint16_t index)
 
 void clean_dalvik_register_cache(void)
 {
-    uint16_t i;                             /* Boucle de parcours          */
+    size_t i;                               /* Boucle de parcours          */
 
     G_LOCK(_dreg_mutex);
 
-- 
cgit v0.11.2-87-g4458