From 2d9f22e04b520b38ecb56308c639b36b725d6783 Mon Sep 17 00:00:00 2001
From: winckel <winckel@eurecom.fr>
Date: Thu, 9 Jan 2014 10:18:26 +0000
Subject: [PATCH] Made buffer size dependent on name length to avoid overflow
 with long names.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4834 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 common/utils/itti_analyzer/libparser/field_type.c   | 2 +-
 common/utils/itti_analyzer/libparser/pointer_type.c | 2 +-
 common/utils/itti_analyzer/libparser/struct_type.c  | 4 ++--
 common/utils/itti_analyzer/libparser/typedef_type.c | 2 +-
 common/utils/itti_analyzer/libparser/union_type.c   | 4 ++--
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/common/utils/itti_analyzer/libparser/field_type.c b/common/utils/itti_analyzer/libparser/field_type.c
index 58538bd1fd..bf62a06a24 100644
--- a/common/utils/itti_analyzer/libparser/field_type.c
+++ b/common/utils/itti_analyzer/libparser/field_type.c
@@ -16,7 +16,7 @@ int field_dissect_from_buffer(
     buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent, gboolean new_line)
 {
     int length = 0;
-    char cbuf[200];
+    char cbuf[50 + (type->name ? strlen (type->name) : 0)];
     types_t *type_child;
     char array_info[50];
     new_line = FALSE;
diff --git a/common/utils/itti_analyzer/libparser/pointer_type.c b/common/utils/itti_analyzer/libparser/pointer_type.c
index 89de53312d..f35b96e29c 100644
--- a/common/utils/itti_analyzer/libparser/pointer_type.c
+++ b/common/utils/itti_analyzer/libparser/pointer_type.c
@@ -28,7 +28,7 @@ int pointer_dissect_from_buffer(
     {
         DISPLAY_TYPE("Ptr");
     }
-    if (type->child->name && type->child) {
+    if (type->child && type->child->name) {
         /*
          INDENTED(stdout, indent, fprintf(stdout, "<%s>0x%08x</%s>\n",
          type->child->name, value, type->child->name));
diff --git a/common/utils/itti_analyzer/libparser/struct_type.c b/common/utils/itti_analyzer/libparser/struct_type.c
index 5cf9e708a8..487c884691 100644
--- a/common/utils/itti_analyzer/libparser/struct_type.c
+++ b/common/utils/itti_analyzer/libparser/struct_type.c
@@ -17,12 +17,12 @@ int struct_dissect_from_buffer(
 {
     int i;
     int length = 0;
-    char cbuf[200];
+    char cbuf[50 + (type->name ? strlen (type->name) : 0)];
     char *name;
 
     DISPLAY_PARSE_INFO("structure", type->name, offset, parent_offset);
 
-    memset (cbuf, 0, 200);
+    memset (cbuf, 0, sizeof(cbuf));
 
     if (new_line) {
         DISPLAY_TYPE("Str");
diff --git a/common/utils/itti_analyzer/libparser/typedef_type.c b/common/utils/itti_analyzer/libparser/typedef_type.c
index 41bd415227..dc42dca9f3 100644
--- a/common/utils/itti_analyzer/libparser/typedef_type.c
+++ b/common/utils/itti_analyzer/libparser/typedef_type.c
@@ -13,7 +13,7 @@ int typedef_dissect_from_buffer(
     buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent, gboolean new_line)
 {
     int length = 0;
-    char cbuf[200];
+    char cbuf[50 + (type->name ? strlen (type->name) : 0)];
     types_t *type_child = NULL;
 
     DISPLAY_PARSE_INFO("typedef", type->name, offset, parent_offset);
diff --git a/common/utils/itti_analyzer/libparser/union_type.c b/common/utils/itti_analyzer/libparser/union_type.c
index fc3fe091ee..13db1f1755 100644
--- a/common/utils/itti_analyzer/libparser/union_type.c
+++ b/common/utils/itti_analyzer/libparser/union_type.c
@@ -55,13 +55,13 @@ int union_dissect_from_buffer(
     buffer_t *buffer, uint32_t offset, uint32_t parent_offset, int indent, gboolean new_line)
 {
     int length = 0;
-    char cbuf[200];
+    char cbuf[50 + (type->name ? strlen (type->name) : 0)];
     char *name;
     int union_child = 0;
 
     DISPLAY_PARSE_INFO("union", type->name, offset, parent_offset);
 
-    memset (cbuf, 0, 200);
+    memset (cbuf, 0, sizeof(cbuf));
 
 //    CHECK_FCT(buffer_has_enouch_data(buffer, offset + parent_offset, type->size / 8));
 
-- 
GitLab