### Bug Summary

File: | builds/wireshark/wireshark/epan/dissectors/packet-tpncp.c
Warning: | line 436, column 10 File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior

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