aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-tpncp.c
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2022-02-01 22:34:54 +0200
committerA Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2022-06-19 17:26:40 +0000
commit0bc756c2c06989f0e227073b8067ab339dd0d487 (patch)
tree08b582a742ddcb12a3e64fc38451925d4fdb75ca /epan/dissectors/packet-tpncp.c
parent058fe0dd09bb6fe78b7e2ca929682a5241b0cd3b (diff)
TPNCP: Simplify size tracking
This also fixes a crash when tpncp.dat is missing the events part.
Diffstat (limited to 'epan/dissectors/packet-tpncp.c')
-rw-r--r--epan/dissectors/packet-tpncp.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/epan/dissectors/packet-tpncp.c b/epan/dissectors/packet-tpncp.c
index 4012b54a30..a9681d1eb3 100644
--- a/epan/dissectors/packet-tpncp.c
+++ b/epan/dissectors/packet-tpncp.c
@@ -118,7 +118,7 @@ static value_string tpncp_events_id_vals[MAX_TPNCP_DB_SIZE];
static value_string tpncp_enums_id_vals[MAX_ENUMS_NUM][MAX_ENUM_ENTRIES];
static gchar *tpncp_enums_name_vals[MAX_ENUMS_NUM];
-static gint hf_size = 1;
+static gint hf_size = 0;
static gint hf_allocated = 0;
static hf_register_info *hf = NULL;
@@ -549,7 +549,7 @@ get_enum_name_val(const gchar *enum_name)
static gboolean add_hf(hf_register_info *hf_entr)
{
- if (hf_size > hf_allocated) {
+ if (hf_size >= hf_allocated) {
void *newbuf;
hf_allocated += 1024;
newbuf = wmem_realloc(wmem_epan_scope(), hf, hf_allocated * sizeof (hf_register_info));
@@ -557,7 +557,7 @@ static gboolean add_hf(hf_register_info *hf_entr)
return FALSE;
hf = (hf_register_info *) newbuf;
}
- memcpy(hf + hf_size - 1, hf_entr, sizeof (hf_register_info));
+ memcpy(hf + hf_size, hf_entr, sizeof (hf_register_info));
hf_size++;
return TRUE;
}
@@ -688,18 +688,17 @@ init_tpncp_data_fields_info(tpncp_data_field_info *data_fields_info, FILE *file)
void *newbuf;
/* Register non-standard data should be done only once. */
- hf_allocated = hf_size + (int) array_length(hf_tpncp) - 1;
+ hf_allocated = hf_size + (int) array_length(hf_tpncp);
newbuf = wmem_realloc(wmem_epan_scope(), hf, hf_allocated * sizeof (hf_register_info));
if (!newbuf)
return -1;
hf = (hf_register_info *) newbuf;
for (idx = 0; idx < array_length(hf_tpncp); idx++) {
- memcpy(hf + (hf_size - 1), hf_tpncp + idx, sizeof (hf_register_info));
+ memcpy(hf + hf_size, hf_tpncp + idx, sizeof (hf_register_info));
hf_size++;
}
was_registered = TRUE;
- } else
- hf_size++;
+ }
is_address_family = FALSE;
ip_addr_field = 0;
@@ -709,10 +708,8 @@ init_tpncp_data_fields_info(tpncp_data_field_info *data_fields_info, FILE *file)
special_type = TPNCP_NORMAL;
since = 0;
snprintf(entry_copy, MAX_TPNCP_DB_ENTRY_LEN, "%s", tpncp_db_entry);
- if (!strncmp(tpncp_db_entry, "#####", 5)) {
- hf_size--;
+ if (!strncmp(tpncp_db_entry, "#####", 5))
break;
- }
/* Default to decimal display type */
hf_entr.hfinfo.display = BASE_DEC;