From 21635af249ba800429831c401cb61018fa568c2a Mon Sep 17 00:00:00 2001
From: winckel <winckel@eurecom.fr>
Date: Wed, 4 Dec 2013 18:13:52 +0000
Subject: [PATCH] Improved detections and processing of null terminated c
 string in itti analyzer.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4599 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 common/utils/itti_analyzer/libparser/array_type.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/common/utils/itti_analyzer/libparser/array_type.c b/common/utils/itti_analyzer/libparser/array_type.c
index 6379543f3d..87c9c2afd2 100644
--- a/common/utils/itti_analyzer/libparser/array_type.c
+++ b/common/utils/itti_analyzer/libparser/array_type.c
@@ -51,13 +51,15 @@ int array_dissect_from_buffer(
             }
 
             /* Check if this is an array of 8 bits items and if at least the firsts ones are not null */
-            if ((type_child->size == 8) && ((items - zero_counter) >= 2))
+            if ((type_child->size == 8) && (zero_counter >= 1) && ((items - zero_counter) >= 2))
             {
+                int end = items - zero_counter;
+
                 /* check if this is a printable string */
                 is_string = TRUE;
-                string = calloc(items + 1, 1);
+                string = malloc(end + 1);
 
-                for (i = 0; i < (items - zero_counter); i++)
+                for (i = 0; i < end; i++)
                 {
                     string[i] = fundamental_read_from_buffer(type_child, buffer, parent_offset, offset + i * type_child->size);
                     if (isprint(string[i]) == 0)
@@ -70,7 +72,8 @@ int array_dissect_from_buffer(
 
                 if (is_string)
                 {
-                    INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, "[%d .. %d] \"%s\"\n", 0, (items - zero_counter - 1), string));
+                    string[i] = '\0';
+                    INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, "[0 .. %d] \"%s\"\n", end - 1, string));
                     ui_set_signal_text_cb(user_data, cbuf, length);
                 }
             }
-- 
GitLab