Bug Summary

File:builds/wireshark/wireshark/epan/dissectors/packet-tpncp.c
Warning:line 465, column 10
Read function called when stream is in EOF state. Function has no effect

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name packet-tpncp.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-22/lib/clang/22 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /builds/wireshark/wireshark/epan/dissectors -isystem /builds/wireshark/wireshark/build/epan/dissectors -isystem /usr/include/mit-krb5 -isystem /builds/wireshark/wireshark/epan -isystem /usr/include/libxml2 -D CARES_NO_DEPRECATED -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_BUILD_DLL -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-22/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -std=gnu17 -ferror-limit 19 -fvisibility=hidden -fwrapv -fwrapv-pointer -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /builds/wireshark/wireshark/sbout/2026-12-04-100315-3660-1 -x c /builds/wireshark/wireshark/epan/dissectors/packet-tpncp.c
1/* packet-tpncp.c
2 * Routines for Audiocodes TrunkPack Network Control Protocol (TPNCP) dissection
3 *
4 * Copyright (c) 2007 by Valery Sigalov <valery.sigalov@audiocodes.com>
5 *
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.com>
8 * Copyright 1998 Gerald Combs
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
13/*---------------------------------------------------------------------------*/
14
15#include "config.h"
16#define WS_LOG_DOMAIN"TPNCP" "TPNCP"
17
18#include <epan/packet.h>
19#include <epan/exceptions.h>
20#include <epan/expert.h>
21#include <epan/prefs.h>
22#include <wsutil/filesystem.h>
23#include <wsutil/file_util.h>
24#include <wsutil/report_message.h>
25#include <wsutil/strtoi.h>
26#include <epan/wmem_scopes.h>
27#include "packet-acdr.h"
28#include "packet-tcp.h"
29
30/*---------------------------------------------------------------------------*/
31
32#define BASE_TPNCP_PORT2424 2424
33#define HA_PORT_TPNCP_TRUNKPACK2442 2442
34#define TCP_PORT_TPNCP_TRUNKPACK2424 BASE_TPNCP_PORT2424
35#define UDP_PORT_TPNCP_TRUNKPACK2424 BASE_TPNCP_PORT2424
36#define TCP_PORT_TPNCP_HOST2424 BASE_TPNCP_PORT2424
37#define UDP_PORT_TPNCP_HOST2424 BASE_TPNCP_PORT2424
38
39#define MAX_TPNCP_DB_ENTRY_LEN3000 3000
40
41/*---------------------------------------------------------------------------*/
42
43void proto_register_tpncp(void);
44void proto_reg_handoff_tpncp(void);
45
46enum SpecialFieldType {
47 TPNCP_NORMAL,
48 TPNCP_ADDRESS_FAMILY,
49 TPNCP_IP_ADDR,
50 TPNCP_OPEN_CHANNEL_START,
51 TPNCP_SECURITY_START,
52 TPNCP_SECURITY_OFFSET,
53 RTP_STATE_START,
54 RTP_STATE_OFFSET,
55 RTP_STATE_END,
56 TPNCP_CHANNEL_CONFIGURATION
57};
58
59/* The linked list for storing information about specific data fields. */
60typedef struct tpncp_data_field_info
61{
62 char *name;
63 int descr;
64 int ipv6_descr;
65 int array_dim;
66 enum SpecialFieldType special_type;
67 unsigned char size;
68 unsigned char sign;
69 int since;
70 struct tpncp_data_field_info *p_next;
71} tpncp_data_field_info;
72
73/*---------------------------------------------------------------------------
74 * Desegmentation of TPNCP over TCP */
75static bool_Bool tpncp_desegment = true1;
76
77/* Database for storing information about all TPNCP events. */
78static tpncp_data_field_info **tpncp_events_info_db;
79static unsigned tpncp_events_info_len;
80
81/* Database for storing information about all TPNCP commands. */
82static tpncp_data_field_info **tpncp_commands_info_db;
83static unsigned tpncp_commands_info_len;
84
85/* Global variables for bitfields representation. */
86/* TPNCP packet header fields. */
87static int proto_tpncp;
88static int hf_tpncp_version;
89static int hf_tpncp_length;
90static int hf_tpncp_seq_number;
91static int hf_tpncp_length_ext;
92static int hf_tpncp_reserved;
93static int hf_tpncp_command_id;
94static int hf_tpncp_event_id;
95static int hf_tpncp_cid;
96
97static expert_field ei_tpncp_unknown_data;
98
99/* TPNCP fields defining a subtree. */
100static int ett_tpncp;
101static int ett_tpncp_body;
102
103static bool_Bool global_tpncp_load_db;
104static const char *tpncp_dat_path = NULL((void*)0);
105
106static dissector_handle_t tpncp_handle;
107static dissector_handle_t tpncp_tcp_handle;
108
109/* TODO: Runtime value_string_ext arrays should be used*/
110static value_string *tpncp_commands_id_vals;
111static value_string *tpncp_events_id_vals;
112static value_string **tpncp_enums_id_vals;
113static char **tpncp_enums_name_vals;
114
115static int hf_size;
116static int hf_allocated;
117static hf_register_info *hf;
118
119static bool_Bool db_initialized;
120
121/*---------------------------------------------------------------------------*/
122
123enum AddressFamily {
124 TPNCP_IPV4 = 2,
125 TPNCP_IPV6 = 10,
126 TPNCP_IPV6_PSOS = 28
127};
128
129static void
130dissect_tpncp_data(unsigned data_id, packet_info *pinfo, tvbuff_t *tvb, proto_tree *ltree,
131 int *offset, tpncp_data_field_info **data_fields_info, int ver, unsigned encoding)
132{
133 unsigned g_str_len;
134 tpncp_data_field_info *field = NULL((void*)0);
135 int bitindex = encoding == ENC_LITTLE_ENDIAN0x80000000 ? 7 : 0;
136 enum AddressFamily address_family = TPNCP_IPV4;
137 int open_channel_start = -1, security_offset = 0, rtp_state_offset = 0;
138 int channel_b_offset = 0, rtp_tx_state_offset = 0, rtp_state_size = 0;
139 const int initial_offset = *offset;
140
141 for (field = data_fields_info[data_id]; field; field = field->p_next) {
142 if (field->since > 0 && field->since > ver)
143 continue;
144 switch (field->special_type) {
145 case TPNCP_OPEN_CHANNEL_START:
146 open_channel_start = *offset;
147 break;
148 case TPNCP_SECURITY_OFFSET: {
149 const uint32_t sec_offset = tvb_get_uint32(tvb, *offset, encoding);
150 if (sec_offset > 0 && open_channel_start >= 0 && sec_offset <= (uint32_t)(G_MAXINT2147483647 - open_channel_start))
151 security_offset = open_channel_start + (int)sec_offset;
152 break;
153 }
154 case TPNCP_SECURITY_START:
155 /* Without a (valid) offset the section is not moved: do not go back to 0 */
156 if (security_offset > 0)
157 *offset = security_offset;
158 open_channel_start = -1;
159 security_offset = 0;
160 break;
161 case RTP_STATE_OFFSET:
162 rtp_state_offset = tvb_get_int32(tvb, *offset, encoding);
163 if (rtp_state_offset > 0) {
164 if (rtp_state_offset <= G_MAXINT2147483647 - (initial_offset + 4))
165 rtp_state_offset += initial_offset + 4; /* The offset starts after CID */
166 else
167 rtp_state_offset = 0;
168 }
169 break;
170 case RTP_STATE_START:
171 if (rtp_tx_state_offset == 0) {
172 unsigned rtp_remaining;
173 if (rtp_state_offset <= 0) {
174 /* No (valid) offset: do not go back to 0 */
175 rtp_state_offset = 0;
176 break;
177 }
178 *offset = rtp_state_offset;
179 rtp_state_offset = 0;
180 rtp_remaining = tvb_reported_length_remaining(tvb, *offset);
181 rtp_state_size = rtp_remaining >= 4 ? (int)((rtp_remaining - 4) / 2) : 0;
182 rtp_tx_state_offset = *offset + rtp_state_size;
183 } else {
184 rtp_state_offset = 0;
185 *offset = rtp_tx_state_offset;
186 rtp_tx_state_offset += rtp_state_size;
187 }
188 break;
189 case RTP_STATE_END:
190 rtp_tx_state_offset = 0;
191 break;
192 case TPNCP_CHANNEL_CONFIGURATION:
193 if (channel_b_offset == 0) {
194 int channel_configuration_size = tvb_reported_length_remaining(tvb, *offset) / 2;
195 channel_b_offset = *offset + channel_configuration_size;
196 } else {
197 *offset = channel_b_offset;
198 channel_b_offset = 0;
199 }
200 break;
201 case TPNCP_ADDRESS_FAMILY:
202 address_family = (enum AddressFamily)tvb_get_uint32(tvb, *offset, encoding);
203 // fall-through
204 default:
205 if (open_channel_start != -1 && security_offset > 0 && *offset >= security_offset)
206 continue;
207 if (rtp_state_offset > 0 && *offset >= rtp_state_offset)
208 continue;
209 if (rtp_tx_state_offset > 0 && *offset >= rtp_tx_state_offset)
210 continue;
211 if (channel_b_offset > 0 && *offset >= channel_b_offset)
212 continue;
213 break;
214 }
215 switch (field->size) {
216 case 1: case 2: case 3: case 4:
217 case 5: case 6: case 7: case 8:
218 /* add char array */
219 if ((g_str_len = field->array_dim)) {
220 const unsigned remaining = tvb_reported_length_remaining(tvb, *offset);
221 g_str_len = MIN(g_str_len, remaining)(((g_str_len) < (remaining)) ? (g_str_len) : (remaining));
222 proto_tree_add_item(ltree, field->descr, tvb, *offset, g_str_len, ENC_NA0x00000000 | ENC_ASCII0x00000000);
223 (*offset) += g_str_len;
224 } else { /* add single char */
225 /* Output only the numeric value for 8-bit fields, considering sign, with no extra formatting. */
226 if (field->size == 8) {
227 uint8_t g_uchar = tvb_get_uint8(tvb, *offset);
228 if (field->sign)
229 proto_tree_add_uint(ltree, field->descr, tvb, *offset, 1, g_uchar);
230 else
231 proto_tree_add_int(ltree, field->descr, tvb, *offset, 1, (int8_t)g_uchar);
232 (*offset)++;
233 } else { /* unsigned bitfield <8 */
234 unsigned bit_offset;
235
236 /*
237 * tpncp.dat always lists bitfields in little-endian (LSB-first) order, regardless of encoding.
238 * Wireshark's proto_tree_add_bits_item with ENC_LITTLE_ENDIAN matches this order.
239 *
240 * Therefore, we always use ENC_LITTLE_ENDIAN for bitfield extraction, regardless of the packet encoding.
241 *
242 * bit_offset is simply (*offset) * 8 + bitindex, and bitindex increments by field->size.
243 */
244 bit_offset = (*offset) * 8 + bitindex;
245 proto_tree_add_bits_item(ltree, field->descr, tvb, bit_offset, field->size, ENC_LITTLE_ENDIAN0x80000000);
246
247 bitindex += field->size;
248 (*offset) += bitindex / 8;
249 bitindex %= 8;
250 }
251 }
252 break;
253 case 16:
254 proto_tree_add_item(ltree, field->descr, tvb, *offset, 2, encoding);
255 (*offset) += 2;
256 break;
257 case 32:
258 proto_tree_add_item(ltree, field->descr, tvb, *offset, 4, encoding);
259 (*offset) += 4;
260 break;
261 case 64:
262 proto_tree_add_item(ltree, field->descr, tvb, *offset, 8, encoding);
263 (*offset) += 8;
264 break;
265 case 128:
266 if (field->special_type == TPNCP_IP_ADDR) {
267 if (address_family == TPNCP_IPV6 || address_family == TPNCP_IPV6_PSOS)
268 proto_tree_add_item(ltree, field->ipv6_descr, tvb, *offset, 16, encoding);
269 else
270 proto_tree_add_item(ltree, field->descr, tvb, *offset, 4, encoding);
271 address_family = TPNCP_IPV4;
272 }
273 (*offset) += 16;
274 break;
275 default:
276 break;
277 }
278 if (tvb_reported_length_remaining(tvb, *offset) <= 0)
279 break;
280 }
281 if ((g_str_len = tvb_reported_length_remaining(tvb, *offset)) > 0) {
282 expert_add_info_format(pinfo, ltree, &ei_tpncp_unknown_data, "TPNCP Unknown Data");
283 (*offset) += g_str_len;
284 }
285}
286
287/*---------------------------------------------------------------------------*/
288static int
289dissect_tpncp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U___attribute__((unused)))
290{
291 proto_item *item = NULL((void*)0);
292 proto_tree *tpncp_tree = NULL((void*)0), *event_tree, *command_tree;
293 int offset = 0, cid = -1;
294 unsigned id;
295 unsigned seq_number, len, ver;
296 unsigned len_ext, reserved, encoding;
297 uint32_t fullLength;
298
299 if (!db_initialized)
300 return 0;
301
302 encoding = tvb_get_ntohs(tvb, 8) == 0 ? ENC_BIG_ENDIAN0x00000000 : ENC_LITTLE_ENDIAN0x80000000;
303
304 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TPNCP");
305
306 item = proto_tree_add_item(tree, proto_tpncp, tvb, 0, -1, ENC_NA0x00000000);
307 tpncp_tree = proto_item_add_subtree(item, ett_tpncp);
308
309 proto_tree_add_item_ret_uint(tpncp_tree, hf_tpncp_version, tvb, 0, 2, encoding, &ver);
310 proto_tree_add_item_ret_uint(tpncp_tree, hf_tpncp_length, tvb, 2, 2, encoding, &len);
311 proto_tree_add_item_ret_uint(tpncp_tree, hf_tpncp_seq_number, tvb, 4, 2, encoding, &seq_number);
312 proto_tree_add_item_ret_uint(tpncp_tree, hf_tpncp_length_ext, tvb, 6, 1, encoding, &len_ext);
313 proto_tree_add_item_ret_uint(tpncp_tree, hf_tpncp_reserved, tvb, 7, 1, encoding, &reserved);
314 fullLength = 0xffff * len_ext + len;
315
316 id = tvb_get_uint32(tvb, 8, encoding);
317 if (len > 8)
318 cid = tvb_get_int32(tvb, 12, encoding);
319 if (pinfo->srcport == UDP_PORT_TPNCP_TRUNKPACK2424 ||
320 pinfo->srcport == HA_PORT_TPNCP_TRUNKPACK2442) {
321 if (try_val_to_str(id, tpncp_events_id_vals)) {
322 proto_tree_add_uint(tpncp_tree, hf_tpncp_event_id, tvb, 8, 4, id);
323 if (len > 8)
324 proto_tree_add_int(tpncp_tree, hf_tpncp_cid, tvb, 12, 4, cid);
325 offset += 16;
326 if (id < tpncp_events_info_len && tpncp_events_info_db[id] != NULL((void*)0) && len > 12) {
327 event_tree = proto_tree_add_subtree_format(
328 tree, tvb, offset, -1, ett_tpncp_body, NULL((void*)0),
329 "TPNCP Event: %s (%d)",
330 val_to_str_const(id, tpncp_events_id_vals, "Unknown"), id);
331 dissect_tpncp_data(id, pinfo, tvb, event_tree, &offset, tpncp_events_info_db,
332 ver, encoding);
333 }
334 }
335 col_add_fstr(pinfo->cinfo, COL_INFO,
336 "EvID=%s(%d), SeqNo=%d, CID=%d, Len=%d, Ver=%d",
337 val_to_str_const(id, tpncp_events_id_vals, "Unknown"),
338 id, seq_number, cid, fullLength, ver);
339 } else {
340 if (try_val_to_str(id, tpncp_commands_id_vals)) {
341 proto_tree_add_uint(tpncp_tree, hf_tpncp_command_id, tvb, 8, 4, id);
342 offset += 12;
343 if (id < tpncp_commands_info_len && tpncp_commands_info_db[id] != NULL((void*)0) && len > 8) {
344 command_tree = proto_tree_add_subtree_format(
345 tree, tvb, offset, -1, ett_tpncp_body, NULL((void*)0),
346 "TPNCP Command: %s (%d)",
347 val_to_str_const(id, tpncp_commands_id_vals, "Unknown"), id);
348 dissect_tpncp_data(id, pinfo, tvb, command_tree, &offset, tpncp_commands_info_db,
349 ver, encoding);
350 }
351 }
352 col_add_fstr(pinfo->cinfo, COL_INFO,
353 "CmdID=%s(%d), SeqNo=%d, CID=%d, Len=%d, Ver=%d",
354 val_to_str_const(id, tpncp_commands_id_vals, "Unknown"),
355 id, seq_number, cid, fullLength, ver);
356 }
357
358 return tvb_reported_length(tvb);
359}
360
361/*---------------------------------------------------------------------------*/
362
363static unsigned
364get_tpncp_pdu_len(packet_info *pinfo _U___attribute__((unused)), tvbuff_t *tvb, int offset, void *data _U___attribute__((unused)))
365{
366 uint32_t plen;
367 unsigned encoding;
368
369 /* The header up to the ID, which gives the byte order, must be available */
370 if (!tvb_bytes_exist(tvb, offset, 10))
371 return 0;
372
373 /* Same byte order detection as in dissect_tpncp() */
374 encoding = tvb_get_ntohs(tvb, offset + 8) == 0 ? ENC_BIG_ENDIAN0x00000000 : ENC_LITTLE_ENDIAN0x80000000;
375
376 /* Get the length of the TPNCP packet. */
377 plen = tvb_get_uint16(tvb, offset + 2, encoding) + 0xffff * tvb_get_uint8(tvb, offset + 6);
378
379 /* Length does not include the version+length field. */
380 plen += 4;
381
382 return plen;
383}
384
385/*---------------------------------------------------------------------------*/
386
387static int
388dissect_tpncp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
389{
390 if (!db_initialized)
391 return 0;
392
393 if (pinfo->can_desegment)
394 /* If desegmentation is enabled (TCP preferences) use the desegmentation API. */
395 tcp_dissect_pdus(tvb, pinfo, tree, tpncp_desegment, 4, get_tpncp_pdu_len,
396 dissect_tpncp, data);
397 else
398 /* Otherwise use the regular dissector (might not give correct dissection). */
399 dissect_tpncp(tvb, pinfo, tree, data);
400
401 return tvb_reported_length(tvb);
402}
403
404/* Dissect as TPNCP with pinfo->srcport set to the given port, restored also after an exception. */
405static int
406dissect_tpncp_with_srcport(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, uint32_t port)
407{
408 uint32_t orig_port = pinfo->srcport;
409 volatile int res = 0;
410
411 pinfo->srcport = port;
412 TRY{ except_t *volatile exc; volatile int except_state = 0; static
const except_id_t catch_spec[] = { { 1, 0 } }; { struct except_stacknode
except_sn; struct except_catch except_ch; except_setup_try(&
except_sn, &except_ch, catch_spec, 1); if (_setjmp (except_ch
.except_jmp)) *(&exc) = &except_ch.except_obj; else *
(&exc) = 0; if(except_state & 1) except_state |= 2; except_state
&= ~1; if (except_state == 0 && exc == 0)
{
413 res = dissect_tpncp(tvb, pinfo, tree, NULL((void*)0));
414 }
415 FINALLYif( !(except_state & 4) && (except_state|=4)) {
416 pinfo->srcport = orig_port;
417 }
418 ENDTRYif(!(except_state&1) && exc != 0) except_rethrow(
exc); except_free(except_ch.except_obj.except_dyndata); except_pop
(); };}
;
419 return res;
420}
421
422static int
423dissect_acdr_event(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
424{
425 acdr_dissector_data_t *acdr_data = (acdr_dissector_data_t *) data;
426
427 if (acdr_data == NULL((void*)0))
428 return 0;
429
430 // only on version 2+ events are sent with TPNCP header that enables using tpncp parser
431 if (acdr_data->version <= 1)
432 return 0;
433
434 // the TPNCP dissector uses the following statement to
435 // differentiate command from event:
436 // if (pinfo->srcport == UDP_PORT_TPNCP_TRUNKPACK) -> Event
437 // so for proper dissection we want to imitate this behaviour
438 return dissect_tpncp_with_srcport(tvb, pinfo, tree, UDP_PORT_TPNCP_TRUNKPACK2424);
439}
440
441static int
442dissect_acdr_tpncp_by_tracepoint(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
443{
444 acdr_dissector_data_t *acdr_data = (acdr_dissector_data_t *) data;
445
446 if (acdr_data == NULL((void*)0))
447 return 0;
448
449 // the TPNCP dissector uses the following statement to
450 // differentiate command from event:
451 // if (pinfo->srcport == UDP_PORT_TPNCP_TRUNKPACK) -> Event
452 // so for proper dissection we want to imitate this behaviour
453
454 if (acdr_data->trace_point == Host2Net) // event
455 return dissect_tpncp_with_srcport(tvb, pinfo, tree, UDP_PORT_TPNCP_TRUNKPACK2424);
456 // Net2Host ->command
457 return dissect_tpncp_with_srcport(tvb, pinfo, tree, UDP_PORT_TPNCP_TRUNKPACK2424 + 1);
458}
459
460/*---------------------------------------------------------------------------*/
461
462static bool_Bool
463fgetline(char *buffer, int size, FILE *file)
464{
465 if (!fgets(buffer, size, file))
11
Assuming stream reaches end-of-file here
12
Taking true branch
21
Read function called when stream is in EOF state. Function has no effect
466 return 0;
467 size_t last = strlen(buffer);
468 if (last > 0 && buffer[last - 1] == '\n')
469 buffer[last - 1] = 0;
470 return 1;
471}
472
473static int
474fill_tpncp_id_vals(value_string **strings, FILE *file)
475{
476 wmem_array_t *vs_arr;
477 char *line_in_file;
478
479 if (file
8.1
'file' is not equal to NULL
18.1
'file' is not equal to NULL
== NULL((void*)0)) return -1;
9
Taking false branch
19
Taking false branch
480
481 line_in_file = (char *) g_malloc(MAX_TPNCP_DB_ENTRY_LEN3000);
482 vs_arr = wmem_array_new(NULL((void*)0), sizeof **strings);
483
484 while (fgetline(line_in_file, MAX_TPNCP_DB_ENTRY_LEN3000, file)) {
10
Calling 'fgetline'
13
Returning from 'fgetline'
14
Loop condition is false. Execution continues on line 499
20
Calling 'fgetline'
485 int tpncp_id = 0;
486 char tpncp_name[256];
487
488 if (!strncmp(line_in_file, "#####", 5))
489 break;
490 if (sscanf(line_in_file, "%255s %d", tpncp_name, &tpncp_id) == 2) {
491 value_string const string = {
492 .value = (uint32_t)tpncp_id,
493 .strptr = wmem_strdup(wmem_epan_scope(), tpncp_name)
494 };
495 wmem_array_append_one(vs_arr, string)wmem_array_append((vs_arr), &(string), 1);
496 }
497 }
498
499 wmem_array_set_null_terminator(vs_arr);
500 *strings = wmem_array_finalize(vs_arr);
501 g_free(line_in_file)(__builtin_object_size ((line_in_file), 0) != ((size_t) - 1))
? g_free_sized (line_in_file, __builtin_object_size ((line_in_file
), 0)) : (g_free) (line_in_file)
;
15
Assuming the condition is false
16
'?' condition is false
502
503 return 0;
504}
505
506/*---------------------------------------------------------------------------*/
507
508static int
509fill_enums_id_vals(char ***enum_names, value_string ***enum_value_strings, FILE *file)
510{
511 wmem_array_t *enum_name_arr, *enum_vs_arr, *enum_vs = NULL((void*)0);
512 char *line_in_file;
513 char enum_type[256];
514
515 line_in_file = (char *) g_malloc(MAX_TPNCP_DB_ENTRY_LEN3000);
516 enum_type[0] = '\0';
517
518 enum_name_arr = wmem_array_new(NULL((void*)0), sizeof **enum_names);
519 enum_vs_arr = wmem_array_new(NULL((void*)0), sizeof **enum_value_strings);
520
521 while (fgetline(line_in_file, MAX_TPNCP_DB_ENTRY_LEN3000, file)) {
522 char enum_name[256], enum_str[256];
523 int enum_id;
524
525 if (!strncmp(line_in_file, "#####", 5))
526 break;
527 if (sscanf(line_in_file, "%255s %255s %d", enum_name, enum_str, &enum_id) == 3) {
528 if (strcmp(enum_type, enum_name) != 0) {
529 /* New record. */
530 if (enum_vs != NULL((void*)0)) {
531 /* The previous enum_vs is now complete. */
532 wmem_array_set_null_terminator(enum_vs);
533 value_string *new_enum_vs = wmem_array_finalize(enum_vs);
534 wmem_array_append_one(enum_vs_arr, new_enum_vs)wmem_array_append((enum_vs_arr), &(new_enum_vs), 1);
535 }
536 enum_vs = wmem_array_sized_new(NULL((void*)0), sizeof ***enum_value_strings, 10);
537
538 char *enum_name_alloc = wmem_strdup(wmem_epan_scope(), enum_name);
539 wmem_array_append_one(enum_name_arr, enum_name_alloc)wmem_array_append((enum_name_arr), &(enum_name_alloc), 1);
540 (void) g_strlcpy(enum_type, enum_name, sizeof enum_type);
541 }
542 value_string const vs = {
543 .value = enum_id,
544 .strptr = wmem_strdup(wmem_epan_scope(), enum_str)
545 };
546 wmem_array_append_one(enum_vs, vs)wmem_array_append((enum_vs), &(vs), 1);
547 }
548 }
549
550 if (enum_vs != NULL((void*)0)) {
551 /* The final enum_vs is now complete. */
552 wmem_array_set_null_terminator(enum_vs);
553 value_string *new_enum_vs = wmem_array_finalize(enum_vs);
554 wmem_array_append_one(enum_vs_arr, new_enum_vs)wmem_array_append((enum_vs_arr), &(new_enum_vs), 1);
555 }
556
557 wmem_array_set_null_terminator(enum_name_arr);
558 *enum_names = (char **)wmem_array_finalize(enum_name_arr);
559
560 wmem_array_set_null_terminator(enum_vs_arr);
561 *enum_value_strings = (value_string **)wmem_array_finalize(enum_vs_arr);
562 g_free(line_in_file)(__builtin_object_size ((line_in_file), 0) != ((size_t) - 1))
? g_free_sized (line_in_file, __builtin_object_size ((line_in_file
), 0)) : (g_free) (line_in_file)
;
563
564 return 0;
565}
566
567/*---------------------------------------------------------------------------*/
568
569static int
570get_enum_name_val(const char *enum_name)
571{
572 int enum_val = 0;
573
574 while (tpncp_enums_name_vals[enum_val]) {
575 if (!strcmp(enum_name, tpncp_enums_name_vals[enum_val]))
576 return enum_val;
577 enum_val++;
578 }
579
580 return -1;
581}
582
583/*---------------------------------------------------------------------------*/
584
585static bool_Bool add_hf(hf_register_info *hf_entr)
586{
587 if (hf_size >= hf_allocated) {
588 void *newbuf;
589 hf_allocated += 1024;
590 newbuf = wmem_realloc(wmem_epan_scope(), hf, hf_allocated * sizeof (hf_register_info));
591 if (!newbuf)
592 return false0;
593 hf = (hf_register_info *) newbuf;
594 }
595 memcpy(hf + hf_size, hf_entr, sizeof (hf_register_info));
596 hf_size++;
597 return true1;
598}
599
600static int
601init_tpncp_data_fields_info(tpncp_data_field_info ***data_fields_info, unsigned *data_fields_len, FILE *file)
602{
603 static bool_Bool was_registered = false0;
604 char tpncp_db_entry[MAX_TPNCP_DB_ENTRY_LEN3000];
605 char entry_copy[MAX_TPNCP_DB_ENTRY_LEN3000];
606 const char *name = NULL((void*)0), *tmp = NULL((void*)0);
607 int enum_val, data_id, current_data_id = -1, array_dim;
608 unsigned char size;
609 enum SpecialFieldType special_type;
610 bool_Bool sign, is_address_family;
611 unsigned idx, since, ip_addr_field;
612 tpncp_data_field_info *field = NULL((void*)0);
613 hf_register_info hf_entr;
614 wmem_array_t *data_fields_info_arr;
615
616 hf_register_info hf_tpncp[] = {
617 {
618 &hf_tpncp_version,
619 {
620 "Version",
621 "tpncp.version",
622 FT_UINT16,
623 BASE_DEC,
624 NULL((void*)0),
625 0x0,
626 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)
627 }
628 },
629 {
630 &hf_tpncp_length,
631 {
632 "Length",
633 "tpncp.length",
634 FT_UINT16,
635 BASE_DEC,
636 NULL((void*)0),
637 0x0,
638 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)
639 }
640 },
641 {
642 &hf_tpncp_seq_number,
643 {
644 "Sequence number",
645 "tpncp.seq_number",
646 FT_UINT16,
647 BASE_DEC,
648 NULL((void*)0),
649 0x0,
650 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)
651 }
652 },
653 {
654 &hf_tpncp_length_ext,
655 {
656 "Length Extension",
657 "tpncp.lengthextension",
658 FT_UINT8,
659 BASE_DEC,
660 NULL((void*)0),
661 0x0,
662 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)
663 }
664 },
665 {
666 &hf_tpncp_reserved,
667 {
668 "Reserved",
669 "tpncp.reserved",
670 FT_UINT8,
671 BASE_DEC,
672 NULL((void*)0),
673 0x0,
674 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)
675 }
676 },
677 {
678 &hf_tpncp_command_id,
679 {
680 "Command ID",
681 "tpncp.command_id",
682 FT_UINT32,
683 BASE_DEC,
684 VALS(tpncp_commands_id_vals)((0 ? (const struct _value_string*)0 : ((tpncp_commands_id_vals
))))
,
685 0x0,
686 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)
687 }
688 },
689 {
690 &hf_tpncp_event_id,
691 {
692 "Event ID",
693 "tpncp.event_id",
694 FT_UINT32,
695 BASE_DEC,
696 VALS(tpncp_events_id_vals)((0 ? (const struct _value_string*)0 : ((tpncp_events_id_vals
))))
,
697 0x0,
698 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)
699 }
700 },
701 {
702 &hf_tpncp_cid,
703 {
704 "Channel ID",
705 "tpncp.channel_id",
706 FT_INT32,
707 BASE_DEC,
708 NULL((void*)0),
709 0x0,
710 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)
711 }
712 }
713 };
714
715 /* Register common fields of hf_register_info structure. */
716 hf_entr.hfinfo.type = FT_NONE;
717 hf_entr.hfinfo.strings = NULL((void*)0);
718 hf_entr.hfinfo.bitmask = 0x0;
719 hf_entr.hfinfo.blurb = NULL((void*)0);
720 HFILL_INIT(hf_entr)(hf_entr).hfinfo.id = -1; (hf_entr).hfinfo.parent = 0; (hf_entr
).hfinfo.ref_type = HF_REF_TYPE_NONE; (hf_entr).hfinfo.same_name_prev_id
= -1; (hf_entr).hfinfo.same_name_next = ((void*)0);
;
721
722 if (!was_registered) {
723 void *newbuf;
724
725 /* Register non-standard data should be done only once. */
726 hf_allocated = hf_size + (int) array_length(hf_tpncp)(sizeof (hf_tpncp) / sizeof (hf_tpncp)[0]);
727 newbuf = wmem_realloc(wmem_epan_scope(), hf, hf_allocated * sizeof (hf_register_info));
728 if (!newbuf)
729 return -1;
730 hf = (hf_register_info *) newbuf;
731 for (idx = 0; idx < array_length(hf_tpncp)(sizeof (hf_tpncp) / sizeof (hf_tpncp)[0]); idx++) {
732 memcpy(hf + hf_size, hf_tpncp + idx, sizeof (hf_register_info));
733 hf_size++;
734 }
735 was_registered = true1;
736 }
737
738 is_address_family = false0;
739 ip_addr_field = 0;
740
741 data_fields_info_arr = wmem_array_new(NULL((void*)0), sizeof **data_fields_info);
742
743 /* Register standard data. */
744 while (fgetline(tpncp_db_entry, MAX_TPNCP_DB_ENTRY_LEN3000, file)) {
745 special_type = TPNCP_NORMAL;
746 since = 0;
747 snprintf(entry_copy, MAX_TPNCP_DB_ENTRY_LEN3000, "%s", tpncp_db_entry);
748 if (!strncmp(tpncp_db_entry, "#####", 5))
749 break;
750
751 /* Default to decimal display type */
752 hf_entr.hfinfo.display = BASE_DEC;
753 if ((tmp = strtok(tpncp_db_entry, " ")) == NULL((void*)0)) {
754 report_failure(
755 "ERROR! Badly formed data base entry: %s - corresponding field's registration is skipped.",
756 entry_copy);
757 continue;
758 }
759 data_id = (int) g_ascii_strtoll(tmp, NULL((void*)0), 10);
760 if ((data_id < 0) || ((name = strtok(NULL((void*)0), " ")) == NULL((void*)0))) {
761 report_failure(
762 "ERROR! Badly formed data base entry: %s - corresponding field's registration is skipped.",
763 entry_copy);
764 continue;
765 }
766
767 /* We happen to have a line without a name (57 0 32 0 0 primitive). Consider unnamed. */
768 if (g_ascii_isdigit(*name)((g_ascii_table[(guchar) (*name)] & G_ASCII_DIGIT) != 0)) {
769 tmp = name;
770 name = "unnamed";
771 } else {
772 if ((tmp = strtok(NULL((void*)0), " ")) == NULL((void*)0)) {
773 report_failure(
774 "ERROR! Badly formed data base entry: %s - corresponding field's registration is skipped.",
775 entry_copy);
776 continue;
777 }
778 }
779 if (name[0] == 'c' && !strcmp(name, "cmd_rev_lsb"))
780 special_type = TPNCP_OPEN_CHANNEL_START;
781 else if (name[0] == 'r' && !strcmp(name, "rtp_authentication_algorithm"))
782 special_type = TPNCP_SECURITY_START;
783 else if (name[0] == 's' && !strcmp(name, "security_cmd_offset"))
784 special_type = TPNCP_SECURITY_OFFSET;
785 else if (data_id != 1611 && name[0] == 's' && !strcmp(name, "ssrc"))
786 special_type = RTP_STATE_START;
787 else if (name[0] == 'r' && !strcmp(name, "rtp_tx_state_ssrc"))
788 special_type = RTP_STATE_START;
789 else if (name[0] == 'r' && !strcmp(name, "rtp_state_offset"))
790 special_type = RTP_STATE_OFFSET;
791 else if (name[0] == 's' && !strcmp(name, "state_update_time_stamp"))
792 special_type = RTP_STATE_END;
793 else if (data_id == 1611 && name[0] == 'c' && strstr(name, "configuration_type_updated"))
794 special_type = TPNCP_CHANNEL_CONFIGURATION;
795 else if ((data_id == 4 && strstr(name, "secondary_rtp_seq_num")) ||
796 (data_id == 1611 && strstr(name, "dtls_remote_fingerprint_alg"))) {
797 since = 7401;
798 }
799 sign = !!((bool_Bool) g_ascii_strtoll(tmp, NULL((void*)0), 10));
800 if ((tmp = strtok(NULL((void*)0), " ")) == NULL((void*)0)) {
801 report_failure(
802 "ERROR! Badly formed data base entry: %s - corresponding field's registration is skipped.",
803 entry_copy);
804 continue;
805 }
806 size = (unsigned char) g_ascii_strtoll(tmp, NULL((void*)0), 10);
807 if ((tmp = strtok(NULL((void*)0), " ")) == NULL((void*)0)) {
808 report_failure(
809 "ERROR! Badly formed data base entry: %s - corresponding field's registration is skipped.",
810 entry_copy);
811 continue;
812 }
813 array_dim = (int) g_ascii_strtoll(tmp, NULL((void*)0), 10);
814 if ((tmp = strtok(NULL((void*)0), " ")) == NULL((void*)0)) {
815 report_failure(
816 "ERROR! Badly formed data base entry: %s - corresponding field's registration is skipped.",
817 entry_copy);
818 continue;
819 }
820 if (sign && g_ascii_strtoll(tmp, NULL((void*)0), 10))
821 special_type = TPNCP_IP_ADDR;
822 if ((tmp = strtok(NULL((void*)0), "\n")) == NULL((void*)0)) {
823 report_failure(
824 "ERROR! Badly formed data base entry: %s - corresponding field's registration is skipped.",
825 entry_copy);
826 continue;
827 }
828
829 if (ip_addr_field > 0) {
830 // ip address that comes after address family has 4 fields: ip_addr_0, ip_addr_1, 2 and 3
831 // On these cases, ignore 1, 2 and 3 and enlarge the field size of 0 to 128
832 char *seq = (char*)name + strlen(name) - 2;
833 --ip_addr_field;
834 if (seq > name && *seq == '_') {
835 if (seq[1] >= '1' && seq[1] <= '3')
836 continue;
837 // relates to the *previous* field
838 if (is_address_family) {
839 *seq = 0;
840 size = 128;
841 special_type = TPNCP_IP_ADDR;
842 } else {
843 report_warning("Bad address form. Field name: %s", name);
844 ip_addr_field = 0;
845 }
846 }
847 }
848
849 is_address_family = false0;
850 if (current_data_id != data_id) { /* new data */
851 tpncp_data_field_info **fp;
852
853 while (wmem_array_get_count(data_fields_info_arr) <= (unsigned)data_id) {
854 static const tpncp_data_field_info **empty = NULL((void*)0);
855 wmem_array_append_one(data_fields_info_arr, empty)wmem_array_append((data_fields_info_arr), &(empty), 1);
856 }
857 fp = (tpncp_data_field_info **)wmem_array_index(data_fields_info_arr, data_id);
858 if (*fp != NULL((void*)0)) {
859 report_failure(
860 "ERROR! The data_id %d already registered. Cannot register two identical events/command",
861 data_id);
862 continue;
863 }
864 field = wmem_new0(wmem_epan_scope(), tpncp_data_field_info)((tpncp_data_field_info*)wmem_alloc0((wmem_epan_scope()), sizeof
(tpncp_data_field_info)))
;
865 *fp = field;
866 current_data_id = data_id;
867 } else {
868 field->p_next = wmem_new(wmem_epan_scope(), tpncp_data_field_info)((tpncp_data_field_info*)wmem_alloc((wmem_epan_scope()), sizeof
(tpncp_data_field_info)))
;
869 if (!field->p_next)
870 return (-1);
871 field = field->p_next;
872 field->p_next = NULL((void*)0);
873 }
874
875 /* Register specific fields of hf_register_info structure. */
876 if (strcmp(tmp, "primitive")) {
877 enum_val = get_enum_name_val(tmp);
878 if (enum_val == -1) {
879 hf_entr.hfinfo.strings = NULL((void*)0);
880 } else {
881 if (special_type == TPNCP_IP_ADDR)
882 special_type = TPNCP_NORMAL;
883 hf_entr.hfinfo.strings = VALS(tpncp_enums_id_vals[enum_val])((0 ? (const struct _value_string*)0 : ((tpncp_enums_id_vals[
enum_val]))))
;
884 if (!strcmp(tmp, "AddressFamily")) {
885 is_address_family = true1;
886 ip_addr_field = 4;
887 }
888 }
889 } else {
890 hf_entr.hfinfo.strings = NULL((void*)0);
891 }
892 field->descr = -1;
893 field->ipv6_descr = -1;
894 hf_entr.p_id = &field->descr;
895 field->name = wmem_strdup_printf(wmem_epan_scope(), "tpncp.%s", name);
896 hf_entr.hfinfo.name = field->name;
897 hf_entr.hfinfo.abbrev = field->name;
898 switch (size) {
899 case 1:
900 hf_entr.hfinfo.type = FT_BOOLEAN;
901 break;
902 case 2: case 3: case 4:
903 case 5: case 6: case 7: case 8:
904 if (array_dim) {
905 hf_entr.hfinfo.type = FT_STRING;
906 hf_entr.hfinfo.display = BASE_NONE;
907 } else {
908 hf_entr.hfinfo.type = (sign) ? FT_UINT8 : FT_INT8;
909 }
910 break;
911 case 16:
912 hf_entr.hfinfo.type = (sign) ? FT_UINT16 : FT_INT16;
913 break;
914 case 32:
915 if (special_type == TPNCP_IP_ADDR) {
916 hf_entr.hfinfo.display = BASE_NONE;
917 hf_entr.hfinfo.type = FT_IPv4;
918 } else {
919 hf_entr.hfinfo.type = (sign) ? FT_UINT32 : FT_INT32;
920 }
921 break;
922 case 64:
923 hf_entr.hfinfo.type = (sign) ? FT_UINT64 : FT_INT64;
924 break;
925 case 128:
926 if (special_type == TPNCP_IP_ADDR) {
927 hf_entr.hfinfo.display = BASE_NONE;
928 hf_entr.hfinfo.type = FT_IPv4;
929 if (!add_hf(&hf_entr))
930 return -1;
931 hf_entr.p_id = &field->ipv6_descr;
932 hf_entr.hfinfo.type = FT_IPv6;
933 }
934 break;
935 default:
936 break;
937 }
938
939 /* Register initialized hf_register_info in global database. */
940 if (!add_hf(&hf_entr))
941 return -1;
942 field->sign = sign;
943 field->size = size;
944 field->array_dim = array_dim;
945 field->special_type = is_address_family ? TPNCP_ADDRESS_FAMILY : special_type;
946 field->since = since;
947 }
948
949 *data_fields_len = wmem_array_get_count(data_fields_info_arr);
950 *data_fields_info = (tpncp_data_field_info **)wmem_array_finalize(data_fields_info_arr);
951
952 return 0;
953}
954
955/*---------------------------------------------------------------------------*/
956
957static FILE *
958open_tpncp_dat(void)
959{
960 char *path_buf = NULL((void*)0);
961 const char *tpncp_dat_file_path = tpncp_dat_path;
962 FILE *res;
963 if (!*tpncp_dat_file_path) {
964 tpncp_dat_file_path = path_buf = g_build_path(
965 G_DIR_SEPARATOR_S"/", get_datafile_dir(epan_get_environment_prefix()), "tpncp", "tpncp.dat", NULL((void*)0));
966 }
967 res = ws_fopenfopen(tpncp_dat_file_path, "r");
968 g_free(path_buf)(__builtin_object_size ((path_buf), 0) != ((size_t) - 1)) ? g_free_sized
(path_buf, __builtin_object_size ((path_buf), 0)) : (g_free)
(path_buf)
;
969 return res;
970}
971
972static int
973init_tpncp_db(void)
974{
975 /* Open file with TPNCP data. */
976 FILE *file = open_tpncp_dat();
977 if (!file
6.1
'file' is non-null
) {
7
Taking false branch
978 return (-1);
979 }
980 fill_tpncp_id_vals(&tpncp_events_id_vals, file);
8
Calling 'fill_tpncp_id_vals'
17
Returning from 'fill_tpncp_id_vals'
981 fill_tpncp_id_vals(&tpncp_commands_id_vals, file);
18
Calling 'fill_tpncp_id_vals'
982 fill_enums_id_vals(&tpncp_enums_name_vals, &tpncp_enums_id_vals, file);
983 init_tpncp_data_fields_info(&tpncp_events_info_db, &tpncp_events_info_len, file);
984 init_tpncp_data_fields_info(&tpncp_commands_info_db, &tpncp_commands_info_len, file);
985
986 fclose(file);
987 return 0;
988}
989
990/*---------------------------------------------------------------------------*/
991
992void
993proto_reg_handoff_tpncp(void)
994{
995 static bool_Bool initialized = false0;
996
997 if (proto_tpncp <= 0) return;
1
Assuming 'proto_tpncp' is > 0
2
Taking false branch
998
999 if (!initialized
2.1
'initialized' is false
) {
3
Taking true branch
1000 dissector_add_uint_with_preference("udp.port", UDP_PORT_TPNCP_TRUNKPACK2424, tpncp_handle);
1001 dissector_add_uint_with_preference("tcp.port", TCP_PORT_TPNCP_TRUNKPACK2424, tpncp_tcp_handle);
1002 dissector_add_uint("acdr.media_type", ACDR_PCIIF_COMMAND, tpncp_handle);
1003 dissector_add_uint("acdr.media_type", ACDR_COMMAND, tpncp_handle);
1004 dissector_add_uint("acdr.media_type", ACDR_Event, create_dissector_handle(dissect_acdr_event, proto_tpncp));
1005 dissector_add_uint("acdr.media_type", ACDR_TPNCP,
1006 create_dissector_handle(dissect_acdr_tpncp_by_tracepoint, proto_tpncp));
1007 dissector_add_uint("acdr.tls_application", TLS_APP_TPNCP, tpncp_handle);
1008 initialized = true1;
1009 }
1010
1011 if (!global_tpncp_load_db)
4
Assuming 'global_tpncp_load_db' is true
1012 return;
1013
1014 /* If we weren't able to load the database (and thus the hf_ entries)
1015 * do not attach to any ports (if we did then we'd get a "dissector bug"
1016 * assertions every time a packet is handed to us and we tried to use the
1017 * hf_ entry).
1018
1019 */
1020 if (hf_allocated == 0 && init_tpncp_db() == -1) {
5
Assuming 'hf_allocated' is equal to 0
6
Calling 'init_tpncp_db'
1021 report_failure("tpncp: Could not load tpncp.dat file, tpncp dissector will not work");
1022 return;
1023 }
1024
1025 if (db_initialized)
1026 return;
1027
1028 /* Rather than duplicating large quantities of code from
1029 * proto_register_field_array() and friends to sanitize the tpncp.dat file
1030 * when we read it, just catch any exceptions we get while registering and
1031 * take them as a hint that the file is corrupt. Then move on, so that at
1032 * least the rest of the protocol dissectors will still work.
1033 */
1034 TRY{ except_t *volatile exc; volatile int except_state = 0; static
const except_id_t catch_spec[] = { { 1, 0 } }; { struct except_stacknode
except_sn; struct except_catch except_ch; except_setup_try(&
except_sn, &except_ch, catch_spec, 1); if (_setjmp (except_ch
.except_jmp)) *(&exc) = &except_ch.except_obj; else *
(&exc) = 0; if(except_state & 1) except_state |= 2; except_state
&= ~1; if (except_state == 0 && exc == 0)
{
1035 int idx;
1036 /* The function proto_register_field_array does not work with dynamic
1037 * arrays, so pass dynamic array elements one-by-one in the loop.
1038 */
1039 for (idx = 0; idx < hf_size; idx++)
1040 proto_register_field_array(proto_tpncp, &hf[idx], 1);
1041 }
1042
1043 CATCH_ALLif (except_state == 0 && exc != 0 && (except_state
|=1))
{
1044 report_failure("Corrupt tpncp.dat file, tpncp dissector will not work.");
1045 }
1046
1047 ENDTRYif(!(except_state&1) && exc != 0) except_rethrow(
exc); except_free(except_ch.except_obj.except_dyndata); except_pop
(); };}
;
1048 db_initialized = true1;
1049}
1050
1051/*---------------------------------------------------------------------------*/
1052
1053void
1054proto_register_tpncp(void)
1055{
1056 module_t *tpncp_module;
1057 expert_module_t* expert_tpncp;
1058 static int *ett[] = {
1059 &ett_tpncp,
1060 &ett_tpncp_body
1061 };
1062
1063 static ei_register_info ei[] = {
1064 { &ei_tpncp_unknown_data, { "tpncp.unknown_data", PI_UNDECODED0x05000000, PI_WARN0x00600000, "Unknown data", EXPFILL0, ((void*)0), 0, ((void*)0), {0, {((void*)0), ((void*)0), FT_NONE
, BASE_NONE, ((void*)0), 0, ((void*)0), -1, 0, HF_REF_TYPE_NONE
, -1, ((void*)0)}}
} },
1065 };
1066
1067 /* this dissector reads hf entries from a database
1068 * a boolean preference defines whether the database is loaded or not
1069 * we initialize the hf array in the handoff function when we have
1070 * access to the preference's value */
1071
1072 proto_tpncp = proto_register_protocol("TPNCP (TrunkPack Network Control Protocol)",
1073 "TPNCP", "tpncp");
1074
1075 tpncp_handle = register_dissector("tpncp", dissect_tpncp, proto_tpncp);
1076 tpncp_tcp_handle = register_dissector("tpncp.tcp", dissect_tpncp_tcp, proto_tpncp);
1077
1078 tpncp_module = prefs_register_protocol(proto_tpncp, proto_reg_handoff_tpncp);
1079
1080 proto_register_subtree_array(ett, array_length(ett)(sizeof (ett) / sizeof (ett)[0]));
1081
1082 expert_tpncp = expert_register_protocol(proto_tpncp);
1083 expert_register_field_array(expert_tpncp, ei, array_length(ei)(sizeof (ei) / sizeof (ei)[0]));
1084
1085 /* See https://gitlab.com/wireshark/wireshark/-/issues/9569 for some discussion on this as well */
1086 prefs_register_bool_preference(tpncp_module, "load_db",
1087 "Whether to load DB or not; if DB not loaded dissector is passive",
1088 "Whether to load the Database or not; not loading the DB"
1089 " disables the protocol; Wireshark has to be restarted for the"
1090 " setting to take effect.",
1091 &global_tpncp_load_db);
1092 prefs_register_filename_preference(tpncp_module, "dat_file",
1093 "TPNCP data file (tpncp.dat)",
1094 "Path to tpncp.dat. If empty, the file shipped with Wireshark will be used.\n"
1095 "Changing the path requires a Wireshark restart to take effect.",
1096 &tpncp_dat_path, false0);
1097}
1098
1099/*
1100 * Editor modelines
1101 *
1102 * Local Variables:
1103 * c-basic-offset: 4
1104 * tab-width: 8
1105 * indent-tabs-mode: nil
1106 * End:
1107 *
1108 * ex: set shiftwidth=4 tabstop=8 expandtab:
1109 * :indentSize=4:tabSize=8:noTabs=true:
1110 */