### Bug Summary

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

### Annotated Source Code

Press '?' to see keyboard shortcuts

Show analyzer invocation
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-21/lib/clang/21 -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 /usr/include/libxml2 -isystem /builds/wireshark/wireshark/epan -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-21/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../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-truncation -Wno-format-nonliteral -Wno-pointer-sign -std=gnu11 -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 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /builds/wireshark/wireshark/sbout/2025-10-24-100317-3623-1 -x c /builds/wireshark/wireshark/epan/dissectors/packet-tpncp.c

Keyboard shortcuts:

- Use 'j/k' keys for keyboard navigation
- Use 'Shift+S' to show/hide relevant lines
- Use '?' to toggle this window

Close
Show only relevant lines Show control flow arrows

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