Bug Summary

File:builds/wireshark/wireshark/epan/proto.c
Warning:line 3415, column 3
3rd function call argument is an uninitialized value

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 proto.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 -isystem /builds/wireshark/wireshark/build/epan -isystem /usr/include/mit-krb5 -isystem /usr/include/lua5.5 -isystem /usr/include/libxml2 -D CARES_NO_DEPRECATED -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D REX_API=extern -D WS_BUILD_DLL -D WS_DEBUG -D WS_DEBUG_UTF_8 -D epan_EXPORTS -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -I /builds/wireshark/wireshark/wiretap -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-11-28-100325-3662-1 -x c /builds/wireshark/wireshark/epan/proto.c
1/* proto.c
2 * Routines for protocol tree
3 *
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11#include "config.h"
12#define WS_LOG_DOMAIN"Epan" LOG_DOMAIN_EPAN"Epan"
13#include "wireshark.h"
14
15#include <float.h>
16#include <errno(*__errno_location ()).h>
17
18#include <epan/tfs.h>
19#include <epan/unit_strings.h>
20
21#include <wsutil/array.h>
22#include <wsutil/bits_ctz.h>
23#include <wsutil/bits_count_ones.h>
24#include <wsutil/sign_ext.h>
25#include <wsutil/utf8_entities.h>
26#include <wsutil/json_dumper.h>
27#include <wsutil/pint.h>
28#include <wsutil/unicode-utils.h>
29#include <wsutil/dtoa.h>
30#include <wsutil/filesystem.h>
31#ifdef HAVE_UNISTD_H1
32#include <unistd.h>
33#endif
34
35#include <ftypes/ftypes.h>
36#include <ftypes/ftypes-int.h>
37
38#include <epan/packet.h>
39#include "exceptions.h"
40#include "ptvcursor.h"
41#include "strutil.h"
42#include "addr_resolv.h"
43#include "address_types.h"
44#include "oids.h"
45#include "proto.h"
46#include "epan_dissect.h"
47#include "dfilter/dfilter.h"
48#include "tvbuff.h"
49#include "charsets.h"
50#include "column-info.h"
51#include "to_str.h"
52#include "osi-utils.h"
53#include "expert.h"
54#include "show_exception.h"
55#include "in_cksum.h"
56
57#include <wsutil/crash_info.h>
58#include <wsutil/epochs.h>
59
60static const value_string prot_group_vals[] = {
61 { PROTOCOL_GROUP_NONE, "" }, /* Not in a group - empty string */
62 { PROTOCOL_GROUP_GAMES, "Games" },
63 { PROTOCOL_GROUP_BITTORRENT, "BitTorrent" },
64 { PROTOCOL_GROUP_BLUETOOTH, "Bluetooth" },
65 { PROTOCOL_GROUP_ZIGBEE, "Zigbee " },
66
67 { 0, NULL((void*)0) },
68};
69
70/* Ptvcursor limits */
71#define SUBTREE_ONCE_ALLOCATION_NUMBER8 8
72#define SUBTREE_MAX_LEVELS256 256
73
74typedef struct __subtree_lvl {
75 unsigned cursor_offset;
76 proto_item *it;
77 proto_tree *tree;
78} subtree_lvl;
79
80struct ptvcursor {
81 wmem_allocator_t *scope;
82 subtree_lvl *pushed_tree;
83 uint8_t pushed_tree_index;
84 uint8_t pushed_tree_max;
85 proto_tree *tree;
86 tvbuff_t *tvb;
87 unsigned offset;
88};
89
90#define cVALS(x)(const value_string*)(x) (const value_string*)(x)
91
92/** See inlined comments.
93 @param tree the tree to append this item to
94 @param free_block a code block to call to free resources if this returns
95 @return NULL if 'tree' is null */
96#define CHECK_FOR_NULL_TREE_AND_FREE(tree, free_block)if (!tree) { free_block; return ((void*)0); } \
97 if (!tree) { \
98 free_block; \
99 return NULL((void*)0); \
100 }
101
102/** See inlined comments.
103 @param tree the tree to append this item to
104 @return NULL if 'tree' is null */
105#define CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); } \
106 CHECK_FOR_NULL_TREE_AND_FREE(tree, ((void)0))if (!tree) { ((void)0); return ((void*)0); }
107
108/** See inlined comments.
109 @param length the length of this item
110 @param cleanup_block a code block to call to free resources if this returns
111 @return NULL if 'length' is equal to 0 */
112#define CHECK_FOR_ZERO_LENGTH_AND_CLEANUP(length, cleanup_block)if (length == 0) { cleanup_block; return ((void*)0); } \
113 if (length == 0) { \
114 cleanup_block; \
115 return NULL((void*)0); \
116 }
117
118/** See inlined comments.
119 @param length the length of this item
120 @return NULL if 'length' is equal to 0 */
121#define CHECK_FOR_ZERO_LENGTH(length)if (length == 0) { ((void)0); return ((void*)0); } \
122 CHECK_FOR_ZERO_LENGTH_AND_CLEANUP(length, ((void)0))if (length == 0) { ((void)0); return ((void*)0); }
123
124/** See inlined comments.
125 @param tree the tree to append this item to
126 @param hfindex field index
127 @param hfinfo header_field
128 @param free_block a code block to call to free resources if this returns
129 @return the header field matching 'hfinfo' */
130#define TRY_TO_FAKE_THIS_ITEM_OR_FREE(tree, hfindex, hfinfo, free_block)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 130
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 130, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 130, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { free_block; if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 130, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { free_block; return proto_tree_add_fake_node(tree, hfinfo
); } } }
\
131 /* If the tree is not visible and this item is not referenced \
132 we don't have to do much work at all but we should still \
133 return a node so that referenced field items below this node \
134 (think proto_item_add_subtree()) will still have somewhere \
135 to attach to or else filtering will not work (they would be \
136 ignored since tree would be NULL). \
137 DON'T try to fake a node where PTREE_FINFO(tree) is visible \
138 because that means we can change its length or repr, and we \
139 don't want to do so with calls intended for this faked new \
140 item, so this item needs a new (hidden) child node. \
141 We fake FT_PROTOCOL unless some clients have requested us \
142 not to do so. \
143 */ \
144 PTREE_DATA(tree)((tree)->tree_data)->count++; \
145 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 145, __func__, "Unregistered hf! index=%d",
hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 145, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 145, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
; \
146 if (PTREE_DATA(tree)((tree)->tree_data)->count > prefs.gui_max_tree_items) { \
147 free_block; \
148 if (wireshark_abort_on_too_many_items) \
149 ws_error("Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)", \ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 150
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items)
150 hfinfo->abbrev, prefs.gui_max_tree_items)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 150
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items)
; \
151 /* Let the exception handler add items to the tree */ \
152 PTREE_DATA(tree)((tree)->tree_data)->count = 0; \
153 THROW_MESSAGE(DissectorError, \except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items)))
154 wmem_strdup_printf(PNODE_POOL(tree), \except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items)))
155 "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)", \except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items)))
156 hfinfo->abbrev, prefs.gui_max_tree_items))except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items)))
; \
157 } \
158 if (!(PTREE_DATA(tree)((tree)->tree_data)->visible)) { \
159 if (PROTO_ITEM_IS_HIDDEN(tree)proto_item_is_hidden((tree))) { \
160 if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) \
161 && (hfinfo->ref_type != HF_REF_TYPE_PRINT) \
162 && (hfinfo->type != FT_PROTOCOL || \
163 PTREE_DATA(tree)((tree)->tree_data)->fake_protocols)) { \
164 free_block; \
165 /* return fake node with no field info */\
166 return proto_tree_add_fake_node(tree, hfinfo); \
167 } \
168 } \
169 }
170
171/** See inlined comments.
172 @param tree the tree to append this item to
173 @param hfindex field index
174 @param hfinfo header_field
175 @return the header field matching 'hfinfo' */
176#define TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 176
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 176, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 176, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 176, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
\
177 TRY_TO_FAKE_THIS_ITEM_OR_FREE(tree, hfindex, hfinfo, ((void)0))((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 177
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 177, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 177, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 177, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
178
179
180/** See inlined comments.
181 @param pi the created protocol item we're about to return */
182#define TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 182, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
\
183 ws_assert(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 183, __func__, "assertion failed: %s", "pi"
); } while (0)
; \
184 if (!PITEM_FINFO(pi)((pi)->finfo)) \
185 return pi; \
186 if (!(PTREE_DATA(pi)((pi)->tree_data)->visible) && \
187 PROTO_ITEM_IS_HIDDEN(pi)proto_item_is_hidden((pi))) { \
188 /* If the tree (GUI) or item isn't visible it's pointless for \
189 * us to generate the protocol item's string representation */ \
190 return pi; \
191 }
192/* Same as above but returning void */
193#define TRY_TO_FAKE_THIS_REPR_VOID(pi)if (!pi || !((pi)->finfo)) return; if (!(((pi)->tree_data
)->visible) && proto_item_is_hidden((pi))) { return
; }
\
194 if (!pi || !PITEM_FINFO(pi)((pi)->finfo)) \
195 return; \
196 if (!(PTREE_DATA(pi)((pi)->tree_data)->visible) && \
197 PROTO_ITEM_IS_HIDDEN(pi)proto_item_is_hidden((pi))) { \
198 /* If the tree (GUI) or item isn't visible it's pointless for \
199 * us to generate the protocol item's string representation */ \
200 return; \
201 }
202/* Similar to above, but allows a NULL tree */
203#define TRY_TO_FAKE_THIS_REPR_NESTED(pi)if ((pi == ((void*)0)) || (((pi)->finfo) == ((void*)0)) ||
(!(((pi)->tree_data)->visible) && proto_item_is_hidden
((pi)))) { return pi; }
\
204 if ((pi == NULL((void*)0)) || (PITEM_FINFO(pi)((pi)->finfo) == NULL((void*)0)) || (!(PTREE_DATA(pi)((pi)->tree_data)->visible) && \
205 PROTO_ITEM_IS_HIDDEN(pi)proto_item_is_hidden((pi)))) { \
206 /* If the tree (GUI) or item isn't visible it's pointless for \
207 * us to generate the protocol item's string representation */ \
208 return pi; \
209 }
210
211#ifdef ENABLE_CHECK_FILTER
212#define CHECK_HF_VALUE(type, spec, start_values) \
213{ \
214 const type *current; \
215 int n, m; \
216 current = start_values; \
217 for (n=0; current; n++, current++) { \
218 /* Drop out if we reached the end. */ \
219 if ((current->value == 0) && (current->strptr == NULL((void*)0))) { \
220 break; \
221 } \
222 /* Check value against all previous */ \
223 for (m=0; m < n; m++) { \
224 /* There are lots of duplicates with the same string, \
225 so only report if different... */ \
226 if ((start_values[m].value == current->value) && \
227 (strcmp(start_values[m].strptr, current->strptr) != 0)) { \
228 ws_error("Field '%s' (%s) has a conflicting entry in its" \ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 231
, __func__, "Field '%s' (%s) has a conflicting entry in its" " value_string: %"
spec " is at indices %u (%s) and %u (%s)", hfinfo->name, hfinfo
->abbrev, current->value, m, start_values[m].strptr, n,
current->strptr)
229 " value_string: %" spec " is at indices %u (%s) and %u (%s)", \ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 231
, __func__, "Field '%s' (%s) has a conflicting entry in its" " value_string: %"
spec " is at indices %u (%s) and %u (%s)", hfinfo->name, hfinfo
->abbrev, current->value, m, start_values[m].strptr, n,
current->strptr)
230 hfinfo->name, hfinfo->abbrev, \ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 231
, __func__, "Field '%s' (%s) has a conflicting entry in its" " value_string: %"
spec " is at indices %u (%s) and %u (%s)", hfinfo->name, hfinfo
->abbrev, current->value, m, start_values[m].strptr, n,
current->strptr)
231 current->value, m, start_values[m].strptr, n, current->strptr)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 231
, __func__, "Field '%s' (%s) has a conflicting entry in its" " value_string: %"
spec " is at indices %u (%s) and %u (%s)", hfinfo->name, hfinfo
->abbrev, current->value, m, start_values[m].strptr, n,
current->strptr)
; \
232 } \
233 } \
234 } \
235}
236#endif
237
238/* The longest NUMBER-like field label we have is for BASE_OUI, which
239 * can have up to 64 bytes for the manufacturer name if resolved plus
240 * 11 bytes for the "XX:XX:XX ()" part = 75 octets.
241 */
242#define NUMBER_LABEL_LENGTH80 80
243
244static const char *hf_try_val_to_str(uint32_t value, const header_field_info *hfinfo);
245static const char *hf_try_val64_to_str(uint64_t value, const header_field_info *hfinfo);
246static const char *hf_try_val_to_str_const(uint32_t value, const header_field_info *hfinfo, const char *unknown_str);
247static const char *hf_try_val64_to_str_const(uint64_t value, const header_field_info *hfinfo, const char *unknown_str);
248static int hfinfo_bitoffset(const header_field_info *hfinfo);
249static int hfinfo_mask_bitwidth(const header_field_info *hfinfo);
250static int hfinfo_container_bitwidth(const header_field_info *hfinfo);
251
252#define label_concat(dst, pos, src)ws_label_strcpy(dst, 240, pos, src, 0) \
253 ws_label_strcpy(dst, ITEM_LABEL_LENGTH240, pos, src, 0)
254
255static void mark_truncated(char *label_str, size_t name_pos, const size_t size, size_t *value_pos);
256static void label_mark_truncated(char *label_str, size_t name_pos, size_t *value_pos);
257
258static void fill_label_boolean(const field_info *fi, char *label_str, size_t *value_pos);
259static void fill_label_bitfield_char(const field_info *fi, char *label_str, size_t *value_pos);
260static void fill_label_bitfield(const field_info *fi, char *label_str, size_t *value_pos, bool_Bool is_signed);
261static void fill_label_bitfield64(const field_info *fi, char *label_str, size_t *value_pos, bool_Bool is_signed);
262static void fill_label_char(const field_info *fi, char *label_str, size_t *value_pos);
263static void fill_label_number(const field_info *fi, char *label_str, size_t *value_pos, bool_Bool is_signed);
264static void fill_label_number64(const field_info *fi, char *label_str, size_t *value_pos, bool_Bool is_signed);
265
266static size_t fill_display_label_float(const field_info *fi, char *label_str, const int label_str_size);
267static void fill_label_float(const field_info *fi, char *label_str, size_t *value_pos);
268static size_t fill_display_label_ieee_11073_float(const field_info *fi, char *label_str, const int label_str_size);
269static void fill_label_ieee_11073_float(const field_info *fi, char *label_str, size_t *value_pos);
270
271static const char *hfinfo_number_value_format_display(const header_field_info *hfinfo, int display, char buf[NUMBER_LABEL_LENGTH80], uint32_t value);
272static const char *hfinfo_number_value_format_display64(const header_field_info *hfinfo, int display, char buf[NUMBER_LABEL_LENGTH80], uint64_t value);
273static const char *hfinfo_char_vals_format(const header_field_info *hfinfo, char buf[32], uint32_t value);
274static const char* hfinfo_char_value_format_display(int display, char buf[7], uint32_t value);
275static const char *hfinfo_number_vals_format(const header_field_info *hfinfo, char buf[NUMBER_LABEL_LENGTH80], uint32_t value);
276static const char *hfinfo_number_vals_format64(const header_field_info *hfinfo, char buf[NUMBER_LABEL_LENGTH80], uint64_t value);
277static const char *hfinfo_number_value_format(const header_field_info *hfinfo, char buf[NUMBER_LABEL_LENGTH80], uint32_t value);
278static const char *hfinfo_number_value_format64(const header_field_info *hfinfo, char buf[NUMBER_LABEL_LENGTH80], uint64_t value);
279static const char *hfinfo_char_value_format(const header_field_info *hfinfo, char buf[32], uint32_t value);
280static const char *hfinfo_numeric_value_format(const header_field_info *hfinfo, char buf[NUMBER_LABEL_LENGTH80], uint32_t value);
281static const char *hfinfo_numeric_value_format64(const header_field_info *hfinfo, char buf[NUMBER_LABEL_LENGTH80], uint64_t value);
282
283static void proto_cleanup_base(void);
284
285static proto_item *
286proto_tree_add_node(proto_tree *tree, field_info *fi);
287
288static proto_item *
289proto_tree_add_fake_node(proto_tree *tree, const header_field_info *hfinfo);
290
291static void
292get_hfi_length(header_field_info *hfinfo, tvbuff_t *tvb, const unsigned start, int *length,
293 int *item_length, const unsigned encoding);
294
295static void
296get_hfi_length_unsigned(header_field_info * hfinfo, tvbuff_t * tvb, const unsigned start, unsigned* length,
297 unsigned* item_length, const unsigned encoding);
298
299static int
300get_full_length(header_field_info *hfinfo, tvbuff_t *tvb, const unsigned start,
301 int length, unsigned item_length, const int encoding);
302
303static field_info *
304new_field_info(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
305 const unsigned start, const int item_length);
306
307static proto_item *
308proto_tree_add_pi(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
309 unsigned start, int *length);
310
311static proto_item *
312proto_tree_add_pi_unsigned(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
313 unsigned start, unsigned *length);
314
315static void
316proto_tree_set_representation_value(proto_item *pi, const char *format, va_list ap);
317static void
318proto_tree_set_representation(proto_item *pi, const char *format, va_list ap);
319
320static void
321proto_tree_set_protocol_tvb(field_info *fi, tvbuff_t *tvb, const char* field_data, int length);
322static void
323proto_tree_set_bytes(field_info *fi, const uint8_t* start_ptr, int length);
324static void
325proto_tree_set_bytes_tvb(field_info *fi, tvbuff_t *tvb, unsigned offset, int length);
326static void
327proto_tree_set_bytes_gbytearray(field_info *fi, const GByteArray *value);
328static void
329proto_tree_set_time(field_info *fi, const nstime_t *value_ptr);
330static void
331proto_tree_set_string(field_info *fi, const char* value);
332static void
333proto_tree_set_ax25(field_info *fi, const uint8_t* value);
334static void
335proto_tree_set_ax25_tvb(field_info *fi, tvbuff_t *tvb, unsigned start);
336static void
337proto_tree_set_vines(field_info *fi, const uint8_t* value);
338static void
339proto_tree_set_vines_tvb(field_info *fi, tvbuff_t *tvb, unsigned start);
340static void
341proto_tree_set_ether(field_info *fi, const uint8_t* value);
342static void
343proto_tree_set_ether_tvb(field_info *fi, tvbuff_t *tvb, unsigned start);
344static void
345proto_tree_set_ipxnet(field_info *fi, uint32_t value);
346static void
347proto_tree_set_ipv4(field_info *fi, ws_in4_addr value);
348static void
349proto_tree_set_ipv6(field_info *fi, const ws_in6_addr* value);
350static void
351proto_tree_set_ipv6_tvb(field_info *fi, tvbuff_t *tvb, unsigned start, unsigned length);
352static void
353proto_tree_set_fcwwn_tvb(field_info *fi, tvbuff_t *tvb, unsigned start, unsigned length);
354static void
355proto_tree_set_guid(field_info *fi, const e_guid_t *value_ptr);
356static void
357proto_tree_set_guid_tvb(field_info *fi, tvbuff_t *tvb, unsigned start, const unsigned encoding);
358static void
359proto_tree_set_oid(field_info *fi, const uint8_t* value_ptr, unsigned length);
360static void
361proto_tree_set_oid_tvb(field_info *fi, tvbuff_t *tvb, unsigned start, unsigned length);
362static void
363proto_tree_set_system_id(field_info *fi, const uint8_t* value_ptr, unsigned length);
364static void
365proto_tree_set_system_id_tvb(field_info *fi, tvbuff_t *tvb, unsigned start, unsigned length);
366static void
367proto_tree_set_boolean(field_info *fi, uint64_t value);
368static void
369proto_tree_set_float(field_info *fi, float value);
370static void
371proto_tree_set_double(field_info *fi, double value);
372static void
373proto_tree_set_uint(field_info *fi, uint32_t value);
374static void
375proto_tree_set_int(field_info *fi, int32_t value);
376static void
377proto_tree_set_uint64(field_info *fi, uint64_t value);
378static void
379proto_tree_set_int64(field_info *fi, int64_t value);
380static void
381proto_tree_set_eui64(field_info *fi, const uint64_t value);
382static void
383proto_tree_set_eui64_tvb(field_info *fi, tvbuff_t *tvb, unsigned start, const unsigned encoding);
384
385/* Handle type length mismatch (now filterable) expert info */
386static int proto_type_length_mismatch;
387static expert_field ei_type_length_mismatch_error;
388static expert_field ei_type_length_mismatch_warn;
389static void register_type_length_mismatch(void);
390
391/* Handle byte array string decoding errors with expert info */
392static int proto_byte_array_string_decoding_error;
393static expert_field ei_byte_array_string_decoding_failed_error;
394static void register_byte_array_string_decodinws_error(void);
395
396/* Handle date and time string decoding errors with expert info */
397static int proto_date_time_string_decoding_error;
398static expert_field ei_date_time_string_decoding_failed_error;
399static void register_date_time_string_decodinws_error(void);
400
401/* Handle string errors expert info */
402static int proto_string_errors;
403static expert_field ei_string_trailing_characters;
404static void register_string_errors(void);
405
406/* Handle varint errors expert info */
407static int proto_varint_errors;
408static expert_field ei_varint_decoding_failed_error;
409static void register_varint_errors(void);
410
411static int proto_register_field_init(header_field_info *hfinfo, const int parent);
412
413/* special-case header field used within proto.c */
414static header_field_info hfi_text_only =
415 { "Text item", "text", FT_NONE, BASE_NONE, NULL((void*)0), 0x0, NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) };
416int hf_text_only;
417
418/** Structure for information about a protocol */
419struct _protocol {
420 const char *name; /**< long description */
421 const char *short_name; /**< short description */
422 const char *filter_name; /**< name of this protocol in filters */
423 GPtrArray *fields; /**< fields for this protocol */
424 int proto_id; /**< field ID for this protocol */
425 bool_Bool is_enabled; /**< true if protocol is enabled */
426 bool_Bool enabled_by_default; /**< true if protocol is enabled by default */
427 bool_Bool can_toggle; /**< true if is_enabled can be changed */
428 int parent_proto_id; /**< Used to identify "pino"s (Protocol In Name Only).
429 For dissectors that need a protocol name so they
430 can be added to a dissector table, but use the
431 parent_proto_id for things like enable/disable */
432 GList *heur_list; /**< Heuristic dissectors associated with this protocol */
433};
434
435/* List of all protocols */
436static GList *protocols;
437
438/* Structure stored for deregistered g_slice */
439struct g_slice_data {
440 size_t block_size;
441 void *mem_block;
442};
443
444/* Deregistered fields */
445static GPtrArray *deregistered_fields;
446static GPtrArray *deregistered_data;
447static GPtrArray *deregistered_slice;
448
449/* indexed by prefix, contains initializers */
450static GHashTable* prefixes;
451
452/* Contains information about a field when a dissector calls
453 * proto_tree_add_item. */
454#define FIELD_INFO_NEW(pool, fi)fi = ((field_info*)wmem_alloc((pool), sizeof(field_info))) fi = wmem_new(pool, field_info)((field_info*)wmem_alloc((pool), sizeof(field_info)))
455#define FIELD_INFO_FREE(pool, fi)wmem_free(pool, fi) wmem_free(pool, fi)
456
457/* Contains the space for proto_nodes. */
458#define PROTO_NODE_INIT(node)node->first_child = ((void*)0); node->last_child = ((void
*)0); node->next = ((void*)0);
\
459 node->first_child = NULL((void*)0); \
460 node->last_child = NULL((void*)0); \
461 node->next = NULL((void*)0);
462
463#define PROTO_NODE_FREE(pool, node)wmem_free(pool, node) \
464 wmem_free(pool, node)
465
466/* String space for protocol and field items for the GUI */
467#define ITEM_LABEL_NEW(pool, il)il = ((item_label_t*)wmem_alloc((pool), sizeof(item_label_t))
); il->value_pos = 0; il->value_len = 0;
\
468 il = wmem_new(pool, item_label_t)((item_label_t*)wmem_alloc((pool), sizeof(item_label_t))); \
469 il->value_pos = 0; \
470 il->value_len = 0;
471#define ITEM_LABEL_FREE(pool, il)wmem_free(pool, il); \
472 wmem_free(pool, il);
473
474#define PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 474, __func__, "Unregistered hf! index=%d",
hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 474, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 474, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
\
475 if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug) \
476 ws_error("Unregistered hf! index=%d", hfindex)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 476
, __func__, "Unregistered hf! index=%d", hfindex)
; \
477 DISSECTOR_ASSERT_HINT(hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len, "Unregistered hf.")((void) ((hfindex > 0 && (unsigned)hfindex < gpa_hfinfo
.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 477, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf."))))
; \
478 DISSECTOR_ASSERT_HINT(gpa_hfinfo.hfi[hfindex] != NULL, "Unregistered hf.")((void) ((gpa_hfinfo.hfi[hfindex] != ((void*)0)) ? (void)0 : (
proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 478, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf."))))
; \
479 hfinfo = gpa_hfinfo.hfi[hfindex];
480
481#define PROTO_PRE_ALLOC_HF_FIELDS_MEM(300000+5000) (300000+PRE_ALLOC_EXPERT_FIELDS_MEM5000)
482
483/* List which stores protocols and fields that have been registered */
484typedef struct _gpa_hfinfo_t {
485 uint32_t len;
486 uint32_t allocated_len;
487 header_field_info **hfi;
488} gpa_hfinfo_t;
489
490static gpa_hfinfo_t gpa_hfinfo;
491
492/* Hash table of abbreviations and IDs */
493static wmem_map_t *gpa_name_map;
494static header_field_info *same_name_hfinfo;
495
496/* Hash table protocol aliases. const char * -> const char * */
497static GHashTable *gpa_protocol_aliases;
498
499/*
500 * We're called repeatedly with the same field name when sorting a column.
501 * Cache our last gpa_name_map hit for faster lookups.
502 */
503static char *last_field_name;
504static header_field_info *last_hfinfo;
505
506/* Points to the first element of an array of bits, indexed by
507 a subtree item type; that array element is true if subtrees of
508 an item of that type are to be expanded. */
509static uint32_t *tree_is_expanded;
510
511/* Number of elements in that array. The entry with index 0 is not used. */
512int num_tree_types = 1;
513
514/* Name hashtables for fast detection of duplicate names */
515static GHashTable* proto_names;
516static GHashTable* proto_short_names;
517static GHashTable* proto_filter_names;
518
519static const char * const reserved_filter_names[] = {
520 /* Display filter keywords. */
521 "eq",
522 "ne",
523 "all_eq",
524 "any_eq",
525 "all_ne",
526 "any_ne",
527 "gt",
528 "ge",
529 "lt",
530 "le",
531 "bitand",
532 "bitwise_and",
533 "contains",
534 "matches",
535 "not",
536 "and",
537 "or",
538 "xor",
539 "in",
540 "any",
541 "all",
542 "true",
543 "false",
544 "nan",
545 "inf",
546 "infinity",
547 NULL((void*)0)
548};
549
550static GHashTable *proto_reserved_filter_names;
551static GQueue* saved_dir_queue;
552
553static gboolean
554proto_strcase_equal(const void* name1, const void* name2)
555{
556 const char* s1 = (const char*)name1;
557 const char* s2 = (const char*)name2;
558
559 return g_ascii_strcasecmp(s1, s2) == 0 ? TRUE(!(0)) : FALSE(0);
560}
561
562static int
563proto_compare_name(const void *p1_arg, const void *p2_arg)
564{
565 const protocol_t *p1 = (const protocol_t *)p1_arg;
566 const protocol_t *p2 = (const protocol_t *)p2_arg;
567
568 return g_ascii_strcasecmp(p1->short_name, p2->short_name);
569}
570
571static GSList *dissector_plugins;
572
573#ifdef HAVE_PLUGINS1
574void
575proto_register_plugin(const proto_plugin *plug)
576{
577 dissector_plugins = g_slist_prepend(dissector_plugins, (proto_plugin *)plug);
578}
579#else /* HAVE_PLUGINS */
580void
581proto_register_plugin(const proto_plugin *plug _U___attribute__((unused)))
582{
583 ws_warning("proto_register_plugin: built without support for binary plugins")do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 583, __func__, "proto_register_plugin: built without support for binary plugins"
); } } while (0)
;
584}
585#endif /* HAVE_PLUGINS */
586
587static void
588call_plugin_register_protoinfo(void *data, void *user_data _U___attribute__((unused)))
589{
590 proto_plugin *plug = (proto_plugin *)data;
591
592 if (plug->register_protoinfo) {
593 plug->register_protoinfo();
594 }
595}
596
597static void
598call_plugin_register_handoff(void *data, void *user_data _U___attribute__((unused)))
599{
600 proto_plugin *plug = (proto_plugin *)data;
601
602 if (plug->register_handoff) {
603 plug->register_handoff();
604 }
605}
606
607void proto_pre_init(void)
608{
609 saved_dir_queue = g_queue_new();
610
611 proto_names = g_hash_table_new(wmem_str_hash, g_str_equal);
612 proto_short_names = g_hash_table_new(wmem_str_hash, g_str_equal);
613 proto_filter_names = g_hash_table_new(wmem_str_hash, g_str_equal);
614
615 proto_reserved_filter_names = g_hash_table_new(wmem_str_hash, proto_strcase_equal);
616 for (const char* const * ptr = reserved_filter_names; *ptr != NULL((void*)0); ptr++) {
617 /* GHashTable has no key destructor so the cast is safe. */
618 g_hash_table_add(proto_reserved_filter_names, *(char**)ptr);
619 }
620
621 gpa_hfinfo.len = 0;
622 gpa_hfinfo.allocated_len = 0;
623 gpa_hfinfo.hfi = NULL((void*)0);
624 gpa_name_map = wmem_map_new(wmem_epan_scope(), wmem_str_hash, g_str_equal);
625 wmem_map_reserve(gpa_name_map, PROTO_PRE_ALLOC_HF_FIELDS_MEM(300000+5000));
626 gpa_protocol_aliases = g_hash_table_new(wmem_str_hash, g_str_equal);
627 deregistered_fields = g_ptr_array_new();
628 deregistered_data = g_ptr_array_new();
629 deregistered_slice = g_ptr_array_new();
630}
631
632/* initialize data structures and register protocols and fields */
633void
634proto_init(GSList *register_all_plugin_protocols_list,
635 GSList *register_all_plugin_handoffs_list,
636 register_entity_func register_func, register_entity_func handoff_func,
637 register_cb cb,
638 void *client_data)
639{
640 /* Initialize the ftype subsystem */
641 ftypes_initialize();
642
643 /* Initialize the address type subsystem */
644 address_types_initialize();
645
646 /* Register one special-case FT_TEXT_ONLY field for use when
647 converting wireshark to new-style proto_tree. These fields
648 are merely strings on the GUI tree; they are not filterable */
649 hf_text_only = proto_register_field_init(&hfi_text_only, -1);
650
651 /* Register the pseudo-protocols used for exceptions. */
652 register_show_exception();
653 register_type_length_mismatch();
654 register_byte_array_string_decodinws_error();
655 register_date_time_string_decodinws_error();
656 register_string_errors();
657 register_varint_errors();
658 ftypes_register_pseudofields();
659 col_register_protocol();
660
661 /* Have each built-in dissector register its protocols, fields,
662 dissector tables, and dissectors to be called through a
663 handle, and do whatever one-time initialization it needs to
664 do. */
665 if (register_func != NULL((void*)0))
666 register_func(cb, client_data);
667
668 /* Now call the registration routines for all epan plugins. */
669 for (GSList *l = register_all_plugin_protocols_list; l != NULL((void*)0); l = l->next) {
670 ((void (*)(register_cb, void *))l->data)(cb, client_data);
671 }
672
673 /* Now call the registration routines for all dissector plugins. */
674 if (cb)
675 (*cb)(RA_PLUGIN_REGISTER, NULL((void*)0), client_data);
676 g_slist_foreach(dissector_plugins, call_plugin_register_protoinfo, NULL((void*)0));
677
678 /* Now call the "handoff registration" routines of all built-in
679 dissectors; those routines register the dissector in other
680 dissectors' handoff tables, and fetch any dissector handles
681 they need. */
682 if (handoff_func != NULL((void*)0))
683 handoff_func(cb, client_data);
684
685 /* Now do the same with epan plugins. */
686 for (GSList *l = register_all_plugin_handoffs_list; l != NULL((void*)0); l = l->next) {
687 ((void (*)(register_cb, void *))l->data)(cb, client_data);
688 }
689
690 /* Now do the same with dissector plugins. */
691 if (cb)
692 (*cb)(RA_PLUGIN_HANDOFF, NULL((void*)0), client_data);
693 g_slist_foreach(dissector_plugins, call_plugin_register_handoff, NULL((void*)0));
694
695 /* sort the protocols by protocol name */
696 protocols = g_list_sort(protocols, proto_compare_name);
697
698 /* sort the dissector handles in dissector tables (for -G reports
699 * and -d error messages. The GUI sorts the handles itself.) */
700 packet_all_tables_sort_handles();
701
702 /* We've assigned all the subtree type values; allocate the array
703 for them, and zero it out. */
704 tree_is_expanded = g_new0(uint32_t, (num_tree_types/32)+1)((uint32_t *) g_malloc0_n (((num_tree_types/32)+1), sizeof (uint32_t
)))
;
705}
706
707static void
708proto_cleanup_base(void)
709{
710 protocol_t *protocol;
711 header_field_info *hfinfo;
712
713 /* Free the abbrev/ID hash table */
714 if (gpa_name_map) {
715 // XXX - We don't have a wmem_map_destroy, but
716 // it does get cleaned up when epan scope is
717 // destroyed
718 //g_hash_table_destroy(gpa_name_map);
719 gpa_name_map = NULL((void*)0);
720 }
721 if (gpa_protocol_aliases) {
722 g_hash_table_destroy(gpa_protocol_aliases);
723 gpa_protocol_aliases = NULL((void*)0);
724 }
725 g_free(last_field_name)(__builtin_object_size ((last_field_name), 0) != ((size_t) - 1
)) ? g_free_sized (last_field_name, __builtin_object_size ((last_field_name
), 0)) : (g_free) (last_field_name)
;
726 last_field_name = NULL((void*)0);
727
728 while (protocols) {
729 protocol = (protocol_t *)protocols->data;
730 PROTO_REGISTRAR_GET_NTH(protocol->proto_id, hfinfo)if((protocol->proto_id == 0 || (unsigned)protocol->proto_id
> gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 730
, __func__, "Unregistered hf! index=%d", protocol->proto_id
); ((void) ((protocol->proto_id > 0 && (unsigned
)protocol->proto_id < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 730, "protocol->proto_id > 0 && (unsigned)protocol->proto_id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[protocol->
proto_id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 730, "gpa_hfinfo.hfi[protocol->proto_id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[protocol->
proto_id];
;
731 DISSECTOR_ASSERT(protocol->proto_id == hfinfo->id)((void) ((protocol->proto_id == hfinfo->id) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 731, "protocol->proto_id == hfinfo->id"
))))
;
732
733 g_slice_free(header_field_info, hfinfo)do { if (1) g_slice_free1 (sizeof (header_field_info), (hfinfo
)); else (void) ((header_field_info*) 0 == (hfinfo)); } while
(0)
;
734 if (protocol->parent_proto_id != -1) {
735 // pino protocol
736 DISSECTOR_ASSERT(protocol->fields == NULL)((void) ((protocol->fields == ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 736, "protocol->fields == ((void*)0)"
))))
; //helpers should not have any registered fields
737 DISSECTOR_ASSERT(protocol->heur_list == NULL)((void) ((protocol->heur_list == ((void*)0)) ? (void)0 : (
proto_report_dissector_bug("%s:%u: failed assertion \"%s\"", "epan/proto.c"
, 737, "protocol->heur_list == ((void*)0)"))))
; //helpers should not have a heuristic list
738 } else {
739 if (protocol->fields) {
740 g_ptr_array_free(protocol->fields, true1);
741 }
742 g_list_free(protocol->heur_list);
743 }
744 protocols = g_list_remove(protocols, protocol);
745 g_free(protocol)(__builtin_object_size ((protocol), 0) != ((size_t) - 1)) ? g_free_sized
(protocol, __builtin_object_size ((protocol), 0)) : (g_free)
(protocol)
;
746 }
747
748 if (proto_names) {
749 g_hash_table_destroy(proto_names);
750 proto_names = NULL((void*)0);
751 }
752
753 if (proto_short_names) {
754 g_hash_table_destroy(proto_short_names);
755 proto_short_names = NULL((void*)0);
756 }
757
758 if (proto_filter_names) {
759 g_hash_table_destroy(proto_filter_names);
760 proto_filter_names = NULL((void*)0);
761 }
762
763 if (proto_reserved_filter_names) {
764 g_hash_table_destroy(proto_reserved_filter_names);
765 proto_reserved_filter_names = NULL((void*)0);
766 }
767
768 if (gpa_hfinfo.allocated_len) {
769 gpa_hfinfo.len = 0;
770 gpa_hfinfo.allocated_len = 0;
771 g_free(gpa_hfinfo.hfi)(__builtin_object_size ((gpa_hfinfo.hfi), 0) != ((size_t) - 1
)) ? g_free_sized (gpa_hfinfo.hfi, __builtin_object_size ((gpa_hfinfo
.hfi), 0)) : (g_free) (gpa_hfinfo.hfi)
;
772 gpa_hfinfo.hfi = NULL((void*)0);
773 }
774
775 if (deregistered_fields) {
776 g_ptr_array_free(deregistered_fields, true1);
777 deregistered_fields = NULL((void*)0);
778 }
779
780 if (deregistered_data) {
781 g_ptr_array_free(deregistered_data, true1);
782 deregistered_data = NULL((void*)0);
783 }
784
785 if (deregistered_slice) {
786 g_ptr_array_free(deregistered_slice, true1);
787 deregistered_slice = NULL((void*)0);
788 }
789
790 g_free(tree_is_expanded)(__builtin_object_size ((tree_is_expanded), 0) != ((size_t) -
1)) ? g_free_sized (tree_is_expanded, __builtin_object_size (
(tree_is_expanded), 0)) : (g_free) (tree_is_expanded)
;
791 tree_is_expanded = NULL((void*)0);
792
793 if (prefixes)
794 g_hash_table_destroy(prefixes);
795
796 if (saved_dir_queue != NULL((void*)0)) {
797 g_queue_clear_full(saved_dir_queue, g_free);
798 g_queue_free(saved_dir_queue);
799 saved_dir_queue = NULL((void*)0);
800 }
801}
802
803void
804proto_cleanup(void)
805{
806 proto_free_deregistered_fields();
807 proto_cleanup_base();
808
809 g_slist_free(dissector_plugins);
810 dissector_plugins = NULL((void*)0);
811}
812
813static bool_Bool
814ws_pushd(const char* dir)
815{
816 //Save the current working directory
817 const char* save_wd = get_current_working_dir();
818 if (save_wd != NULL((void*)0))
819 g_queue_push_head(saved_dir_queue, g_strdup(save_wd)g_strdup_inline (save_wd));
820
821 //Change to the new one
822#ifdef _WIN32
823 SetCurrentDirectory(utf_8to16(dir));
824 return true1;
825#else
826 return (chdir(dir) == 0);
827#endif
828}
829
830static bool_Bool
831ws_popd(void)
832{
833 int ret = 0;
834 char* saved_wd = g_queue_pop_head(saved_dir_queue);
835 if (saved_wd == NULL((void*)0))
836 return false0;
837
838 //Restore the previous one
839#ifdef _WIN32
840 SetCurrentDirectory(utf_8to16(saved_wd));
841#else
842 ret = chdir(saved_wd);
843#endif
844 g_free(saved_wd)(__builtin_object_size ((saved_wd), 0) != ((size_t) - 1)) ? g_free_sized
(saved_wd, __builtin_object_size ((saved_wd), 0)) : (g_free)
(saved_wd)
;
845 return (ret == 0);
846}
847
848void
849proto_execute_in_directory(const char* dir, proto_execute_in_directory_func func, void* param)
850{
851 if (ws_pushd(dir))
852 {
853 func(param);
854 ws_popd();
855 }
856}
857
858static bool_Bool
859// NOLINTNEXTLINE(misc-no-recursion)
860proto_tree_traverse_pre_order(proto_tree *tree, proto_tree_traverse_func func,
861 void *data)
862{
863 proto_node *pnode = tree;
864 proto_node *child;
865 proto_node *current;
866
867 if (func(pnode, data))
868 return true1;
869
870 child = pnode->first_child;
871 while (child != NULL((void*)0)) {
872 /*
873 * The routine we call might modify the child, e.g. by
874 * freeing it, so we get the child's successor before
875 * calling that routine.
876 */
877 current = child;
878 child = current->next;
879 // We recurse here, but we're limited by prefs.gui_max_tree_depth
880 if (proto_tree_traverse_pre_order((proto_tree *)current, func, data))
881 return true1;
882 }
883
884 return false0;
885}
886
887void
888proto_tree_children_foreach(proto_tree *tree, proto_tree_foreach_func func,
889 void *data)
890{
891 proto_node *node = tree;
892 proto_node *current;
893
894 if (!node)
895 return;
896
897 node = node->first_child;
898 while (node != NULL((void*)0)) {
899 current = node;
900 node = current->next;
901 func((proto_tree *)current, data);
902 }
903}
904
905static void
906free_GPtrArray_value(void *key, void *value, void *user_data _U___attribute__((unused)))
907{
908 GPtrArray *ptrs = (GPtrArray *)value;
909 int hfid = GPOINTER_TO_UINT(key)((guint) (gulong) (key));
910 header_field_info *hfinfo;
911
912 PROTO_REGISTRAR_GET_NTH(hfid, hfinfo)if((hfid == 0 || (unsigned)hfid > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 912, __func__, "Unregistered hf! index=%d",
hfid); ((void) ((hfid > 0 && (unsigned)hfid < gpa_hfinfo
.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 912, "hfid > 0 && (unsigned)hfid < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfid] != (
(void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 912, "gpa_hfinfo.hfi[hfid] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[hfid];
;
913 if (hfinfo->ref_type != HF_REF_TYPE_NONE) {
914 /* when a field is referenced by a filter this also
915 affects the refcount for the parent protocol so we need
916 to adjust the refcount for the parent as well
917 */
918 if (hfinfo->parent != -1) {
919 header_field_info *parent_hfinfo;
920 PROTO_REGISTRAR_GET_NTH(hfinfo->parent, parent_hfinfo)if((hfinfo->parent == 0 || (unsigned)hfinfo->parent >
gpa_hfinfo.len) && wireshark_abort_on_dissector_bug)
ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 920
, __func__, "Unregistered hf! index=%d", hfinfo->parent); (
(void) ((hfinfo->parent > 0 && (unsigned)hfinfo
->parent < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 920, "hfinfo->parent > 0 && (unsigned)hfinfo->parent < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
parent] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 920, "gpa_hfinfo.hfi[hfinfo->parent] != ((void*)0)"
, "Unregistered hf.")))) ; parent_hfinfo = gpa_hfinfo.hfi[hfinfo
->parent];
;
921 parent_hfinfo->ref_type = HF_REF_TYPE_NONE;
922 }
923 hfinfo->ref_type = HF_REF_TYPE_NONE;
924 }
925
926 g_ptr_array_free(ptrs, true1);
927}
928
929static void
930proto_tree_free_node(proto_node *node, void *data _U___attribute__((unused)))
931{
932 field_info *finfo = PNODE_FINFO(node)((node)->finfo);
933
934 proto_tree_children_foreach(node, proto_tree_free_node, NULL((void*)0));
935
936 if (finfo) {
937 // The fvalue_t structure was allocated using fvalue_new_pool()
938 // (see new_field_info()) and will be reclaimed when the pool is
939 // freed, so we only release the type-specific data it owns here.
940 fvalue_cleanup(finfo->value);
941 finfo->value = NULL((void*)0);
942 }
943}
944
945void
946proto_tree_reset(proto_tree *tree)
947{
948 tree_data_t *tree_data = PTREE_DATA(tree)((tree)->tree_data);
949
950 proto_tree_children_foreach(tree, proto_tree_free_node, NULL((void*)0));
951
952 /* free tree data */
953 if (tree_data->interesting_hfids) {
954 /* Free all the GPtrArray's in the interesting_hfids hash. */
955 g_hash_table_foreach(tree_data->interesting_hfids,
956 free_GPtrArray_value, NULL((void*)0));
957
958 /* And then remove all values. */
959 g_hash_table_remove_all(tree_data->interesting_hfids);
960 }
961
962 /* Reset track of the number of children */
963 tree_data->count = 0;
964
965 /* Reset our loop checks */
966 tree_data->idle_count_ds_tvb = NULL((void*)0);
967 tree_data->max_start = 0;
968 tree_data->start_idle_count = 0;
969
970 PROTO_NODE_INIT(tree)tree->first_child = ((void*)0); tree->last_child = ((void
*)0); tree->next = ((void*)0);
;
971}
972
973/* frees the resources that the dissection a proto_tree uses */
974void
975proto_tree_free(proto_tree *tree)
976{
977 tree_data_t *tree_data = PTREE_DATA(tree)((tree)->tree_data);
978
979 proto_tree_children_foreach(tree, proto_tree_free_node, NULL((void*)0));
980
981 /* free tree data */
982 if (tree_data->interesting_hfids) {
983 /* Free all the GPtrArray's in the interesting_hfids hash. */
984 g_hash_table_foreach(tree_data->interesting_hfids,
985 free_GPtrArray_value, NULL((void*)0));
986
987 /* And then destroy the hash. */
988 g_hash_table_destroy(tree_data->interesting_hfids);
989 }
990
991 g_slice_free(tree_data_t, tree_data)do { if (1) g_slice_free1 (sizeof (tree_data_t), (tree_data))
; else (void) ((tree_data_t*) 0 == (tree_data)); } while (0)
;
992
993 g_slice_free(proto_tree, tree)do { if (1) g_slice_free1 (sizeof (proto_tree), (tree)); else
(void) ((proto_tree*) 0 == (tree)); } while (0)
;
994}
995
996/* Is the parsing being done for a visible proto_tree or an invisible one?
997 * By setting this correctly, the proto_tree creation is sped up by not
998 * having to call vsnprintf and copy strings around.
999 */
1000bool_Bool
1001proto_tree_set_visible(proto_tree *tree, bool_Bool visible)
1002{
1003 bool_Bool old_visible = PTREE_DATA(tree)((tree)->tree_data)->visible;
1004
1005 PTREE_DATA(tree)((tree)->tree_data)->visible = visible;
1006
1007 return old_visible;
1008}
1009
1010void
1011proto_tree_set_fake_protocols(proto_tree *tree, bool_Bool fake_protocols)
1012{
1013 if (tree)
1014 PTREE_DATA(tree)((tree)->tree_data)->fake_protocols = fake_protocols;
1015}
1016
1017/* Assume dissector set only its protocol fields.
1018 This function is called by dissectors and allows the speeding up of filtering
1019 in wireshark; if this function returns false it is safe to reset tree to NULL
1020 and thus skip calling most of the expensive proto_tree_add_...()
1021 functions.
1022 If the tree is visible we implicitly assume the field is referenced.
1023*/
1024bool_Bool
1025proto_field_is_referenced(proto_tree *tree, int proto_id)
1026{
1027 register header_field_info *hfinfo;
1028
1029
1030 if (!tree)
1031 return false0;
1032
1033 if (PTREE_DATA(tree)((tree)->tree_data)->visible)
1034 return true1;
1035
1036 PROTO_REGISTRAR_GET_NTH(proto_id, hfinfo)if((proto_id == 0 || (unsigned)proto_id > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 1036, __func__, "Unregistered hf! index=%d"
, proto_id); ((void) ((proto_id > 0 && (unsigned)proto_id
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 1036,
"proto_id > 0 && (unsigned)proto_id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[proto_id]
!= ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 1036, "gpa_hfinfo.hfi[proto_id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[proto_id];
;
1037 if (hfinfo->ref_type != HF_REF_TYPE_NONE)
1038 return true1;
1039
1040 if (hfinfo->type == FT_PROTOCOL && !PTREE_DATA(tree)((tree)->tree_data)->fake_protocols)
1041 return true1;
1042
1043 return false0;
1044}
1045
1046
1047/* Finds a record in the hfinfo array by id. */
1048header_field_info *
1049proto_registrar_get_nth(unsigned hfindex)
1050{
1051 register header_field_info *hfinfo;
1052
1053 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 1053, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 1053,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 1053, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
1054 return hfinfo;
1055}
1056
1057
1058/* Prefix initialization
1059 * this allows for a dissector to register a display filter name prefix
1060 * so that it can delay the initialization of the hf array as long as
1061 * possible.
1062 */
1063
1064/* compute a hash for the part before the dot of a display filter */
1065static unsigned
1066prefix_hash (const void *key) {
1067 /* end the string at the dot and compute its hash */
1068 char* copy = g_strdup((const char *)key)g_strdup_inline ((const char *)key);
1069 char* c = copy;
1070 unsigned tmp;
1071
1072 for (; *c; c++) {
1073 if (*c == '.') {
1074 *c = 0;
1075 break;
1076 }
1077 }
1078
1079 tmp = wmem_str_hash(copy);
1080 g_free(copy)(__builtin_object_size ((copy), 0) != ((size_t) - 1)) ? g_free_sized
(copy, __builtin_object_size ((copy), 0)) : (g_free) (copy)
;
1081 return tmp;
1082}
1083
1084/* are both strings equal up to the end or the dot? */
1085static gboolean
1086prefix_equal (const void *ap, const void *bp) {
1087 const char* a = (const char *)ap;
1088 const char* b = (const char *)bp;
1089
1090 do {
1091 char ac = *a++;
1092 char bc = *b++;
1093
1094 if ( (ac == '.' || ac == '\0') && (bc == '.' || bc == '\0') ) return TRUE(!(0));
1095
1096 if ( (ac == '.' || ac == '\0') && ! (bc == '.' || bc == '\0') ) return FALSE(0);
1097 if ( (bc == '.' || bc == '\0') && ! (ac == '.' || ac == '\0') ) return FALSE(0);
1098
1099 if (ac != bc) return FALSE(0);
1100 } while (1);
1101
1102 return FALSE(0);
1103}
1104
1105/* Register a new prefix for "delayed" initialization of field arrays */
1106void
1107proto_register_prefix(const char *prefix, prefix_initializer_t pi ) {
1108 if (! prefixes ) {
1109 prefixes = g_hash_table_new(prefix_hash, prefix_equal);
1110 }
1111
1112 g_hash_table_insert(prefixes, (void *)prefix, (void *)pi);
1113}
1114
1115/* helper to call all prefix initializers */
1116static gboolean
1117initialize_prefix(void *k, void *v, void *u _U___attribute__((unused))) {
1118 ((prefix_initializer_t)v)((const char *)k);
1119 return TRUE(!(0));
1120}
1121
1122/** Initialize every remaining uninitialized prefix. */
1123void
1124proto_initialize_all_prefixes(void) {
1125 if (!prefixes) {
1126 return;
1127 }
1128 g_hash_table_foreach_remove(prefixes, initialize_prefix, NULL((void*)0));
1129}
1130
1131/* Finds a record in the hfinfo array by name.
1132 * If it fails to find it in the already registered fields,
1133 * it tries to find and call an initializer in the prefixes
1134 * table and if so it looks again.
1135 */
1136
1137header_field_info *
1138proto_registrar_get_byname(const char *field_name)
1139{
1140 header_field_info *hfinfo;
1141 prefix_initializer_t pi;
1142
1143 if (!field_name)
1144 return NULL((void*)0);
1145
1146 if (g_strcmp0(field_name, last_field_name) == 0) {
1147 return last_hfinfo;
1148 }
1149
1150 hfinfo = (header_field_info *)wmem_map_lookup(gpa_name_map, field_name);
1151
1152 if (hfinfo) {
1153 g_free(last_field_name)(__builtin_object_size ((last_field_name), 0) != ((size_t) - 1
)) ? g_free_sized (last_field_name, __builtin_object_size ((last_field_name
), 0)) : (g_free) (last_field_name)
;
1154 last_field_name = g_strdup(field_name)g_strdup_inline (field_name);
1155 last_hfinfo = hfinfo;
1156 return hfinfo;
1157 }
1158
1159 if (!prefixes)
1160 return NULL((void*)0);
1161
1162 if ((pi = (prefix_initializer_t)g_hash_table_lookup(prefixes, field_name) ) != NULL((void*)0)) {
1163 pi(field_name);
1164 g_hash_table_remove(prefixes, field_name);
1165 } else {
1166 return NULL((void*)0);
1167 }
1168
1169 hfinfo = (header_field_info *)wmem_map_lookup(gpa_name_map, field_name);
1170
1171 if (hfinfo) {
1172 g_free(last_field_name)(__builtin_object_size ((last_field_name), 0) != ((size_t) - 1
)) ? g_free_sized (last_field_name, __builtin_object_size ((last_field_name
), 0)) : (g_free) (last_field_name)
;
1173 last_field_name = g_strdup(field_name)g_strdup_inline (field_name);
1174 last_hfinfo = hfinfo;
1175 }
1176 return hfinfo;
1177}
1178
1179header_field_info*
1180proto_registrar_get_byalias(const char *alias_name)
1181{
1182 if (!alias_name) {
1183 return NULL((void*)0);
1184 }
1185
1186 /* Find our aliased protocol. */
1187 char *an_copy = g_strdup(alias_name)g_strdup_inline (alias_name);
1188 char *dot = strchr(an_copy, '.');
1189 if (dot) {
1190 *dot = '\0';
1191 }
1192 const char *proto_pfx = (const char *) g_hash_table_lookup(gpa_protocol_aliases, an_copy);
1193 if (!proto_pfx) {
1194 g_free(an_copy)(__builtin_object_size ((an_copy), 0) != ((size_t) - 1)) ? g_free_sized
(an_copy, __builtin_object_size ((an_copy), 0)) : (g_free) (
an_copy)
;
1195 return NULL((void*)0);
1196 }
1197
1198 /* Construct our aliased field and look it up. */
1199 GString *filter_name = g_string_new(proto_pfx);
1200 if (dot) {
1201 g_string_append_printf(filter_name, ".%s", dot+1);
1202 }
1203 header_field_info *hfinfo = proto_registrar_get_byname(filter_name->str);
1204 g_free(an_copy)(__builtin_object_size ((an_copy), 0) != ((size_t) - 1)) ? g_free_sized
(an_copy, __builtin_object_size ((an_copy), 0)) : (g_free) (
an_copy)
;
1205 g_string_free(filter_name, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) (
(filter_name), ((!(0)))) : g_string_free_and_steal (filter_name
)) : (g_string_free) ((filter_name), ((!(0)))))
;
1206
1207 return hfinfo;
1208}
1209
1210int
1211proto_registrar_get_id_byname(const char *field_name)
1212{
1213 header_field_info *hfinfo;
1214
1215 hfinfo = proto_registrar_get_byname(field_name);
1216
1217 if (!hfinfo)
1218 return -1;
1219
1220 return hfinfo->id;
1221}
1222
1223static int
1224label_strcat_flags(const header_field_info *hfinfo)
1225{
1226 if (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF) & BASE_STR_WSP)
1227 return FORMAT_LABEL_REPLACE_SPACE(0x1 << 0);
1228
1229 return 0;
1230}
1231
1232static char *
1233format_bytes_hfinfo_maxlen(wmem_allocator_t *scope, const header_field_info *hfinfo,
1234 const uint8_t *bytes, unsigned length, size_t max_str_len)
1235{
1236 char *str = NULL((void*)0);
1237 const uint8_t *p;
1238 bool_Bool is_printable;
1239
1240 if (bytes) {
1241 if (hfinfo->display & BASE_SHOW_UTF_8_PRINTABLE0x00020000) {
1242 /*
1243 * If all bytes are valid and printable UTF-8, show the
1244 * bytes as a string - in quotes to indicate that it's
1245 * a string.
1246 */
1247 if (isprint_utf8_string((const char*)bytes, length)) {
1248 str = wmem_strdup_printf(scope, "\"%.*s\"",
1249 (int)length, bytes);
1250 return str;
1251 }
1252 } else if (hfinfo->display & BASE_SHOW_ASCII_PRINTABLE0x00010000) {
1253 /*
1254 * Check whether all bytes are printable.
1255 */
1256 is_printable = true1;
1257 for (p = bytes; p < bytes+length; p++) {
1258 if (!g_ascii_isprint(*p)((g_ascii_table[(guchar) (*p)] & G_ASCII_PRINT) != 0)) {
1259 /* Not printable. */
1260 is_printable = false0;
1261 break;
1262 }
1263 }
1264
1265 /*
1266 * If all bytes are printable ASCII, show the bytes
1267 * as a string - in quotes to indicate that it's
1268 * a string.
1269 */
1270 if (is_printable) {
1271 str = wmem_strdup_printf(scope, "\"%.*s\"",
1272 (int)length, bytes);
1273 return str;
1274 }
1275 }
1276
1277 /*
1278 * Either it's not printable ASCII, or we don't care whether
1279 * it's printable ASCII; show it as hex bytes.
1280 */
1281 switch (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF)) {
1282 case SEP_DOT:
1283 str = bytes_to_str_punct_maxlen(scope, bytes, length, '.', max_str_len/3);
1284 break;
1285 case SEP_DASH:
1286 str = bytes_to_str_punct_maxlen(scope, bytes, length, '-', max_str_len/3);
1287 break;
1288 case SEP_COLON:
1289 str = bytes_to_str_punct_maxlen(scope, bytes, length, ':', max_str_len/3);
1290 break;
1291 case SEP_SPACE:
1292 str = bytes_to_str_punct_maxlen(scope, bytes, length, ' ', max_str_len/3);
1293 break;
1294 case BASE_NONE:
1295 default:
1296 if (prefs.display_byte_fields_with_spaces) {
1297 str = bytes_to_str_punct_maxlen(scope, bytes, length, ' ', max_str_len/3);
1298 } else {
1299 str = bytes_to_str_maxlen(scope, bytes, length, max_str_len/2);
1300 }
1301 break;
1302 }
1303 }
1304 else {
1305 if (hfinfo->display & BASE_ALLOW_ZERO0x00000800) {
1306 str = wmem_strdup(scope, "<none>");
1307 } else {
1308 str = wmem_strdup(scope, "<MISSING>");
1309 }
1310 }
1311 return str;
1312}
1313
1314static char *
1315format_bytes_hfinfo(wmem_allocator_t *scope, const header_field_info *hfinfo,
1316 const uint8_t *bytes, unsigned length)
1317{
1318 return format_bytes_hfinfo_maxlen(scope, hfinfo, bytes, length, ITEM_LABEL_LENGTH240);
1319}
1320
1321static void
1322ptvcursor_new_subtree_levels(ptvcursor_t *ptvc)
1323{
1324 subtree_lvl *pushed_tree;
1325
1326 DISSECTOR_ASSERT(ptvc->pushed_tree_max <= SUBTREE_MAX_LEVELS-SUBTREE_ONCE_ALLOCATION_NUMBER)((void) ((ptvc->pushed_tree_max <= 256 -8) ? (void)0 : (
proto_report_dissector_bug("%s:%u: failed assertion \"%s\"", "epan/proto.c"
, 1326, "ptvc->pushed_tree_max <= 256-8"))))
;
1327 ptvc->pushed_tree_max += SUBTREE_ONCE_ALLOCATION_NUMBER8;
1328
1329 pushed_tree = (subtree_lvl *)wmem_realloc(ptvc->scope, (void *)ptvc->pushed_tree, sizeof(subtree_lvl) * ptvc->pushed_tree_max);
1330 DISSECTOR_ASSERT(pushed_tree != NULL)((void) ((pushed_tree != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 1330, "pushed_tree != ((void*)0)"
))))
;
1331 ptvc->pushed_tree = pushed_tree;
1332}
1333
1334static void
1335ptvcursor_free_subtree_levels(ptvcursor_t *ptvc)
1336{
1337 ptvc->pushed_tree = NULL((void*)0);
1338 ptvc->pushed_tree_max = 0;
1339 DISSECTOR_ASSERT(ptvc->pushed_tree_index == 0)((void) ((ptvc->pushed_tree_index == 0) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 1339, "ptvc->pushed_tree_index == 0"
))))
;
1340 ptvc->pushed_tree_index = 0;
1341}
1342
1343/* Allocates an initializes a ptvcursor_t with 3 variables:
1344 * proto_tree, tvbuff, and offset. */
1345ptvcursor_t *
1346ptvcursor_new(wmem_allocator_t *scope, proto_tree *tree, tvbuff_t *tvb, unsigned offset)
1347{
1348 ptvcursor_t *ptvc;
1349
1350 ptvc = wmem_new(scope, ptvcursor_t)((ptvcursor_t*)wmem_alloc((scope), sizeof(ptvcursor_t)));
1351 ptvc->scope = scope;
1352 ptvc->tree = tree;
1353 ptvc->tvb = tvb;
1354 ptvc->offset = offset;
1355 ptvc->pushed_tree = NULL((void*)0);
1356 ptvc->pushed_tree_max = 0;
1357 ptvc->pushed_tree_index = 0;
1358 return ptvc;
1359}
1360
1361
1362/* Frees memory for ptvcursor_t, but nothing deeper than that. */
1363void
1364ptvcursor_free(ptvcursor_t *ptvc)
1365{
1366 ptvcursor_free_subtree_levels(ptvc);
1367 wmem_free(ptvc->scope, ptvc);
1368}
1369
1370/* Returns tvbuff. */
1371tvbuff_t *
1372ptvcursor_tvbuff(ptvcursor_t *ptvc)
1373{
1374 return ptvc->tvb;
1375}
1376
1377/* Returns current offset. */
1378unsigned
1379ptvcursor_current_offset(ptvcursor_t *ptvc)
1380{
1381 return ptvc->offset;
1382}
1383
1384proto_tree *
1385ptvcursor_tree(ptvcursor_t *ptvc)
1386{
1387 if (!ptvc)
1388 return NULL((void*)0);
1389
1390 return ptvc->tree;
1391}
1392
1393void
1394ptvcursor_set_tree(ptvcursor_t *ptvc, proto_tree *tree)
1395{
1396 ptvc->tree = tree;
1397}
1398
1399/* creates a subtree, sets it as the working tree and pushes the old working tree */
1400proto_tree *
1401ptvcursor_push_subtree(ptvcursor_t *ptvc, proto_item *it, int ett_subtree)
1402{
1403 subtree_lvl *subtree;
1404 if (ptvc->pushed_tree_index >= ptvc->pushed_tree_max)
1405 ptvcursor_new_subtree_levels(ptvc);
1406
1407 subtree = ptvc->pushed_tree + ptvc->pushed_tree_index;
1408 subtree->tree = ptvc->tree;
1409 subtree->it= NULL((void*)0);
1410 ptvc->pushed_tree_index++;
1411 return ptvcursor_set_subtree(ptvc, it, ett_subtree);
1412}
1413
1414/* pops a subtree */
1415void
1416ptvcursor_pop_subtree(ptvcursor_t *ptvc)
1417{
1418 subtree_lvl *subtree;
1419
1420 if (ptvc->pushed_tree_index <= 0)
1421 return;
1422
1423 ptvc->pushed_tree_index--;
1424 subtree = ptvc->pushed_tree + ptvc->pushed_tree_index;
1425 if (subtree->it != NULL((void*)0))
1426 proto_item_set_len(subtree->it, ptvcursor_current_offset(ptvc) - subtree->cursor_offset);
1427
1428 ptvc->tree = subtree->tree;
1429}
1430
1431/* saves the current tvb offset and the item in the current subtree level */
1432static void
1433ptvcursor_subtree_set_item(ptvcursor_t *ptvc, proto_item *it)
1434{
1435 subtree_lvl *subtree;
1436
1437 DISSECTOR_ASSERT(ptvc->pushed_tree_index > 0)((void) ((ptvc->pushed_tree_index > 0) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 1437, "ptvc->pushed_tree_index > 0"
))))
;
1438
1439 subtree = ptvc->pushed_tree + ptvc->pushed_tree_index - 1;
1440 subtree->it = it;
1441 subtree->cursor_offset = ptvcursor_current_offset(ptvc);
1442}
1443
1444/* Creates a subtree and adds it to the cursor as the working tree but does not
1445 * save the old working tree */
1446proto_tree *
1447ptvcursor_set_subtree(ptvcursor_t *ptvc, proto_item *it, int ett_subtree)
1448{
1449 ptvc->tree = proto_item_add_subtree(it, ett_subtree);
1450 return ptvc->tree;
1451}
1452
1453static proto_tree *
1454ptvcursor_add_subtree_item(ptvcursor_t *ptvc, proto_item *it, int ett_subtree, int length)
1455{
1456 ptvcursor_push_subtree(ptvc, it, ett_subtree);
1457 if (length == SUBTREE_UNDEFINED_LENGTH-1)
1458 ptvcursor_subtree_set_item(ptvc, it);
1459 return ptvcursor_tree(ptvc);
1460}
1461
1462/* Add an item to the tree and create a subtree
1463 * If the length is unknown, length may be defined as SUBTREE_UNDEFINED_LENGTH.
1464 * In this case, when the subtree will be closed, the parent item length will
1465 * be equal to the advancement of the cursor since the creation of the subtree.
1466 */
1467proto_tree *
1468ptvcursor_add_with_subtree(ptvcursor_t *ptvc, int hfindex, int length,
1469 const unsigned encoding, int ett_subtree)
1470{
1471 proto_item *it;
1472
1473 it = ptvcursor_add_no_advance(ptvc, hfindex, length, encoding);
1474 return ptvcursor_add_subtree_item(ptvc, it, ett_subtree, length);
1475}
1476
1477static proto_item *
1478proto_tree_add_text_node(proto_tree *tree, tvbuff_t *tvb, unsigned start, int length);
1479
1480/* Add a text node to the tree and create a subtree
1481 * If the length is unknown, length may be defined as SUBTREE_UNDEFINED_LENGTH.
1482 * In this case, when the subtree will be closed, the item length will be equal
1483 * to the advancement of the cursor since the creation of the subtree.
1484 */
1485proto_tree *
1486ptvcursor_add_text_with_subtree(ptvcursor_t *ptvc, int length,
1487 int ett_subtree, const char *format, ...)
1488{
1489 proto_item *pi;
1490 va_list ap;
1491 header_field_info *hfinfo;
1492 proto_tree *tree;
1493
1494 tree = ptvcursor_tree(ptvc);
1495
1496 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
1497
1498 TRY_TO_FAKE_THIS_ITEM(tree, hf_text_only, hfinfo)((tree)->tree_data)->count++; if((hf_text_only == 0 || (
unsigned)hf_text_only > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 1498
, __func__, "Unregistered hf! index=%d", hf_text_only); ((void
) ((hf_text_only > 0 && (unsigned)hf_text_only <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 1498, "hf_text_only > 0 && (unsigned)hf_text_only < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hf_text_only
] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 1498, "gpa_hfinfo.hfi[hf_text_only] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hf_text_only
];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 1498, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
1499
1500 pi = proto_tree_add_text_node(tree, ptvcursor_tvbuff(ptvc),
1501 ptvcursor_current_offset(ptvc), length);
1502
1503 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 1503, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
1504
1505 va_start(ap, format)__builtin_va_start(ap, format);
1506 proto_tree_set_representation(pi, format, ap);
1507 va_end(ap)__builtin_va_end(ap);
1508
1509 return ptvcursor_add_subtree_item(ptvc, pi, ett_subtree, length);
1510}
1511
1512/* Add a text-only node, leaving it to our caller to fill the text in */
1513static proto_item *
1514proto_tree_add_text_node(proto_tree *tree, tvbuff_t *tvb, unsigned start, int length)
1515{
1516 proto_item *pi;
1517
1518 if (tree == NULL((void*)0))
1519 return NULL((void*)0);
1520
1521 pi = proto_tree_add_pi(tree, &hfi_text_only, tvb, start, &length);
1522
1523 return pi;
1524}
1525
1526/* (INTERNAL USE ONLY) Add a text-only node to the proto_tree */
1527proto_item *
1528proto_tree_add_text_internal(proto_tree *tree, tvbuff_t *tvb, unsigned start, unsigned length,
1529 const char *format, ...)
1530{
1531 proto_item *pi;
1532 va_list ap;
1533 header_field_info *hfinfo;
1534
1535 tvb_ensure_bytes_exist(tvb, start, length);
1536
1537 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
1538
1539 TRY_TO_FAKE_THIS_ITEM(tree, hf_text_only, hfinfo)((tree)->tree_data)->count++; if((hf_text_only == 0 || (
unsigned)hf_text_only > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 1539
, __func__, "Unregistered hf! index=%d", hf_text_only); ((void
) ((hf_text_only > 0 && (unsigned)hf_text_only <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 1539, "hf_text_only > 0 && (unsigned)hf_text_only < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hf_text_only
] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 1539, "gpa_hfinfo.hfi[hf_text_only] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hf_text_only
];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 1539, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
1540
1541 pi = proto_tree_add_text_node(tree, tvb, start, length);
1542
1543 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 1543, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
1544
1545 va_start(ap, format)__builtin_va_start(ap, format);
1546 proto_tree_set_representation(pi, format, ap);
1547 va_end(ap)__builtin_va_end(ap);
1548
1549 return pi;
1550}
1551
1552/* (INTERNAL USE ONLY) Add a text-only node to the proto_tree (va_list version) */
1553proto_item *
1554proto_tree_add_text_valist_internal(proto_tree *tree, tvbuff_t *tvb, unsigned start,
1555 unsigned length, const char *format, va_list ap)
1556{
1557 proto_item *pi;
1558 header_field_info *hfinfo;
1559
1560 /* proto_tree_add_text_node calls proto_tree_add_pi() with the
1561 * FT_NONE hf_text_only, which calls get_hfi_length, which adjusts
1562 * the length to be what's in the tvbuff if length is -1, and the
1563 * minimum of length and what's in the tvbuff if not.
1564 */
1565
1566 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
1567
1568 TRY_TO_FAKE_THIS_ITEM(tree, hf_text_only, hfinfo)((tree)->tree_data)->count++; if((hf_text_only == 0 || (
unsigned)hf_text_only > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 1568
, __func__, "Unregistered hf! index=%d", hf_text_only); ((void
) ((hf_text_only > 0 && (unsigned)hf_text_only <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 1568, "hf_text_only > 0 && (unsigned)hf_text_only < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hf_text_only
] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 1568, "gpa_hfinfo.hfi[hf_text_only] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hf_text_only
];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 1568, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
1569
1570 pi = proto_tree_add_text_node(tree, tvb, start, length);
1571
1572 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 1572, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
1573
1574 proto_tree_set_representation(pi, format, ap);
1575
1576 return pi;
1577}
1578
1579/* Add a text-only node that creates a subtree underneath.
1580 */
1581proto_tree *
1582proto_tree_add_subtree(proto_tree *tree, tvbuff_t *tvb, unsigned start, int length, int idx, proto_item **tree_item, const char *text)
1583{
1584 return proto_tree_add_subtree_format(tree, tvb, start, length, idx, tree_item, "%s", text);
1585}
1586
1587/* Add a text-only node that creates a subtree underneath.
1588 */
1589proto_tree *
1590proto_tree_add_subtree_format(proto_tree *tree, tvbuff_t *tvb, unsigned start, int length, int idx, proto_item **tree_item, const char *format, ...)
1591{
1592 proto_tree *pt;
1593 proto_item *pi;
1594 va_list ap;
1595
1596 if (length == -1) {
1597 length = tvb_captured_length_remaining(tvb, start);
1598 }
1599
1600 va_start(ap, format)__builtin_va_start(ap, format);
1601 pi = proto_tree_add_text_valist_internal(tree, tvb, start, length, format, ap);
1602 va_end(ap)__builtin_va_end(ap);
1603
1604 if (tree_item != NULL((void*)0))
1605 *tree_item = pi;
1606
1607 pt = proto_item_add_subtree(pi, idx);
1608
1609 return pt;
1610}
1611
1612/* Add a text-only node for debugging purposes. The caller doesn't need
1613 * to worry about tvbuff, start, or length. Debug message gets sent to
1614 * STDOUT, too */
1615proto_item *
1616proto_tree_add_debug_text(proto_tree *tree, const char *format, ...)
1617{
1618 proto_item *pi;
1619 va_list ap;
1620
1621 pi = proto_tree_add_text_node(tree, NULL((void*)0), 0, 0);
1622
1623 if (pi) {
1624 va_start(ap, format)__builtin_va_start(ap, format);
1625 proto_tree_set_representation(pi, format, ap);
1626 va_end(ap)__builtin_va_end(ap);
1627 }
1628 va_start(ap, format)__builtin_va_start(ap, format);
1629 vprintf(format, ap);
1630 va_end(ap)__builtin_va_end(ap);
1631 printf("\n");
1632
1633 return pi;
1634}
1635
1636proto_item *
1637proto_tree_add_format_text(proto_tree *tree, tvbuff_t *tvb, unsigned start, unsigned length)
1638{
1639 proto_item *pi;
1640 header_field_info *hfinfo;
1641
1642 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
1643
1644 TRY_TO_FAKE_THIS_ITEM(tree, hf_text_only, hfinfo)((tree)->tree_data)->count++; if((hf_text_only == 0 || (
unsigned)hf_text_only > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 1644
, __func__, "Unregistered hf! index=%d", hf_text_only); ((void
) ((hf_text_only > 0 && (unsigned)hf_text_only <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 1644, "hf_text_only > 0 && (unsigned)hf_text_only < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hf_text_only
] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 1644, "gpa_hfinfo.hfi[hf_text_only] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hf_text_only
];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 1644, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
1645
1646 pi = proto_tree_add_text_node(tree, tvb, start, length);
1647
1648 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 1648, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
1649
1650 proto_item_set_text(pi, "%s", tvb_format_text(tree->tree_data->pinfo->pool, tvb, start, length));
1651
1652 return pi;
1653}
1654
1655proto_item *
1656proto_tree_add_format_wsp_text(proto_tree *tree, tvbuff_t *tvb, unsigned start, unsigned length)
1657{
1658 proto_item *pi;
1659 header_field_info *hfinfo;
1660 char *str;
1661
1662 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
1663
1664 TRY_TO_FAKE_THIS_ITEM(tree, hf_text_only, hfinfo)((tree)->tree_data)->count++; if((hf_text_only == 0 || (
unsigned)hf_text_only > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 1664
, __func__, "Unregistered hf! index=%d", hf_text_only); ((void
) ((hf_text_only > 0 && (unsigned)hf_text_only <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 1664, "hf_text_only > 0 && (unsigned)hf_text_only < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hf_text_only
] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 1664, "gpa_hfinfo.hfi[hf_text_only] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hf_text_only
];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 1664, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
1665
1666 pi = proto_tree_add_text_node(tree, tvb, start, length);
1667
1668 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 1668, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
1669
1670 str = tvb_format_text_wsp(NULL((void*)0), tvb, start, length);
1671 proto_item_set_text(pi, "%s", str);
1672 wmem_free(NULL((void*)0), str);
1673
1674 return pi;
1675}
1676
1677void proto_report_dissector_bug(const char *format, ...)
1678{
1679 va_list args;
1680
1681 if (wireshark_abort_on_dissector_bug) {
1682 /*
1683 * Try to have the error message show up in the crash
1684 * information.
1685 */
1686 va_start(args, format)__builtin_va_start(args, format);
1687 ws_vadd_crash_info(format, args);
1688 va_end(args)__builtin_va_end(args);
1689
1690 /*
1691 * Print the error message.
1692 */
1693 va_start(args, format)__builtin_va_start(args, format);
1694 vfprintf(stderrstderr, format, args);
1695 va_end(args)__builtin_va_end(args);
1696 putc('\n', stderrstderr);
1697
1698 /*
1699 * And crash.
1700 */
1701 abort();
1702 } else {
1703 va_start(args, format)__builtin_va_start(args, format);
1704 VTHROW_FORMATTED(DissectorError, format, args)except_vthrowf(1, (6), format, args);
1705 va_end(args)__builtin_va_end(args);
1706 ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 1706
, __func__, "assertion \"not reached\" failed")
; /* GCC 12 with ASAN needs this. */
1707 }
1708}
1709
1710/* We could probably get away with changing is_error to a minimum length value. */
1711static void
1712report_type_length_mismatch(proto_tree *tree, const char *descr, int length, bool_Bool is_error)
1713{
1714 if (is_error) {
1715 expert_add_info_format(NULL((void*)0), tree, &ei_type_length_mismatch_error, "Trying to fetch %s with length %d", descr, length);
1716 } else {
1717 expert_add_info_format(NULL((void*)0), tree, &ei_type_length_mismatch_warn, "Trying to fetch %s with length %d", descr, length);
1718 }
1719
1720 if (is_error) {
1721 THROW(ReportedBoundsError)except_throw(1, (3), ((void*)0));
1722 }
1723}
1724
1725static uint32_t
1726get_uint_value(proto_tree *tree, tvbuff_t *tvb, unsigned offset, int length, const unsigned encoding)
1727{
1728 uint32_t value;
1729 bool_Bool length_error;
1730
1731 switch (length) {
1732
1733 case 1:
1734 value = tvb_get_uint8(tvb, offset);
1735 if (encoding & ENC_ZIGBEE0x40000000) {
1736 if (value == 0xFF) { /* Invalid Zigbee length, set to 0 */
1737 value = 0;
1738 }
1739 }
1740 break;
1741
1742 case 2:
1743 value = (encoding & ENC_LITTLE_ENDIAN0x80000000) ? tvb_get_letohs(tvb, offset)
1744 : tvb_get_ntohs(tvb, offset);
1745 if (encoding & ENC_ZIGBEE0x40000000) {
1746 if (value == 0xFFFF) { /* Invalid Zigbee length, set to 0 */
1747 value = 0;
1748 }
1749 }
1750 break;
1751
1752 case 3:
1753 value = (encoding & ENC_LITTLE_ENDIAN0x80000000) ? tvb_get_letoh24(tvb, offset)
1754 : tvb_get_ntoh24(tvb, offset);
1755 break;
1756
1757 case 4:
1758 value = (encoding & ENC_LITTLE_ENDIAN0x80000000) ? tvb_get_letohl(tvb, offset)
1759 : tvb_get_ntohl(tvb, offset);
1760 break;
1761
1762 default:
1763 if (length < 1) {
1764 length_error = true1;
1765 value = 0;
1766 } else {
1767 length_error = false0;
1768 value = (encoding & ENC_LITTLE_ENDIAN0x80000000) ? tvb_get_letohl(tvb, offset)
1769 : tvb_get_ntohl(tvb, offset);
1770 }
1771 report_type_length_mismatch(tree, "an unsigned integer", length, length_error);
1772 break;
1773 }
1774 return value;
1775}
1776
1777static inline uint64_t
1778get_uint64_value(proto_tree *tree, tvbuff_t *tvb, unsigned offset, unsigned length, const unsigned encoding)
1779{
1780 uint64_t value;
1781
1782 value = tvb_get_uint64_with_length(tvb, offset, length, encoding);
1783
1784 if (length < 1 || length > 8) {
1785 report_type_length_mismatch(tree, "an unsigned integer", length, (length < 1));
1786 }
1787
1788 return value;
1789}
1790
1791static int32_t
1792get_int_value(proto_tree *tree, tvbuff_t *tvb, unsigned offset, int length, const unsigned encoding)
1793{
1794 int32_t value;
1795 bool_Bool length_error;
1796
1797 switch (length) {
1798
1799 case 1:
1800 value = tvb_get_int8(tvb, offset);
1801 break;
1802
1803 case 2:
1804 value = encoding ? tvb_get_letohis(tvb, offset)
1805 : tvb_get_ntohis(tvb, offset);
1806 break;
1807
1808 case 3:
1809 value = encoding ? tvb_get_letohi24(tvb, offset)
1810 : tvb_get_ntohi24(tvb, offset);
1811 break;
1812
1813 case 4:
1814 value = encoding ? tvb_get_letohil(tvb, offset)
1815 : tvb_get_ntohil(tvb, offset);
1816 break;
1817
1818 default:
1819 if (length < 1) {
1820 length_error = true1;
1821 value = 0;
1822 } else {
1823 length_error = false0;
1824 value = encoding ? tvb_get_letohil(tvb, offset)
1825 : tvb_get_ntohil(tvb, offset);
1826 }
1827 report_type_length_mismatch(tree, "a signed integer", length, length_error);
1828 break;
1829 }
1830 return value;
1831}
1832
1833/* Note: this returns an unsigned int64, but with the appropriate bit(s) set to
1834 * be cast-able as a int64_t. This is weird, but what the code has always done.
1835 */
1836static inline uint64_t
1837get_int64_value(proto_tree *tree, tvbuff_t *tvb, unsigned start, unsigned length, const unsigned encoding)
1838{
1839 uint64_t value = get_uint64_value(tree, tvb, start, length, encoding);
1840
1841 switch (length) {
1842 case 7:
1843 value = ws_sign_ext64(value, 56);
1844 break;
1845 case 6:
1846 value = ws_sign_ext64(value, 48);
1847 break;
1848 case 5:
1849 value = ws_sign_ext64(value, 40);
1850 break;
1851 case 4:
1852 value = ws_sign_ext64(value, 32);
1853 break;
1854 case 3:
1855 value = ws_sign_ext64(value, 24);
1856 break;
1857 case 2:
1858 value = ws_sign_ext64(value, 16);
1859 break;
1860 case 1:
1861 value = ws_sign_ext64(value, 8);
1862 break;
1863 }
1864
1865 return value;
1866}
1867
1868/* For FT_STRING */
1869static inline const uint8_t *
1870get_string_value(wmem_allocator_t *scope, tvbuff_t *tvb, unsigned start,
1871 int length, unsigned *ret_length, const unsigned encoding)
1872{
1873 if (length == -1) {
1874 *ret_length = tvb_ensure_captured_length_remaining(tvb, start);
1875 } else {
1876 *ret_length = length;
1877 }
1878 return tvb_get_string_enc(scope, tvb, start, *ret_length, encoding);
1879}
1880
1881/* For FT_STRINGZ */
1882static inline const uint8_t *
1883get_stringz_value(wmem_allocator_t *scope, proto_tree *tree, tvbuff_t *tvb,
1884 unsigned start, int length, unsigned *ret_length, const unsigned encoding)
1885{
1886 const uint8_t *value;
1887
1888 if (length < -1) {
1889 report_type_length_mismatch(tree, "a string", length, true1);
1890 }
1891
1892 /* XXX - Ideally, every "null-terminated string which fits into a
1893 * known length" should be either FT_STRINGZPAD or FT_STRINGZTRUNC
1894 * as appropriate, not a FT_STRINGZ. If so, then we could always call
1895 * tvb_get_stringz_enc here. Failing that, we could treat length 0
1896 * as unknown length as well (since there is a trailing '\0', the real
1897 * length is never zero), allowing switching to unsigned lengths.
1898 */
1899 if (length == -1) {
1900 /* This can throw an exception */
1901 value = tvb_get_stringz_enc(scope, tvb, start, ret_length, encoding);
1902 } else {
1903 /* In this case, length signifies the length of the string.
1904 *
1905 * This could either be a null-padded string, which doesn't
1906 * necessarily have a '\0' at the end, or a null-terminated
1907 * string, with a trailing '\0'. (Yes, there are cases
1908 * where you have a string that's both counted and null-
1909 * terminated.)
1910 *
1911 * In the first case, we must allocate a buffer of length
1912 * "length+1", to make room for a trailing '\0'.
1913 *
1914 * In the second case, we don't assume that there is a
1915 * trailing '\0' there, as the packet might be malformed.
1916 * (XXX - should we throw an exception if there's no
1917 * trailing '\0'?) Therefore, we allocate a buffer of
1918 * length "length+1", and put in a trailing '\0', just to
1919 * be safe.
1920 *
1921 * (XXX - this would change if we made string values counted
1922 * rather than null-terminated.)
1923 */
1924 *ret_length = length;
1925 value = tvb_get_string_enc(scope, tvb, start, *ret_length, encoding);
1926 }
1927 return value;
1928}
1929
1930/* For FT_UINT_STRING */
1931static inline const uint8_t *
1932get_uint_string_value(wmem_allocator_t *scope, proto_tree *tree,
1933 tvbuff_t *tvb, unsigned start, int length, unsigned *ret_length,
1934 const unsigned encoding)
1935{
1936 uint32_t n;
1937 const uint8_t *value;
1938
1939 /* I believe it's ok if this is called with a NULL tree */
1940 n = get_uint_value(tree, tvb, start, length, encoding & ~ENC_CHARENCODING_MASK0x0000FFFE);
1941 value = tvb_get_string_enc(scope, tvb, start + length, n, encoding);
1942 *ret_length = length + n;
1943 return value;
1944}
1945
1946/* For FT_STRINGZPAD */
1947static inline const uint8_t *
1948get_stringzpad_value(wmem_allocator_t *scope, tvbuff_t *tvb, unsigned start,
1949 int length, unsigned *ret_length, const unsigned encoding)
1950{
1951 /*
1952 * XXX - currently, string values are null-
1953 * terminated, so a "zero-padded" string
1954 * isn't special. If we represent string
1955 * values as something that includes a counted
1956 * array of bytes, we'll need to strip the
1957 * trailing NULs.
1958 */
1959 if (length == -1) {
1960 *ret_length = tvb_ensure_captured_length_remaining(tvb, start);
1961 } else {
1962 *ret_length = length;
1963 }
1964 return tvb_get_string_enc(scope, tvb, start, *ret_length, encoding);
1965}
1966
1967/* For FT_STRINGZTRUNC */
1968static inline const uint8_t *
1969get_stringztrunc_value(wmem_allocator_t *scope, tvbuff_t *tvb, unsigned start,
1970 int length, unsigned *ret_length, const unsigned encoding)
1971{
1972 /*
1973 * XXX - currently, string values are null-
1974 * terminated, so a "zero-truncated" string
1975 * isn't special. If we represent string
1976 * values as something that includes a counted
1977 * array of bytes, we'll need to strip everything
1978 * starting with the terminating NUL.
1979 */
1980 if (length == -1) {
1981 *ret_length = tvb_ensure_captured_length_remaining(tvb, start);
1982 } else {
1983 *ret_length = length;
1984 }
1985 return tvb_get_string_enc(scope, tvb, start, *ret_length, encoding);
1986}
1987
1988/*
1989 * Deltas between the epochs for various non-UN*X time stamp formats and
1990 * the January 1, 1970, 00:00:00 (proleptic?) UTC epoch for the UN*X time
1991 * stamp format.
1992 */
1993
1994/*
1995 * NTP Era 0: the epoch is January 1, 1900, 00:00:00 (proleptic?) UTC.
1996 * XXX - if it's OK if this is unsigned, can we just use
1997 * EPOCH_DELTA_1900_01_01_00_00_00_UTC?
1998 */
1999#define NTP_TIMEDIFF1900TO1970SEC2208988800L INT64_C(2208988800)2208988800L
2000
2001/*
2002 * NTP Era 1: the epoch is February 7, 2036, 06:28:16 UTC.
2003 */
2004#define NTP_TIMEDIFF1970TO2036SEC2085978496L INT64_C(2085978496)2085978496L
2005
2006/* this can be called when there is no tree, so tree may be null */
2007static void
2008get_time_value(proto_tree *tree, tvbuff_t *tvb, const unsigned start,
2009 const int length, const unsigned encoding, nstime_t *time_stamp,
2010 const bool_Bool is_relative)
2011{
2012 uint32_t tmpsecs;
2013 uint64_t tmp64secs;
2014 uint64_t todusecs;
2015
2016 switch (encoding) {
2017
2018 case ENC_TIME_SECS_NSECS0x00000000|ENC_BIG_ENDIAN0x00000000:
2019 /*
2020 * If the length is 16, 8-byte seconds, followed
2021 * by 8-byte fractional time in nanoseconds,
2022 * both big-endian.
2023 *
2024 * If the length is 12, 8-byte seconds, followed
2025 * by 4-byte fractional time in nanoseconds,
2026 * both big-endian.
2027 *
2028 * If the length is 8, 4-byte seconds, followed
2029 * by 4-byte fractional time in nanoseconds,
2030 * both big-endian.
2031 *
2032 * For absolute times, the seconds are seconds
2033 * since the UN*X epoch.
2034 */
2035 if (length == 16) {
2036 time_stamp->secs = (time_t)tvb_get_ntoh64(tvb, start);
2037 time_stamp->nsecs = (uint32_t)tvb_get_ntoh64(tvb, start+8);
2038 } else if (length == 12) {
2039 time_stamp->secs = (time_t)tvb_get_ntoh64(tvb, start);
2040 time_stamp->nsecs = tvb_get_ntohl(tvb, start+8);
2041 } else if (length == 8) {
2042 time_stamp->secs = (time_t)tvb_get_ntohl(tvb, start);
2043 time_stamp->nsecs = tvb_get_ntohl(tvb, start+4);
2044 } else if (length == 4) {
2045 /*
2046 * Backwards compatibility.
2047 * ENC_TIME_SECS_NSECS is 0; using
2048 * ENC_BIG_ENDIAN by itself with a 4-byte
2049 * time-in-seconds value was done in the
2050 * past.
2051 */
2052 time_stamp->secs = (time_t)tvb_get_ntohl(tvb, start);
2053 time_stamp->nsecs = 0;
2054 } else {
2055 time_stamp->secs = 0;
2056 time_stamp->nsecs = 0;
2057 report_type_length_mismatch(tree, "a timespec", length, (length < 4));
2058 }
2059 break;
2060
2061 case ENC_TIME_SECS_NSECS0x00000000|ENC_LITTLE_ENDIAN0x80000000:
2062 /*
2063 * If the length is 16, 8-byte seconds, followed
2064 * by 8-byte fractional time in nanoseconds,
2065 * both little-endian.
2066 *
2067 * If the length is 12, 8-byte seconds, followed
2068 * by 4-byte fractional time in nanoseconds,
2069 * both little-endian.
2070 *
2071 * If the length is 8, 4-byte seconds, followed
2072 * by 4-byte fractional time in nanoseconds,
2073 * both little-endian.
2074 *
2075 * For absolute times, the seconds are seconds
2076 * since the UN*X epoch.
2077 */
2078 if (length == 16) {
2079 time_stamp->secs = (time_t)tvb_get_letoh64(tvb, start);
2080 time_stamp->nsecs = (uint32_t)tvb_get_letoh64(tvb, start+8);
2081 } else if (length == 12) {
2082 time_stamp->secs = (time_t)tvb_get_letoh64(tvb, start);
2083 time_stamp->nsecs = tvb_get_letohl(tvb, start+8);
2084 } else if (length == 8) {
2085 time_stamp->secs = (time_t)tvb_get_letohl(tvb, start);
2086 time_stamp->nsecs = tvb_get_letohl(tvb, start+4);
2087 } else if (length == 4) {
2088 /*
2089 * Backwards compatibility.
2090 * ENC_TIME_SECS_NSECS is 0; using
2091 * ENC_LITTLE_ENDIAN by itself with a 4-byte
2092 * time-in-seconds value was done in the
2093 * past.
2094 */
2095 time_stamp->secs = (time_t)tvb_get_letohl(tvb, start);
2096 time_stamp->nsecs = 0;
2097 } else {
2098 time_stamp->secs = 0;
2099 time_stamp->nsecs = 0;
2100 report_type_length_mismatch(tree, "a timespec", length, (length < 4));
2101 }
2102 break;
2103
2104 case ENC_TIME_NTP0x00000002|ENC_BIG_ENDIAN0x00000000:
2105 /*
2106 * NTP time stamp, big-endian.
2107 * Only supported for absolute times.
2108 */
2109 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2109, "!is_relative"
))))
;
2110
2111 /* We need a temporary variable here so the unsigned math
2112 * works correctly (for years > 2036 according to RFC 2030
2113 * chapter 3).
2114 *
2115 * If bit 0 is set, the UTC time is in the range 1968-2036 and
2116 * UTC time is reckoned from 0h 0m 0s UTC on 1 January 1900.
2117 * If bit 0 is not set, the time is in the range 2036-2104 and
2118 * UTC time is reckoned from 6h 28m 16s UTC on 7 February 2036.
2119 */
2120 tmpsecs = tvb_get_ntohl(tvb, start);
2121 if ((tmpsecs & 0x80000000) != 0)
2122 time_stamp->secs = (time_t)((int64_t)tmpsecs - NTP_TIMEDIFF1900TO1970SEC2208988800L);
2123 else
2124 time_stamp->secs = (time_t)((int64_t)tmpsecs + NTP_TIMEDIFF1970TO2036SEC2085978496L);
2125
2126 if (length == 8) {
2127 tmp64secs = tvb_get_ntoh64(tvb, start);
2128 if (tmp64secs == 0) {
2129 //This is "NULL" time
2130 time_stamp->secs = 0;
2131 time_stamp->nsecs = 0;
2132 } else {
2133 /*
2134 * Convert 1/2^32s of a second to
2135 * nanoseconds.
2136 */
2137 time_stamp->nsecs = (int)(1000000000*(tvb_get_ntohl(tvb, start+4)/4294967296.0));
2138 }
2139 } else if (length == 4) {
2140 /*
2141 * Backwards compatibility.
2142 */
2143 if (tmpsecs == 0) {
2144 //This is "NULL" time
2145 time_stamp->secs = 0;
2146 }
2147 time_stamp->nsecs = 0;
2148 } else {
2149 time_stamp->secs = 0;
2150 time_stamp->nsecs = 0;
2151 report_type_length_mismatch(tree, "an NTP time stamp", length, (length < 4));
2152 }
2153 break;
2154
2155 case ENC_TIME_NTP0x00000002|ENC_LITTLE_ENDIAN0x80000000:
2156 /*
2157 * NTP time stamp, little-endian.
2158 * Only supported for absolute times.
2159 *
2160 * NTP doesn't use this, because it's an Internet format
2161 * and hence big-endian. Any implementation must decide
2162 * whether the NTP timestamp is a 64-bit unsigned fixed
2163 * point number (RFC 1305, RFC 4330) or a 64-bit struct
2164 * with a 32-bit unsigned seconds field followed by a
2165 * 32-bit fraction field (cf. RFC 5905, which obsoletes
2166 * the previous two).
2167 *
2168 * XXX: We do the latter, but no dissector uses this format.
2169 * OTOH, ERF timestamps do the former, so perhaps we
2170 * should switch the interpretation so that packet-erf.c
2171 * could use this directly? (ENC_TIME_RTPS is this 64-bit
2172 * struct with two 32-bit fields, but with the UN*X epoch.)
2173 */
2174 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2174, "!is_relative"
))))
;
2175
2176 /* We need a temporary variable here so the unsigned math
2177 * works correctly (for years > 2036 according to RFC 2030
2178 * chapter 3).
2179 *
2180 * If bit 0 is set, the UTC time is in the range 1968-2036 and
2181 * UTC time is reckoned from 0h 0m 0s UTC on 1 January 1900.
2182 * If bit 0 is not set, the time is in the range 2036-2104 and
2183 * UTC time is reckoned from 6h 28m 16s UTC on 7 February 2036.
2184 */
2185 tmpsecs = tvb_get_letohl(tvb, start);
2186 if ((tmpsecs & 0x80000000) != 0)
2187 time_stamp->secs = (time_t)((int64_t)tmpsecs - NTP_TIMEDIFF1900TO1970SEC2208988800L);
2188 else
2189 time_stamp->secs = (time_t)((int64_t)tmpsecs + NTP_TIMEDIFF1970TO2036SEC2085978496L);
2190
2191 if (length == 8) {
2192 tmp64secs = tvb_get_letoh64(tvb, start);
2193 if (tmp64secs == 0) {
2194 //This is "NULL" time
2195 time_stamp->secs = 0;
2196 time_stamp->nsecs = 0;
2197 } else {
2198 /*
2199 * Convert 1/2^32s of a second to
2200 * nanoseconds.
2201 */
2202 time_stamp->nsecs = (int)(1000000000*(tvb_get_letohl(tvb, start+4)/4294967296.0));
2203 }
2204 } else if (length == 4) {
2205 /*
2206 * Backwards compatibility.
2207 */
2208 if (tmpsecs == 0) {
2209 //This is "NULL" time
2210 time_stamp->secs = 0;
2211 }
2212 time_stamp->nsecs = 0;
2213 } else {
2214 time_stamp->secs = 0;
2215 time_stamp->nsecs = 0;
2216 report_type_length_mismatch(tree, "an NTP time stamp", length, (length < 4));
2217 }
2218 break;
2219
2220 case ENC_TIME_TOD0x00000004|ENC_BIG_ENDIAN0x00000000:
2221 /*
2222 * S/3x0 and z/Architecture TOD clock time stamp,
2223 * big-endian. The epoch is January 1, 1900,
2224 * 00:00:00 (proleptic?) UTC.
2225 *
2226 * Only supported for absolute times.
2227 */
2228 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2228, "!is_relative"
))))
;
2229 DISSECTOR_ASSERT(length == 8)((void) ((length == 8) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2229, "length == 8"
))))
;
2230
2231 if (length == 8) {
2232 todusecs = tvb_get_ntoh64(tvb, start) >> 12;
2233 time_stamp->secs = (time_t)((todusecs / 1000000) - EPOCH_DELTA_1900_01_01_00_00_00_UTC2208988800U);
2234 time_stamp->nsecs = (int)((todusecs % 1000000) * 1000);
2235 } else {
2236 time_stamp->secs = 0;
2237 time_stamp->nsecs = 0;
2238 report_type_length_mismatch(tree, "a TOD clock time stamp", length, (length < 4));
2239 }
2240 break;
2241
2242 case ENC_TIME_TOD0x00000004|ENC_LITTLE_ENDIAN0x80000000:
2243 /*
2244 * S/3x0 and z/Architecture TOD clock time stamp,
2245 * little-endian. The epoch is January 1, 1900,
2246 * 00:00:00 (proleptic?) UTC.
2247 *
2248 * Only supported for absolute times.
2249 */
2250 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2250, "!is_relative"
))))
;
2251
2252 if (length == 8) {
2253 todusecs = tvb_get_letoh64(tvb, start) >> 12 ;
2254 time_stamp->secs = (time_t)((todusecs / 1000000) - EPOCH_DELTA_1900_01_01_00_00_00_UTC2208988800U);
2255 time_stamp->nsecs = (int)((todusecs % 1000000) * 1000);
2256 } else {
2257 time_stamp->secs = 0;
2258 time_stamp->nsecs = 0;
2259 report_type_length_mismatch(tree, "a TOD clock time stamp", length, (length < 4));
2260 }
2261 break;
2262
2263 case ENC_TIME_RTPS0x00000008|ENC_BIG_ENDIAN0x00000000:
2264 /*
2265 * Time stamp using the same seconds/fraction format
2266 * as NTP, but with the origin of the time stamp being
2267 * the UNIX epoch rather than the NTP epoch; big-
2268 * endian.
2269 *
2270 * Only supported for absolute times.
2271 */
2272 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2272, "!is_relative"
))))
;
2273
2274 if (length == 8) {
2275 time_stamp->secs = (time_t)tvb_get_ntohl(tvb, start);
2276 /*
2277 * Convert 1/2^32s of a second to nanoseconds.
2278 */
2279 time_stamp->nsecs = (int)(1000000000*(tvb_get_ntohl(tvb, start+4)/4294967296.0));
2280 } else {
2281 time_stamp->secs = 0;
2282 time_stamp->nsecs = 0;
2283 report_type_length_mismatch(tree, "an RTPS time stamp", length, (length < 4));
2284 }
2285 break;
2286
2287 case ENC_TIME_RTPS0x00000008|ENC_LITTLE_ENDIAN0x80000000:
2288 /*
2289 * Time stamp using the same seconds/fraction format
2290 * as NTP, but with the origin of the time stamp being
2291 * the UNIX epoch rather than the NTP epoch; little-
2292 * endian.
2293 *
2294 * Only supported for absolute times.
2295 *
2296 * The RTPS specification explicitly supports Little
2297 * Endian encoding. In one place, it states that its
2298 * Time_t representation "is the one defined by ...
2299 * RFC 1305", but in another explicitly defines it as
2300 * a struct consisting of an 32 bit unsigned seconds
2301 * field and a 32 bit unsigned fraction field, not a 64
2302 * bit fixed point, so we do that here.
2303 * https://www.omg.org/spec/DDSI-RTPS/2.5/PDF
2304 */
2305 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2305, "!is_relative"
))))
;
2306
2307 if (length == 8) {
2308 time_stamp->secs = (time_t)tvb_get_letohl(tvb, start);
2309 /*
2310 * Convert 1/2^32s of a second to nanoseconds.
2311 */
2312 time_stamp->nsecs = (int)(1000000000*(tvb_get_letohl(tvb, start+4)/4294967296.0));
2313 } else {
2314 time_stamp->secs = 0;
2315 time_stamp->nsecs = 0;
2316 report_type_length_mismatch(tree, "an RTPS time stamp", length, (length < 4));
2317 }
2318 break;
2319
2320 case ENC_TIME_MIP60x00000024 | ENC_BIG_ENDIAN0x00000000:
2321 /*
2322 * MIP6 time stamp, big-endian.
2323 * A 64-bit unsigned integer field containing a timestamp. The
2324 * value indicates the number of seconds since January 1, 1970,
2325 * 00:00 UTC, by using a fixed point format. In this format, the
2326 * integer number of seconds is contained in the first 48 bits of
2327 * the field, and the remaining 16 bits indicate the number of
2328 * 1/65536 fractions of a second.
2329
2330 * Only supported for absolute times.
2331 */
2332 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2332, "!is_relative"
))))
;
2333
2334 if (length == 8) {
2335 /* We need a temporary variable here so the casting and fractions
2336 * of a second work correctly.
2337 */
2338 tmp64secs = tvb_get_ntoh48(tvb, start);
2339 tmpsecs = tvb_get_ntohs(tvb, start + 6);
2340 tmpsecs <<= 16;
2341
2342 if ((tmp64secs == 0) && (tmpsecs == 0)) {
2343 //This is "NULL" time
2344 time_stamp->secs = 0;
2345 time_stamp->nsecs = 0;
2346 } else {
2347 time_stamp->secs = (time_t)tmp64secs;
2348 time_stamp->nsecs = (int)((tmpsecs / 4294967296.0) * 1000000000);
2349 }
2350 } else {
2351 time_stamp->secs = 0;
2352 time_stamp->nsecs = 0;
2353 report_type_length_mismatch(tree, "an NTP time stamp", length, (length != 8));
2354 }
2355 break;
2356
2357 case ENC_TIME_SECS_USECS0x00000010|ENC_BIG_ENDIAN0x00000000:
2358 /*
2359 * If the length is 16, 8-byte seconds, followed
2360 * by 8-byte fractional time in microseconds,
2361 * both big-endian.
2362 *
2363 * If the length is 12, 8-byte seconds, followed
2364 * by 4-byte fractional time in microseconds,
2365 * both big-endian.
2366 *
2367 * If the length is 8, 4-byte seconds, followed
2368 * by 4-byte fractional time in microseconds,
2369 * both big-endian.
2370 *
2371 * For absolute times, the seconds are seconds
2372 * since the UN*X epoch.
2373 */
2374 if (length == 16) {
2375 time_stamp->secs = (time_t)tvb_get_ntoh64(tvb, start);
2376 time_stamp->nsecs = (uint32_t)tvb_get_ntoh64(tvb, start+8)*1000;
2377 } else if (length == 12) {
2378 time_stamp->secs = (time_t)tvb_get_ntoh64(tvb, start);
2379 time_stamp->nsecs = tvb_get_ntohl(tvb, start+8)*1000;
2380 } else if (length == 8) {
2381 time_stamp->secs = (time_t)tvb_get_ntohl(tvb, start);
2382 time_stamp->nsecs = tvb_get_ntohl(tvb, start+4)*1000;
2383 } else {
2384 time_stamp->secs = 0;
2385 time_stamp->nsecs = 0;
2386 report_type_length_mismatch(tree, "a timeval", length, (length < 4));
2387 }
2388 break;
2389
2390 case ENC_TIME_SECS_USECS0x00000010|ENC_LITTLE_ENDIAN0x80000000:
2391 /*
2392 * If the length is 16, 8-byte seconds, followed
2393 * by 8-byte fractional time in microseconds,
2394 * both little-endian.
2395 *
2396 * If the length is 12, 8-byte seconds, followed
2397 * by 4-byte fractional time in microseconds,
2398 * both little-endian.
2399 *
2400 * If the length is 8, 4-byte seconds, followed
2401 * by 4-byte fractional time in microseconds,
2402 * both little-endian.
2403 *
2404 * For absolute times, the seconds are seconds
2405 * since the UN*X epoch.
2406 */
2407 if (length == 16) {
2408 time_stamp->secs = (time_t)tvb_get_letoh64(tvb, start);
2409 time_stamp->nsecs = (uint32_t)tvb_get_letoh64(tvb, start+8)*1000;
2410 } else if (length == 12) {
2411 time_stamp->secs = (time_t)tvb_get_letoh64(tvb, start);
2412 time_stamp->nsecs = tvb_get_letohl(tvb, start+8)*1000;
2413 } else if (length == 8) {
2414 time_stamp->secs = (time_t)tvb_get_letohl(tvb, start);
2415 time_stamp->nsecs = tvb_get_letohl(tvb, start+4)*1000;
2416 } else {
2417 time_stamp->secs = 0;
2418 time_stamp->nsecs = 0;
2419 report_type_length_mismatch(tree, "a timeval", length, (length < 4));
2420 }
2421 break;
2422
2423 case ENC_TIME_SECS0x00000012|ENC_BIG_ENDIAN0x00000000:
2424 case ENC_TIME_SECS0x00000012|ENC_LITTLE_ENDIAN0x80000000:
2425 /*
2426 * Seconds, 1 to 8 bytes.
2427 * For absolute times, it's seconds since the
2428 * UN*X epoch.
2429 */
2430 if (length >= 1 && length <= 8) {
2431 time_stamp->secs = (time_t)get_uint64_value(tree, tvb, start, length, encoding);
2432 time_stamp->nsecs = 0;
2433 } else {
2434 time_stamp->secs = 0;
2435 time_stamp->nsecs = 0;
2436 report_type_length_mismatch(tree, "a time-in-seconds time stamp", length, (length < 4));
2437 }
2438 break;
2439
2440 case ENC_TIME_MSECS0x00000014|ENC_BIG_ENDIAN0x00000000:
2441 case ENC_TIME_MSECS0x00000014|ENC_LITTLE_ENDIAN0x80000000:
2442 /*
2443 * Milliseconds, 1 to 8 bytes.
2444 * For absolute times, it's milliseconds since the
2445 * UN*X epoch.
2446 */
2447 if (length >= 1 && length <= 8) {
2448 uint64_t msecs;
2449
2450 msecs = get_uint64_value(tree, tvb, start, length, encoding);
2451 time_stamp->secs = (time_t)(msecs / 1000);
2452 time_stamp->nsecs = (int)(msecs % 1000)*1000000;
2453 } else {
2454 time_stamp->secs = 0;
2455 time_stamp->nsecs = 0;
2456 report_type_length_mismatch(tree, "a time-in-milliseconds time stamp", length, (length < 4));
2457 }
2458 break;
2459
2460 case ENC_TIME_USECS0x00000030|ENC_BIG_ENDIAN0x00000000:
2461 case ENC_TIME_USECS0x00000030|ENC_LITTLE_ENDIAN0x80000000:
2462 /*
2463 * Microseconds, 1 to 8 bytes.
2464 * For absolute times, it's microseconds since the
2465 * UN*X epoch.
2466 */
2467 if (length >= 1 && length <= 8) {
2468 uint64_t usecs;
2469
2470 usecs = get_uint64_value(tree, tvb, start, length, encoding);
2471 time_stamp->secs = (time_t)(usecs / 1000000);
2472 time_stamp->nsecs = (int)(usecs % 1000000)*1000;
2473 } else {
2474 time_stamp->secs = 0;
2475 time_stamp->nsecs = 0;
2476 report_type_length_mismatch(tree, "a time-in-microseconds time stamp", length, (length < 4));
2477 }
2478 break;
2479
2480 case ENC_TIME_NSECS0x00000028|ENC_BIG_ENDIAN0x00000000:
2481 case ENC_TIME_NSECS0x00000028|ENC_LITTLE_ENDIAN0x80000000:
2482 /*
2483 * nanoseconds, 1 to 8 bytes.
2484 * For absolute times, it's nanoseconds since the
2485 * UN*X epoch.
2486 */
2487
2488 if (length >= 1 && length <= 8) {
2489 uint64_t nsecs;
2490
2491 nsecs = get_uint64_value(tree, tvb, start, length, encoding);
2492 time_stamp->secs = (time_t)(nsecs / 1000000000);
2493 time_stamp->nsecs = (int)(nsecs % 1000000000);
2494 } else {
2495 time_stamp->secs = 0;
2496 time_stamp->nsecs = 0;
2497 report_type_length_mismatch(tree, "a time-in-nanoseconds time stamp", length, (length < 4));
2498 }
2499 break;
2500
2501 case ENC_TIME_RFC_39710x00000020|ENC_BIG_ENDIAN0x00000000:
2502 /*
2503 * 1/64ths of a second since the UN*X epoch,
2504 * big-endian.
2505 *
2506 * Only supported for absolute times.
2507 */
2508 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2508, "!is_relative"
))))
;
2509
2510 if (length == 8) {
2511 /*
2512 * The upper 48 bits are seconds since the
2513 * UN*X epoch.
2514 */
2515 time_stamp->secs = (time_t)tvb_get_ntoh48(tvb, start);
2516 /*
2517 * The lower 16 bits are 1/2^16s of a second;
2518 * convert them to nanoseconds.
2519 *
2520 * XXX - this may give the impression of higher
2521 * precision than you actually get.
2522 */
2523 time_stamp->nsecs = (int)(1000000000*(tvb_get_ntohs(tvb, start+6)/65536.0));
2524 } else {
2525 time_stamp->secs = 0;
2526 time_stamp->nsecs = 0;
2527 report_type_length_mismatch(tree, "an RFC 3971-style time stamp", length, (length < 4));
2528 }
2529 break;
2530
2531 case ENC_TIME_RFC_39710x00000020|ENC_LITTLE_ENDIAN0x80000000:
2532 /*
2533 * 1/64ths of a second since the UN*X epoch,
2534 * little-endian.
2535 *
2536 * Only supported for absolute times.
2537 */
2538 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2538, "!is_relative"
))))
;
2539
2540 if (length == 8) {
2541 /*
2542 * XXX - this is assuming that, if anybody
2543 * were ever to use this format - RFC 3971
2544 * doesn't, because that's an Internet
2545 * protocol, and those use network byte
2546 * order, i.e. big-endian - they'd treat it
2547 * as a 64-bit count of 1/2^16s of a second,
2548 * putting the upper 48 bits at the end.
2549 *
2550 * The lower 48 bits are seconds since the
2551 * UN*X epoch.
2552 */
2553 time_stamp->secs = (time_t)tvb_get_letoh48(tvb, start+2);
2554 /*
2555 * The upper 16 bits are 1/2^16s of a second;
2556 * convert them to nanoseconds.
2557 *
2558 * XXX - this may give the impression of higher
2559 * precision than you actually get.
2560 */
2561 time_stamp->nsecs = (int)(1000000000*(tvb_get_letohs(tvb, start)/65536.0));
2562 } else {
2563 time_stamp->secs = 0;
2564 time_stamp->nsecs = 0;
2565 report_type_length_mismatch(tree, "an RFC 3971-style time stamp", length, (length < 4));
2566 }
2567 break;
2568
2569 case ENC_TIME_SECS_NTP0x00000018|ENC_BIG_ENDIAN0x00000000:
2570 /*
2571 * NTP time stamp, with 1-second resolution (i.e.,
2572 * seconds since the NTP epoch), big-endian.
2573 * Only supported for absolute times.
2574 */
2575 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2575, "!is_relative"
))))
;
2576
2577 if (length == 4) {
2578 /*
2579 * We need a temporary variable here so the unsigned math
2580 * works correctly (for years > 2036 according to RFC 2030
2581 * chapter 3).
2582 *
2583 * If bit 0 is set, the UTC time is in the range 1968-2036 and
2584 * UTC time is reckoned from 0h 0m 0s UTC on 1 January 1900.
2585 * If bit 0 is not set, the time is in the range 2036-2104 and
2586 * UTC time is reckoned from 6h 28m 16s UTC on 7 February 2036.
2587 */
2588 tmpsecs = tvb_get_ntohl(tvb, start);
2589 if ((tmpsecs & 0x80000000) != 0)
2590 time_stamp->secs = (time_t)((int64_t)tmpsecs - NTP_TIMEDIFF1900TO1970SEC2208988800L);
2591 else
2592 time_stamp->secs = (time_t)((int64_t)tmpsecs + NTP_TIMEDIFF1970TO2036SEC2085978496L);
2593 time_stamp->nsecs = 0;
2594 } else {
2595 time_stamp->secs = 0;
2596 time_stamp->nsecs = 0;
2597 report_type_length_mismatch(tree, "an NTP seconds-only time stamp", length, (length < 4));
2598 }
2599 break;
2600
2601 case ENC_TIME_SECS_NTP0x00000018|ENC_LITTLE_ENDIAN0x80000000:
2602 /*
2603 * NTP time stamp, with 1-second resolution (i.e.,
2604 * seconds since the NTP epoch), little-endian.
2605 * Only supported for absolute times.
2606 */
2607 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2607, "!is_relative"
))))
;
2608
2609 /*
2610 * We need a temporary variable here so the unsigned math
2611 * works correctly (for years > 2036 according to RFC 2030
2612 * chapter 3).
2613 *
2614 * If bit 0 is set, the UTC time is in the range 1968-2036 and
2615 * UTC time is reckoned from 0h 0m 0s UTC on 1 January 1900.
2616 * If bit 0 is not set, the time is in the range 2036-2104 and
2617 * UTC time is reckoned from 6h 28m 16s UTC on 7 February 2036.
2618 */
2619 if (length == 4) {
2620 tmpsecs = tvb_get_letohl(tvb, start);
2621 if ((tmpsecs & 0x80000000) != 0)
2622 time_stamp->secs = (time_t)((int64_t)tmpsecs - NTP_TIMEDIFF1900TO1970SEC2208988800L);
2623 else
2624 time_stamp->secs = (time_t)((int64_t)tmpsecs + NTP_TIMEDIFF1970TO2036SEC2085978496L);
2625 time_stamp->nsecs = 0;
2626 } else {
2627 time_stamp->secs = 0;
2628 time_stamp->nsecs = 0;
2629 report_type_length_mismatch(tree, "an NTP seconds-only time stamp", length, (length < 4));
2630 }
2631 break;
2632
2633 case ENC_TIME_MSEC_NTP0x00000022 | ENC_BIG_ENDIAN0x00000000:
2634 /*
2635 * Milliseconds, 6 to 8 bytes.
2636 * For absolute times, it's milliseconds since the
2637 * NTP epoch.
2638 *
2639 * ETSI TS 129.274 8.119 defines this as:
2640 * "a 48 bit unsigned integer in network order format
2641 * ...encoded as the number of milliseconds since
2642 * 00:00:00 January 1, 1900 00:00 UTC, i.e. as the
2643 * rounded value of 1000 x the value of the 64-bit
2644 * timestamp (Seconds + (Fraction / (1<<32))) defined
2645 * in clause 6 of IETF RFC 5905."
2646 *
2647 * Taken literally, the part after "i.e." would
2648 * mean that the value rolls over before reaching
2649 * 2^32 * 1000 = 4294967296000 = 0x3e800000000
2650 * when the 64 bit timestamp rolls over, and we have
2651 * to pick an NTP Era equivalence class to support
2652 * (such as 1968-01-20 to 2104-02-06).
2653 *
2654 * OTOH, the extra room might be used to store Era
2655 * information instead, in which case times until
2656 * 10819-08-03 can be represented with 6 bytes without
2657 * ambiguity. We handle both implementations, and assume
2658 * that times before 1968-01-20 are not represented.
2659 *
2660 * Only 6 bytes or more makes sense as an absolute
2661 * time. 5 bytes or fewer could express a span of
2662 * less than 35 years, either 1900-1934 or 2036-2070.
2663 */
2664 if (length >= 6 && length <= 8) {
2665 uint64_t msecs;
2666
2667 msecs = get_uint64_value(tree, tvb, start, length, encoding);
2668 tmp64secs = (msecs / 1000);
2669 /*
2670 * Assume that times in the first half of NTP
2671 * Era 0 really represent times in the NTP
2672 * Era 1.
2673 */
2674 if (tmp64secs >= 0x80000000)
2675 time_stamp->secs = (time_t)((int64_t)tmp64secs - NTP_TIMEDIFF1900TO1970SEC2208988800L);
2676 else
2677 time_stamp->secs = (time_t)((int64_t)tmp64secs + NTP_TIMEDIFF1970TO2036SEC2085978496L);
2678 time_stamp->nsecs = (int)(msecs % 1000)*1000000;
2679 }
2680 else {
2681 time_stamp->secs = 0;
2682 time_stamp->nsecs = 0;
2683 report_type_length_mismatch(tree, "a time-in-milliseconds NTP time stamp", length, (length < 6));
2684 }
2685 break;
2686
2687 case ENC_TIME_MP4_FILE_SECS0x00000026|ENC_BIG_ENDIAN0x00000000:
2688 /*
2689 * MP4 file time stamps, big-endian.
2690 * Only supported for absolute times.
2691 */
2692 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2692, "!is_relative"
))))
;
2693
2694 if (length == 8) {
2695 tmp64secs = tvb_get_ntoh64(tvb, start);
2696 time_stamp->secs = (time_t)(int64_t)(tmp64secs - EPOCH_DELTA_1904_01_01_00_00_00_UTC2082844800U);
2697 time_stamp->nsecs = 0;
2698 } else if (length == 4) {
2699 tmpsecs = tvb_get_ntohl(tvb, start);
2700 time_stamp->secs = (time_t)(int32_t)(tmpsecs - EPOCH_DELTA_1904_01_01_00_00_00_UTC2082844800U);
2701 time_stamp->nsecs = 0;
2702 } else {
2703 time_stamp->secs = 0;
2704 time_stamp->nsecs = 0;
2705 report_type_length_mismatch(tree, "an MP4 time stamp", length, (length < 4));
2706 }
2707 break;
2708
2709 case ENC_TIME_ZBEE_ZCL0x00000032 | ENC_BIG_ENDIAN0x00000000:
2710 /*
2711 * Zigbee ZCL time stamps, big-endian.
2712 * Only supported for absolute times.
2713 */
2714 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2714, "!is_relative"
))))
;
2715
2716 if (length == 8) {
2717 tmp64secs = tvb_get_ntoh64(tvb, start);
2718 if (ckd_add(&time_stamp->secs, tmp64secs, EPOCH_DELTA_2000_01_01_00_00_00_UTC)__builtin_add_overflow((tmp64secs), (((3*365 + 366)*7 + 2*365
)*24*3600UL), (&time_stamp->secs))
) {
2719 /* There are several other possible choices for what to do
2720 * with overflow; make sure to coordinate with whatever
2721 * packet-zbee-zcl.h does. */
2722 time_stamp->secs = TIME_T_MAX((time_t) (~ (time_t) 0 - ((time_t) ((time_t)0 < (time_t) -
1 ? (time_t) 0 : (time_t) (~0ULL << (sizeof (time_t) * 8
- 1))))))
;
2723 }
2724 time_stamp->nsecs = 0;
2725 } else if (length == 4) {
2726 tmpsecs = tvb_get_ntohl(tvb, start);
2727 if (ckd_add(&time_stamp->secs, tmpsecs, EPOCH_DELTA_2000_01_01_00_00_00_UTC)__builtin_add_overflow((tmpsecs), (((3*365 + 366)*7 + 2*365)*
24*3600UL), (&time_stamp->secs))
) {
2728 time_stamp->secs = TIME_T_MAX((time_t) (~ (time_t) 0 - ((time_t) ((time_t)0 < (time_t) -
1 ? (time_t) 0 : (time_t) (~0ULL << (sizeof (time_t) * 8
- 1))))))
;
2729 }
2730 time_stamp->nsecs = 0;
2731 } else {
2732 time_stamp->secs = 0;
2733 time_stamp->nsecs = 0;
2734 report_type_length_mismatch(tree, "a Zigbee ZCL time stamp", length, (length < 4));
2735 }
2736 break;
2737
2738 case ENC_TIME_ZBEE_ZCL0x00000032 | ENC_LITTLE_ENDIAN0x80000000:
2739 /*
2740 * Zigbee ZCL time stamps, little-endian.
2741 * Only supported for absolute times.
2742 */
2743 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2743, "!is_relative"
))))
;
2744
2745 if (length == 8) {
2746 tmp64secs = tvb_get_letoh64(tvb, start);
2747 if (ckd_add(&time_stamp->secs, tmp64secs, EPOCH_DELTA_2000_01_01_00_00_00_UTC)__builtin_add_overflow((tmp64secs), (((3*365 + 366)*7 + 2*365
)*24*3600UL), (&time_stamp->secs))
) {
2748 time_stamp->secs = TIME_T_MAX((time_t) (~ (time_t) 0 - ((time_t) ((time_t)0 < (time_t) -
1 ? (time_t) 0 : (time_t) (~0ULL << (sizeof (time_t) * 8
- 1))))))
;
2749 }
2750 time_stamp->nsecs = 0;
2751 } else if (length == 4) {
2752 tmpsecs = tvb_get_letohl(tvb, start);
2753 if (ckd_add(&time_stamp->secs, tmpsecs, EPOCH_DELTA_2000_01_01_00_00_00_UTC)__builtin_add_overflow((tmpsecs), (((3*365 + 366)*7 + 2*365)*
24*3600UL), (&time_stamp->secs))
) {
2754 time_stamp->secs = TIME_T_MAX((time_t) (~ (time_t) 0 - ((time_t) ((time_t)0 < (time_t) -
1 ? (time_t) 0 : (time_t) (~0ULL << (sizeof (time_t) * 8
- 1))))))
;
2755 }
2756 time_stamp->nsecs = 0;
2757 } else {
2758 time_stamp->secs = 0;
2759 time_stamp->nsecs = 0;
2760 report_type_length_mismatch(tree, "a Zigbee ZCL time stamp", length, (length < 4));
2761 }
2762 break;
2763
2764 case ENC_TIME_WINDOWS0x00000034 | ENC_BIG_ENDIAN0x00000000:
2765 /*
2766 * WINDOWS FILETIME, big-endian.
2767 * Only supported for absolute times.
2768 * A FILETIME is a struct with the low 32-bits followed
2769 * by the high 32-bits:
2770 * https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime
2771 * There exist cases where the value is stored in a
2772 * 64-bit integer:
2773 * (See epan/dissectors/pidl/samr/samr.idl "NTTIME_hyper last_password_change;"
2774 * which is confirmed as "LARGE_INTEGER PasswordLastSet;" in
2775 * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-samr/1cd138b9-cc1b-4706-b115-49e53189e32e
2776 * That doesn't make a difference when retrieving little-endian,
2777 * because tvb_get_letoh64 handles unaligned accesses and it's
2778 * otherwise the same. However, for big-endian, it does matter,
2779 * analogous to the ENC_TIME_NTP little-endian case. We use the
2780 * struct version, but that means that this MUST NOT be used
2781 * for dissect_nttime_hyper in packet-windows-common.h, at
2782 * least
2783 */
2784 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2784, "!is_relative"
))))
;
2785
2786 if (length == 8) {
2787 tmp64secs = tvb_get_ntoh64(tvb, start); // Really 100-ns units
2788 if (!filetime_to_nstime(time_stamp, tmp64secs)) {
2789 // With 32-bit time_t, this could overflow in
2790 // either direction. We should probably add some
2791 // kind of time overflow expert item to all
2792 // encodings.
2793 time_stamp->secs = TIME_T_MAX((time_t) (~ (time_t) 0 - ((time_t) ((time_t)0 < (time_t) -
1 ? (time_t) 0 : (time_t) (~0ULL << (sizeof (time_t) * 8
- 1))))))
;
2794 time_stamp->nsecs = 0;
2795 }
2796 } else {
2797 time_stamp->secs = 0;
2798 time_stamp->nsecs = 0;
2799 report_type_length_mismatch(tree, "an NTFS FILETIME time stamp", length, (length < 8));
2800 }
2801 break;
2802
2803 case ENC_TIME_WINDOWS0x00000034 | ENC_LITTLE_ENDIAN0x80000000:
2804 /*
2805 * WINDOWS FILETIME, big-endian.
2806 * Only supported for absolute times.
2807 * https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime
2808 */
2809 DISSECTOR_ASSERT(!is_relative)((void) ((!is_relative) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 2809, "!is_relative"
))))
;
2810
2811 if (length == 8) {
2812 tmp64secs = tvb_get_letoh64(tvb, start); // Really 100-ns units
2813 if (!filetime_to_nstime(time_stamp, tmp64secs)) {
2814 // With 32-bit time_t, this could overflow in
2815 // either direction. We should probably add some
2816 // kind of time overflow expert item to all
2817 // encodings.
2818 time_stamp->secs = TIME_T_MAX((time_t) (~ (time_t) 0 - ((time_t) ((time_t)0 < (time_t) -
1 ? (time_t) 0 : (time_t) (~0ULL << (sizeof (time_t) * 8
- 1))))))
;
2819 time_stamp->nsecs = 0;
2820 }
2821 } else {
2822 time_stamp->secs = 0;
2823 time_stamp->nsecs = 0;
2824 report_type_length_mismatch(tree, "an NTFS FILETIME time stamp", length, (length < 8));
2825 }
2826 break;
2827 default:
2828 DISSECTOR_ASSERT_NOT_REACHED()(proto_report_dissector_bug("%s:%u: failed assertion \"DISSECTOR_ASSERT_NOT_REACHED\""
, "epan/proto.c", 2828))
;
2829 break;
2830 }
2831}
2832
2833static void
2834tree_data_add_maybe_interesting_field(tree_data_t *tree_data, field_info *fi)
2835{
2836 const header_field_info *hfinfo = fi->hfinfo;
2837
2838 if (hfinfo->ref_type == HF_REF_TYPE_DIRECT || hfinfo->ref_type == HF_REF_TYPE_PRINT) {
2839 GPtrArray *ptrs = NULL((void*)0);
2840
2841 if (tree_data->interesting_hfids == NULL((void*)0)) {
2842 /* Initialize the hash because we now know that it is needed */
2843 tree_data->interesting_hfids =
2844 g_hash_table_new(g_direct_hash, NULL((void*)0) /* g_direct_equal */);
2845 } else if (g_hash_table_size(tree_data->interesting_hfids)) {
2846 ptrs = (GPtrArray *)g_hash_table_lookup(tree_data->interesting_hfids,
2847 GINT_TO_POINTER(hfinfo->id)((gpointer) (glong) (hfinfo->id)));
2848 }
2849
2850 if (!ptrs) {
2851 /* First element triggers the creation of pointer array */
2852 ptrs = g_ptr_array_new();
2853 g_hash_table_insert(tree_data->interesting_hfids,
2854 GINT_TO_POINTER(hfinfo->id)((gpointer) (glong) (hfinfo->id)), ptrs);
2855 }
2856
2857 g_ptr_array_add(ptrs, fi);
2858 }
2859}
2860
2861
2862/*
2863 * Validates that field length bytes are available starting from
2864 * start (pos/neg). Throws an exception if they aren't.
2865 */
2866static void
2867test_length(header_field_info *hfinfo, tvbuff_t *tvb,
2868 unsigned start, int length, const unsigned encoding)
2869{
2870 int size = length;
2871
2872 if (!tvb)
2873 return;
2874
2875 if ((hfinfo->type == FT_STRINGZ) ||
2876 ((encoding & ENC_VARINT_MASK(0x00000002|0x00000004|0x00000008|0x00000010)) &&
2877 (FT_IS_UINT(hfinfo->type)(((hfinfo->type) == FT_CHAR || (hfinfo->type) == FT_UINT8
|| (hfinfo->type) == FT_UINT16 || (hfinfo->type) == FT_UINT24
|| (hfinfo->type) == FT_UINT32 || (hfinfo->type) == FT_FRAMENUM
) || ((hfinfo->type) == FT_UINT40 || (hfinfo->type) == FT_UINT48
|| (hfinfo->type) == FT_UINT56 || (hfinfo->type) == FT_UINT64
))
|| FT_IS_INT(hfinfo->type)(((hfinfo->type) == FT_INT8 || (hfinfo->type) == FT_INT16
|| (hfinfo->type) == FT_INT24 || (hfinfo->type) == FT_INT32
) || ((hfinfo->type) == FT_INT40 || (hfinfo->type) == FT_INT48
|| (hfinfo->type) == FT_INT56 || (hfinfo->type) == FT_INT64
))
))) {
2878 /* If we're fetching until the end of the TVB, only validate
2879 * that the offset is within range.
2880 */
2881 if (length == -1)
2882 size = 0;
2883 }
2884
2885 tvb_ensure_bytes_exist(tvb, start, size);
2886}
2887
2888static void
2889detect_trailing_stray_characters(unsigned encoding, const char *string, int length, proto_item *pi)
2890{
2891 bool_Bool found_stray_character = false0;
2892
2893 if (!string)
2894 return;
2895
2896 switch (encoding & ENC_CHARENCODING_MASK0x0000FFFE) {
2897 case ENC_ASCII0x00000000:
2898 case ENC_UTF_80x00000002:
2899 for (int i = (int)strlen(string); i < length; i++) {
2900 if (string[i] != '\0') {
2901 found_stray_character = true1;
2902 break;
2903 }
2904 }
2905 break;
2906
2907 default:
2908 break;
2909 }
2910
2911 if (found_stray_character) {
2912 expert_add_info(NULL((void*)0), pi, &ei_string_trailing_characters);
2913 }
2914}
2915
2916/* Add an item to a proto_tree, using the text label registered to that item;
2917 the item is extracted from the tvbuff handed to it. */
2918static proto_item *
2919proto_tree_new_item(field_info *new_fi, proto_tree *tree,
2920 tvbuff_t *tvb, unsigned start, int length,
2921 unsigned encoding)
2922{
2923 proto_item *pi;
2924 uint32_t value, n;
2925 uint64_t value64;
2926 ws_in4_addr ipv4_value;
2927 float floatval;
2928 double doubleval;
2929 const char *stringval = NULL((void*)0);
2930 nstime_t time_stamp;
2931 bool_Bool length_error;
2932 unsigned item_length;
1
'item_length' declared without an initial value
2933
2934 // new_fi->value is allocated from the packet-scoped pool (see
2935 // new_field_info()), so if a tvbuff accessor below throws before the
2936 // node is added to the tree the fvalue_t structure is still reclaimed
2937 // when the pool is freed; no explicit cleanup handler is needed. This
2938 // relies on the invariant that the type-specific data an fvalue owns
2939 // (byte arrays, string buffers, ...) is only allocated *after* the
2940 // throwing tvbuff read that produced it succeeds, so nothing that would
2941 // need fvalue_cleanup() is ever leaked on the exception path.
2942 switch (new_fi->hfinfo->type) {
2
Control jumps to 'case FT_NONE:' at line 2943
2943 case FT_NONE:
2944 /* no value to set for FT_NONE */
2945 break;
2946
2947 case FT_PROTOCOL:
2948 /* Set the protocol_tvb via the start offset, but include
2949 * rest of the ds_tvb so that if finfo_set_len is called
2950 * later it can be lengthened as much as possible. */
2951 proto_tree_set_protocol_tvb(new_fi, new_fi->ds_tvb ? tvb_new_subset_remaining(new_fi->ds_tvb, new_fi->start) : NULL((void*)0), new_fi->hfinfo->name, length);
2952 break;
2953
2954 case FT_BYTES:
2955 proto_tree_set_bytes_tvb(new_fi, tvb, start, length);
2956 break;
2957
2958 case FT_UINT_BYTES:
2959 n = get_uint_value(tree, tvb, start, length, encoding);
2960 proto_tree_set_bytes_tvb(new_fi, tvb, start + length, n);
2961
2962 /* Instead of calling proto_item_set_len(), since we don't yet
2963 * have a proto_item, we set the field_info's length ourselves. */
2964 new_fi->length = n + length;
2965 break;
2966
2967 case FT_BOOLEAN:
2968 /*
2969 * Map all non-zero values to little-endian for
2970 * backwards compatibility.
2971 */
2972 if (encoding)
2973 encoding = ENC_LITTLE_ENDIAN0x80000000;
2974 proto_tree_set_boolean(new_fi,
2975 get_uint64_value(tree, tvb, start, length, encoding));
2976 break;
2977
2978 case FT_CHAR:
2979 /* XXX - make these just FT_UINT? */
2980 case FT_UINT8:
2981 case FT_UINT16:
2982 case FT_UINT24:
2983 case FT_UINT32:
2984 if (encoding & ENC_VARINT_MASK(0x00000002|0x00000004|0x00000008|0x00000010)) {
2985 new_fi->length = tvb_get_varint(tvb, start, (length == -1) ? FT_VARINT_MAX_LEN10 : length, &value64, encoding);
2986 value = (uint32_t)value64;
2987 if (!(encoding & ENC_VARINT_QUIC0x00000004)) {
2988 new_fi->flags |= FI_VARINT0x00040000;
2989 }
2990 }
2991 else {
2992 /*
2993 * Map all non-zero values to little-endian for
2994 * backwards compatibility.
2995 */
2996 if (encoding)
2997 encoding = ENC_LITTLE_ENDIAN0x80000000;
2998
2999 value = get_uint_value(tree, tvb, start, length, encoding);
3000 }
3001 proto_tree_set_uint(new_fi, value);
3002 break;
3003
3004 case FT_UINT40:
3005 case FT_UINT48:
3006 case FT_UINT56:
3007 case FT_UINT64:
3008 if (encoding & ENC_VARINT_MASK(0x00000002|0x00000004|0x00000008|0x00000010)) {
3009 new_fi->length = tvb_get_varint(tvb, start, (length == -1) ? FT_VARINT_MAX_LEN10 : length, &value64, encoding);
3010 if (!(encoding & ENC_VARINT_QUIC0x00000004)) {
3011 new_fi->flags |= FI_VARINT0x00040000;
3012 }
3013 }
3014 else {
3015 /*
3016 * Map all other non-zero values to little-endian for
3017 * backwards compatibility.
3018 */
3019 if (encoding)
3020 encoding = ENC_LITTLE_ENDIAN0x80000000;
3021
3022 value64 = get_uint64_value(tree, tvb, start, length, encoding);
3023 }
3024 proto_tree_set_uint64(new_fi, value64);
3025 break;
3026
3027 /* XXX - make these just FT_INT? */
3028 case FT_INT8:
3029 case FT_INT16:
3030 case FT_INT24:
3031 case FT_INT32:
3032 /*
3033 * Map all non-zero values to little-endian for
3034 * backwards compatibility.
3035 */
3036 if (encoding)
3037 encoding = ENC_LITTLE_ENDIAN0x80000000;
3038 proto_tree_set_int(new_fi,
3039 get_int_value(tree, tvb, start, length, encoding));
3040 break;
3041
3042 case FT_INT40:
3043 case FT_INT48:
3044 case FT_INT56:
3045 case FT_INT64:
3046 /*
3047 * Map all non-zero values to little-endian for
3048 * backwards compatibility.
3049 */
3050 if (encoding)
3051 encoding = ENC_LITTLE_ENDIAN0x80000000;
3052 proto_tree_set_int64(new_fi,
3053 get_int64_value(tree, tvb, start, length, encoding));
3054 break;
3055
3056 case FT_IPv4:
3057 /*
3058 * Map all non-zero values to little-endian for
3059 * backwards compatibility.
3060 */
3061 if (encoding)
3062 encoding = ENC_LITTLE_ENDIAN0x80000000;
3063 if (length != FT_IPv4_LEN4) {
3064 length_error = length < FT_IPv4_LEN4 ? true1 : false0;
3065 report_type_length_mismatch(tree, "an IPv4 address", length, length_error);
3066 }
3067 ipv4_value = tvb_get_ipv4(tvb, start);
3068 /*
3069 * NOTE: to support code written when
3070 * proto_tree_add_item() took a bool as its
3071 * last argument, with false meaning "big-endian"
3072 * and true meaning "little-endian", we treat any
3073 * non-zero value of "encoding" as meaning
3074 * "little-endian".
3075 */
3076 proto_tree_set_ipv4(new_fi, encoding ? GUINT32_SWAP_LE_BE(ipv4_value)(((guint32) ( (((guint32) (ipv4_value) & (guint32) 0x000000ffU
) << 24) | (((guint32) (ipv4_value) & (guint32) 0x0000ff00U
) << 8) | (((guint32) (ipv4_value) & (guint32) 0x00ff0000U
) >> 8) | (((guint32) (ipv4_value) & (guint32) 0xff000000U
) >> 24))))
: ipv4_value);
3077 break;
3078
3079 case FT_IPXNET:
3080 if (length != FT_IPXNET_LEN4) {
3081 length_error = length < FT_IPXNET_LEN4 ? true1 : false0;
3082 report_type_length_mismatch(tree, "an IPXNET address", length, length_error);
3083 }
3084 proto_tree_set_ipxnet(new_fi,
3085 get_uint_value(tree, tvb, start, FT_IPXNET_LEN4, ENC_BIG_ENDIAN0x00000000));
3086 break;
3087
3088 case FT_IPv6:
3089 if (length != FT_IPv6_LEN16) {
3090 length_error = length < FT_IPv6_LEN16 ? true1 : false0;
3091 report_type_length_mismatch(tree, "an IPv6 address", length, length_error);
3092 }
3093 proto_tree_set_ipv6_tvb(new_fi, tvb, start, length);
3094 break;
3095
3096 case FT_FCWWN:
3097 if (length != FT_FCWWN_LEN8) {
3098 length_error = length < FT_FCWWN_LEN8 ? true1 : false0;
3099 report_type_length_mismatch(tree, "an FCWWN address", length, length_error);
3100 }
3101 proto_tree_set_fcwwn_tvb(new_fi, tvb, start, length);
3102 break;
3103
3104 case FT_AX25:
3105 if (length != 7) {
3106 length_error = length < 7 ? true1 : false0;
3107 report_type_length_mismatch(tree, "an AX.25 address", length, length_error);
3108 }
3109 proto_tree_set_ax25_tvb(new_fi, tvb, start);
3110 break;
3111
3112 case FT_VINES:
3113 if (length != VINES_ADDR_LEN6) {
3114 length_error = length < VINES_ADDR_LEN6 ? true1 : false0;
3115 report_type_length_mismatch(tree, "a Vines address", length, length_error);
3116 }
3117 proto_tree_set_vines_tvb(new_fi, tvb, start);
3118 break;
3119
3120 case FT_ETHER:
3121 if (length != FT_ETHER_LEN6) {
3122 length_error = length < FT_ETHER_LEN6 ? true1 : false0;
3123 report_type_length_mismatch(tree, "a MAC address", length, length_error);
3124 }
3125 proto_tree_set_ether_tvb(new_fi, tvb, start);
3126 break;
3127
3128 case FT_EUI64:
3129 /*
3130 * Map all non-zero values to little-endian for
3131 * backwards compatibility.
3132 */
3133 if (encoding)
3134 encoding = ENC_LITTLE_ENDIAN0x80000000;
3135 if (length != FT_EUI64_LEN8) {
3136 length_error = length < FT_EUI64_LEN8 ? true1 : false0;
3137 report_type_length_mismatch(tree, "an EUI-64 address", length, length_error);
3138 }
3139 proto_tree_set_eui64_tvb(new_fi, tvb, start, encoding);
3140 break;
3141 case FT_GUID:
3142 /*
3143 * Map all non-zero values to little-endian for
3144 * backwards compatibility.
3145 */
3146 if (encoding)
3147 encoding = ENC_LITTLE_ENDIAN0x80000000;
3148 if (length != FT_GUID_LEN16) {
3149 length_error = length < FT_GUID_LEN16 ? true1 : false0;
3150 report_type_length_mismatch(tree, "a GUID", length, length_error);
3151 }
3152 proto_tree_set_guid_tvb(new_fi, tvb, start, encoding);
3153 break;
3154
3155 case FT_OID:
3156 case FT_REL_OID:
3157 proto_tree_set_oid_tvb(new_fi, tvb, start, length);
3158 break;
3159
3160 case FT_SYSTEM_ID:
3161 proto_tree_set_system_id_tvb(new_fi, tvb, start, length);
3162 break;
3163
3164 case FT_FLOAT:
3165 /*
3166 * NOTE: to support code written when
3167 * proto_tree_add_item() took a bool as its
3168 * last argument, with false meaning "big-endian"
3169 * and true meaning "little-endian", we treat any
3170 * non-zero value of "encoding" as meaning
3171 * "little-endian".
3172 *
3173 * At some point in the future, we might
3174 * support non-IEEE-binary floating-point
3175 * formats in the encoding as well
3176 * (IEEE decimal, System/3x0, VAX).
3177 */
3178 if (encoding)
3179 encoding = ENC_LITTLE_ENDIAN0x80000000;
3180 if (length != 4) {
3181 length_error = length < 4 ? true1 : false0;
3182 report_type_length_mismatch(tree, "a single-precision floating point number", length, length_error);
3183 }
3184 if (encoding)
3185 floatval = tvb_get_letohieee_float(tvb, start);
3186 else
3187 floatval = tvb_get_ntohieee_float(tvb, start);
3188 proto_tree_set_float(new_fi, floatval);
3189 break;
3190
3191 case FT_DOUBLE:
3192 /*
3193 * NOTE: to support code written when
3194 * proto_tree_add_item() took a bool as its
3195 * last argument, with false meaning "big-endian"
3196 * and true meaning "little-endian", we treat any
3197 * non-zero value of "encoding" as meaning
3198 * "little-endian".
3199 *
3200 * At some point in the future, we might
3201 * support non-IEEE-binary floating-point
3202 * formats in the encoding as well
3203 * (IEEE decimal, System/3x0, VAX).
3204 */
3205 if (encoding == true1)
3206 encoding = ENC_LITTLE_ENDIAN0x80000000;
3207 if (length != 8) {
3208 length_error = length < 8 ? true1 : false0;
3209 report_type_length_mismatch(tree, "a double-precision floating point number", length, length_error);
3210 }
3211 if (encoding)
3212 doubleval = tvb_get_letohieee_double(tvb, start);
3213 else
3214 doubleval = tvb_get_ntohieee_double(tvb, start);
3215 proto_tree_set_double(new_fi, doubleval);
3216 break;
3217
3218 case FT_STRING:
3219 stringval = (const char*)get_string_value(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool),
3220 tvb, start, length, &item_length, encoding);
3221 proto_tree_set_string(new_fi, stringval);
3222
3223 /* Instead of calling proto_item_set_len(), since we
3224 * don't yet have a proto_item, we set the
3225 * field_info's length ourselves.
3226 *
3227 * XXX - our caller can't use that length to
3228 * advance an offset unless they arrange that
3229 * there always be a protocol tree into which
3230 * we're putting this item.
3231 */
3232 new_fi->length = item_length;
3233 break;
3234
3235 case FT_STRINGZ:
3236 stringval = (const char*)get_stringz_value(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool),
3237 tree, tvb, start, length, &item_length, encoding);
3238 proto_tree_set_string(new_fi, stringval);
3239
3240 /* Instead of calling proto_item_set_len(),
3241 * since we don't yet have a proto_item, we
3242 * set the field_info's length ourselves.
3243 *
3244 * XXX - our caller can't use that length to
3245 * advance an offset unless they arrange that
3246 * there always be a protocol tree into which
3247 * we're putting this item.
3248 */
3249 new_fi->length = item_length;
3250 break;
3251
3252 case FT_UINT_STRING:
3253 /*
3254 * NOTE: to support code written when
3255 * proto_tree_add_item() took a bool as its
3256 * last argument, with false meaning "big-endian"
3257 * and true meaning "little-endian", if the
3258 * encoding value is true, treat that as
3259 * ASCII with a little-endian length.
3260 *
3261 * This won't work for code that passes
3262 * arbitrary non-zero values; that code
3263 * will need to be fixed.
3264 */
3265 if (encoding == true1)
3266 encoding = ENC_ASCII0x00000000|ENC_LITTLE_ENDIAN0x80000000;
3267 stringval = (const char*)get_uint_string_value(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool),
3268 tree, tvb, start, length, &item_length, encoding);
3269 proto_tree_set_string(new_fi, stringval);
3270
3271 /* Instead of calling proto_item_set_len(), since we
3272 * don't yet have a proto_item, we set the
3273 * field_info's length ourselves.
3274 *
3275 * XXX - our caller can't use that length to
3276 * advance an offset unless they arrange that
3277 * there always be a protocol tree into which
3278 * we're putting this item.
3279 */
3280 new_fi->length = item_length;
3281 break;
3282
3283 case FT_STRINGZPAD:
3284 stringval = (const char*)get_stringzpad_value(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool),
3285 tvb, start, length, &item_length, encoding);
3286 proto_tree_set_string(new_fi, stringval);
3287
3288 /* Instead of calling proto_item_set_len(), since we
3289 * don't yet have a proto_item, we set the
3290 * field_info's length ourselves.
3291 *
3292 * XXX - our caller can't use that length to
3293 * advance an offset unless they arrange that
3294 * there always be a protocol tree into which
3295 * we're putting this item.
3296 */
3297 new_fi->length = item_length;
3298 break;
3299
3300 case FT_STRINGZTRUNC:
3301 stringval = (const char*)get_stringztrunc_value(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool),
3302 tvb, start, length, &item_length, encoding);
3303 proto_tree_set_string(new_fi, stringval);
3304
3305 /* Instead of calling proto_item_set_len(), since we
3306 * don't yet have a proto_item, we set the
3307 * field_info's length ourselves.
3308 *
3309 * XXX - our caller can't use that length to
3310 * advance an offset unless they arrange that
3311 * there always be a protocol tree into which
3312 * we're putting this item.
3313 */
3314 new_fi->length = item_length;
3315 break;
3316
3317 case FT_ABSOLUTE_TIME:
3318 /*
3319 * Absolute times can be in any of a number of
3320 * formats, and they can be big-endian or
3321 * little-endian.
3322 *
3323 * Historically FT_TIMEs were only timespecs;
3324 * the only question was whether they were stored
3325 * in big- or little-endian format.
3326 *
3327 * For backwards compatibility, we interpret an
3328 * encoding of 1 as meaning "little-endian timespec",
3329 * so that passing true is interpreted as that.
3330 */
3331 if (encoding == true1)
3332 encoding = ENC_TIME_SECS_NSECS0x00000000|ENC_LITTLE_ENDIAN0x80000000;
3333
3334 get_time_value(tree, tvb, start, length, encoding, &time_stamp, false0);
3335
3336 proto_tree_set_time(new_fi, &time_stamp);
3337 break;
3338
3339 case FT_RELATIVE_TIME:
3340 /*
3341 * Relative times can be in any of a number of
3342 * formats, and they can be big-endian or
3343 * little-endian.
3344 *
3345 * Historically FT_TIMEs were only timespecs;
3346 * the only question was whether they were stored
3347 * in big- or little-endian format.
3348 *
3349 * For backwards compatibility, we interpret an
3350 * encoding of 1 as meaning "little-endian timespec",
3351 * so that passing true is interpreted as that.
3352 */
3353 if (encoding == true1)
3354 encoding = ENC_TIME_SECS_NSECS0x00000000|ENC_LITTLE_ENDIAN0x80000000;
3355
3356 get_time_value(tree, tvb, start, length, encoding, &time_stamp, true1);
3357
3358 proto_tree_set_time(new_fi, &time_stamp);
3359 break;
3360 case FT_IEEE_11073_SFLOAT:
3361 if (encoding)
3362 encoding = ENC_LITTLE_ENDIAN0x80000000;
3363 if (length != 2) {
3364 length_error = length < 2 ? true1 : false0;
3365 report_type_length_mismatch(tree, "a IEEE 11073 SFLOAT", length, length_error);
3366 }
3367
3368 fvalue_set_uinteger(new_fi->value, tvb_get_uint16(tvb, start, encoding));
3369
3370 break;
3371 case FT_IEEE_11073_FLOAT:
3372 if (encoding)
3373 encoding = ENC_LITTLE_ENDIAN0x80000000;
3374 if (length != 4) {
3375 length_error = length < 4 ? true1 : false0;
3376 report_type_length_mismatch(tree, "a IEEE 11073 FLOAT", length, length_error);
3377 }
3378 fvalue_set_uinteger(new_fi->value, tvb_get_uint32(tvb, start, encoding));
3379
3380 break;
3381 default:
3382 REPORT_DISSECTOR_BUG("field %s is of unknown type %d (%s)",proto_report_dissector_bug("field %s is of unknown type %d (%s)"
, new_fi->hfinfo->abbrev, new_fi->hfinfo->type, ftype_name
(new_fi->hfinfo->type))
3383 new_fi->hfinfo->abbrev,proto_report_dissector_bug("field %s is of unknown type %d (%s)"
, new_fi->hfinfo->abbrev, new_fi->hfinfo->type, ftype_name
(new_fi->hfinfo->type))
3384 new_fi->hfinfo->type,proto_report_dissector_bug("field %s is of unknown type %d (%s)"
, new_fi->hfinfo->abbrev, new_fi->hfinfo->type, ftype_name
(new_fi->hfinfo->type))
3385 ftype_name(new_fi->hfinfo->type))proto_report_dissector_bug("field %s is of unknown type %d (%s)"
, new_fi->hfinfo->abbrev, new_fi->hfinfo->type, ftype_name
(new_fi->hfinfo->type))
;
3386 break;
3387 }
3388 FI_SET_FLAG(new_fi, (encoding & ENC_LITTLE_ENDIAN) ? FI_LITTLE_ENDIAN : FI_BIG_ENDIAN)do { if (new_fi) (new_fi)->flags = (new_fi)->flags | ((
encoding & 0x80000000) ? 0x00000008 : 0x00000010); } while
(0)
;
3
Execution continues on line 3388
4
Taking true branch
5
Assuming the condition is false
6
'?' condition is false
7
Loop condition is false. Exiting loop
3389
3390 /* Don't add new node to proto_tree until now so that any exceptions
3391 * raised by a tvbuff access method doesn't leave junk in the proto_tree. */
3392 /* XXX. wouldn't be better to add this item to tree, with some special
3393 * flag (FI_EXCEPTION?) to know which item caused exception? For
3394 * strings and bytes, we would have to set new_fi->value to something
3395 * non-NULL, or otherwise ensure that proto_item_fill_display_label
3396 * could handle NULL values. */
3397 pi = proto_tree_add_node(tree, new_fi);
3398
3399 switch (new_fi->hfinfo->type) {
8
Control jumps to 'case FT_STRING:' at line 3401
3400
3401 case FT_STRING:
3402 /* XXX: trailing stray character detection should be done
3403 * _before_ conversion to UTF-8, because conversion can change
3404 * the length, or else get_string_length should return a value
3405 * for the "length in bytes of the string after conversion
3406 * including internal nulls." (Noting that we do, for other
3407 * reasons, still need the "length in bytes in the field",
3408 * especially for FT_STRINGZ.)
3409 *
3410 * This is true even for ASCII and UTF-8, because
3411 * substituting REPLACEMENT CHARACTERS for illegal characters
3412 * can also do so (and for UTF-8 possibly even make the
3413 * string _shorter_).
3414 */
3415 detect_trailing_stray_characters(encoding, stringval, item_length, pi);
9
3rd function call argument is an uninitialized value
3416 break;
3417
3418 default:
3419 break;
3420 }
3421
3422 return pi;
3423}
3424
3425proto_item *
3426proto_tree_add_item_ret_int(proto_tree *tree, int hfindex, tvbuff_t *tvb,
3427 const unsigned start, unsigned length,
3428 const unsigned encoding, int32_t *retval)
3429{
3430 header_field_info *hfinfo;
3431 field_info *new_fi;
3432 int32_t value;
3433
3434 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 3434, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 3434,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3434, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
3435
3436 switch (hfinfo->type) {
3437 case FT_INT8:
3438 case FT_INT16:
3439 case FT_INT24:
3440 case FT_INT32:
3441 break;
3442 case FT_INT64:
3443 REPORT_DISSECTOR_BUG("64-bit signed integer field %s used with proto_tree_add_item_ret_int()",proto_report_dissector_bug("64-bit signed integer field %s used with proto_tree_add_item_ret_int()"
, hfinfo->abbrev)
3444 hfinfo->abbrev)proto_report_dissector_bug("64-bit signed integer field %s used with proto_tree_add_item_ret_int()"
, hfinfo->abbrev)
;
3445 default:
3446 REPORT_DISSECTOR_BUG("Non-signed-integer field %s used with proto_tree_add_item_ret_int()",proto_report_dissector_bug("Non-signed-integer field %s used with proto_tree_add_item_ret_int()"
, hfinfo->abbrev)
3447 hfinfo->abbrev)proto_report_dissector_bug("Non-signed-integer field %s used with proto_tree_add_item_ret_int()"
, hfinfo->abbrev)
;
3448 }
3449
3450 CHECK_FOR_ZERO_LENGTH_AND_CLEANUP(length,if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3451 {if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3452 if(retval)if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3453 {if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3454 *retval = 0;if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3455 }if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3456 } )if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
;
3457
3458 if (encoding & ENC_STRING0x07000000) {
3459 REPORT_DISSECTOR_BUG("wrong encoding")proto_report_dissector_bug("wrong encoding");
3460 }
3461 /* I believe it's ok if this is called with a NULL tree */
3462 value = get_int_value(tree, tvb, start, length, encoding);
3463
3464 if (retval) {
3465 int no_of_bits;
3466 *retval = value;
3467 if (hfinfo->bitmask) {
3468 /* Mask out irrelevant portions */
3469 *retval &= (uint32_t)(hfinfo->bitmask);
3470 /* Shift bits */
3471 *retval >>= hfinfo_bitshift(hfinfo);
3472 }
3473 no_of_bits = ws_count_ones(hfinfo->bitmask);
3474 *retval = ws_sign_ext32(*retval, no_of_bits);
3475 }
3476
3477 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
3478
3479 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3479
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3479, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3479, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3479, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
3480
3481 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
3482
3483 proto_tree_set_int(new_fi, value);
3484
3485 new_fi->flags |= (encoding & ENC_LITTLE_ENDIAN0x80000000) ? FI_LITTLE_ENDIAN0x00000008 : FI_BIG_ENDIAN0x00000010;
3486
3487 return proto_tree_add_node(tree, new_fi);
3488}
3489
3490proto_item *
3491proto_tree_add_item_ret_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb,
3492 const unsigned start, unsigned length,
3493 const unsigned encoding, uint32_t *retval)
3494{
3495 header_field_info *hfinfo;
3496 field_info *new_fi;
3497 uint32_t value;
3498
3499 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 3499, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 3499,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3499, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
3500
3501 switch (hfinfo->type) {
3502 case FT_CHAR:
3503 case FT_UINT8:
3504 case FT_UINT16:
3505 case FT_UINT24:
3506 case FT_UINT32:
3507 break;
3508 default:
3509 REPORT_DISSECTOR_BUG("field %s is not of type FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32",proto_report_dissector_bug("field %s is not of type FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32"
, hfinfo->abbrev)
3510 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32"
, hfinfo->abbrev)
;
3511 }
3512
3513 CHECK_FOR_ZERO_LENGTH_AND_CLEANUP(length,if (length == 0) { { if (retval) { *retval = 0; } return ((void
*)0); }; return ((void*)0); }
3514 {if (length == 0) { { if (retval) { *retval = 0; } return ((void
*)0); }; return ((void*)0); }
3515 if (retval) {if (length == 0) { { if (retval) { *retval = 0; } return ((void
*)0); }; return ((void*)0); }
3516 *retval = 0;if (length == 0) { { if (retval) { *retval = 0; } return ((void
*)0); }; return ((void*)0); }
3517 }if (length == 0) { { if (retval) { *retval = 0; } return ((void
*)0); }; return ((void*)0); }
3518 return NULL;if (length == 0) { { if (retval) { *retval = 0; } return ((void
*)0); }; return ((void*)0); }
3519 }if (length == 0) { { if (retval) { *retval = 0; } return ((void
*)0); }; return ((void*)0); }
3520 )if (length == 0) { { if (retval) { *retval = 0; } return ((void
*)0); }; return ((void*)0); }
;
3521
3522 if (encoding & ENC_STRING0x07000000) {
3523 REPORT_DISSECTOR_BUG("wrong encoding")proto_report_dissector_bug("wrong encoding");
3524 }
3525 /* I believe it's ok if this is called with a NULL tree */
3526 /* XXX - modify if we ever support EBCDIC FT_CHAR */
3527 if (encoding & ENC_VARINT_MASK(0x00000002|0x00000004|0x00000008|0x00000010)) {
3528 uint64_t temp64;
3529 tvb_get_varint(tvb, start, length, &temp64, encoding);
3530 value = (uint32_t)temp64;
3531 } else {
3532 value = get_uint_value(tree, tvb, start, length, encoding);
3533 }
3534
3535 if (retval) {
3536 *retval = value;
3537 if (hfinfo->bitmask) {
3538 /* Mask out irrelevant portions */
3539 *retval &= (uint32_t)(hfinfo->bitmask);
3540 /* Shift bits */
3541 *retval >>= hfinfo_bitshift(hfinfo);
3542 }
3543 }
3544
3545 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
3546
3547 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3547
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3547, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3547, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3547, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
3548
3549 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
3550
3551 proto_tree_set_uint(new_fi, value);
3552
3553 new_fi->flags |= (encoding & ENC_LITTLE_ENDIAN0x80000000) ? FI_LITTLE_ENDIAN0x00000008 : FI_BIG_ENDIAN0x00000010;
3554 if (encoding & (ENC_VARINT_PROTOBUF0x00000002|ENC_VARINT_ZIGZAG0x00000008|ENC_VARINT_SDNV0x00000010)) {
3555 new_fi->flags |= FI_VARINT0x00040000;
3556 }
3557 return proto_tree_add_node(tree, new_fi);
3558}
3559
3560proto_item *
3561proto_tree_add_item_ret_uint32(proto_tree *tree, int hfindex, tvbuff_t *tvb,
3562 const unsigned start, unsigned length,
3563 const unsigned encoding, uint32_t *retval)
3564{
3565 return proto_tree_add_item_ret_uint(tree, hfindex, tvb, start, length, encoding, retval);
3566}
3567
3568proto_item *
3569proto_tree_add_item_ret_uint8(proto_tree *tree, int hfindex, tvbuff_t *tvb,
3570 const unsigned start, unsigned length,
3571 const unsigned encoding, uint8_t *retval)
3572{
3573 /* TODO: further restrict by hfinfo->type ? */
3574 uint32_t val32;
3575 proto_item *item = proto_tree_add_item_ret_uint(tree, hfindex, tvb, start, length, encoding, &val32);
3576 *retval = (uint8_t)val32;
3577 return item;
3578}
3579
3580proto_item *
3581proto_tree_add_item_ret_uint16(proto_tree *tree, int hfindex, tvbuff_t *tvb,
3582 const unsigned start, unsigned length,
3583 const unsigned encoding, uint16_t *retval)
3584{
3585 /* TODO: further restrict by hfinfo->type ? */
3586 uint32_t val32;
3587 proto_item *item = proto_tree_add_item_ret_uint(tree, hfindex, tvb, start, length, encoding, &val32);
3588 *retval = (uint16_t)(val32 & 0xFFFF); /* Bitwise AND is a classic 'Reset' for taint */
3589 return item;
3590}
3591
3592
3593/* Gets data from tvbuff, adds it to proto_tree, increments offset,
3594 * and returns proto_item* and uint value retrieved*/
3595proto_item *
3596ptvcursor_add_ret_uint(ptvcursor_t *ptvc, int hfindex, unsigned length,
3597 const unsigned encoding, uint32_t *retval)
3598{
3599 field_info *new_fi;
3600 header_field_info *hfinfo;
3601 unsigned item_length;
3602 unsigned offset;
3603 uint32_t value;
3604
3605 offset = ptvc->offset;
3606 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 3606, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 3606,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3606, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
3607
3608 switch (hfinfo->type) {
3609 case FT_CHAR:
3610 case FT_UINT8:
3611 case FT_UINT16:
3612 case FT_UINT24:
3613 case FT_UINT32:
3614 break;
3615 default:
3616 REPORT_DISSECTOR_BUG("field %s is not of type FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32",proto_report_dissector_bug("field %s is not of type FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32"
, hfinfo->abbrev)
3617 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32"
, hfinfo->abbrev)
;
3618 }
3619
3620 get_hfi_length_unsigned(hfinfo, ptvc->tvb, offset, &length, &item_length, encoding);
3621 test_length(hfinfo, ptvc->tvb, offset, item_length, encoding);
3622
3623 /* I believe it's ok if this is called with a NULL tree */
3624 /* XXX - modify if we ever support EBCDIC FT_CHAR */
3625 value = get_uint_value(ptvc->tree, ptvc->tvb, offset, item_length, encoding);
3626
3627 if (retval) {
3628 *retval = value;
3629 if (hfinfo->bitmask) {
3630 /* Mask out irrelevant portions */
3631 *retval &= (uint32_t)(hfinfo->bitmask);
3632 /* Shift bits */
3633 *retval >>= hfinfo_bitshift(hfinfo);
3634 }
3635 }
3636
3637 ptvcursor_advance(ptvc, get_full_length(hfinfo, ptvc->tvb, offset, length, item_length, encoding));
3638
3639 CHECK_FOR_NULL_TREE(ptvc->tree)if (!ptvc->tree) { ((void)0); return ((void*)0); };
3640
3641 /* Coast clear. Try and fake it */
3642 TRY_TO_FAKE_THIS_ITEM(ptvc->tree, hfindex, hfinfo)((ptvc->tree)->tree_data)->count++; if((hfindex == 0
|| (unsigned)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3642
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3642, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3642, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((ptvc->tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3642, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((ptvc->tree
)->tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((ptvc->tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((ptvc
->tree)->tree_data)->visible)) { if (proto_item_is_hidden
((ptvc->tree))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT
) && (hfinfo->ref_type != HF_REF_TYPE_PRINT) &&
(hfinfo->type != FT_PROTOCOL || ((ptvc->tree)->tree_data
)->fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(ptvc->tree, hfinfo); } } }
;
3643
3644 new_fi = new_field_info(ptvc->tree, hfinfo, ptvc->tvb, offset, item_length);
3645
3646 return proto_tree_new_item(new_fi, ptvc->tree, ptvc->tvb,
3647 offset, length, encoding);
3648}
3649
3650/* Gets data from tvbuff, adds it to proto_tree, increments offset,
3651 * and returns proto_item* and int value retrieved*/
3652proto_item *
3653ptvcursor_add_ret_int(ptvcursor_t *ptvc, int hfindex, unsigned length,
3654 const unsigned encoding, int32_t *retval)
3655{
3656 field_info *new_fi;
3657 header_field_info *hfinfo;
3658 unsigned item_length;
3659 unsigned offset;
3660 uint32_t value;
3661
3662 offset = ptvc->offset;
3663 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 3663, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 3663,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3663, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
3664
3665 switch (hfinfo->type) {
3666 case FT_INT8:
3667 case FT_INT16:
3668 case FT_INT24:
3669 case FT_INT32:
3670 break;
3671 default:
3672 REPORT_DISSECTOR_BUG("field %s is not of type FT_INT8, FT_INT16, FT_INT24, or FT_INT32",proto_report_dissector_bug("field %s is not of type FT_INT8, FT_INT16, FT_INT24, or FT_INT32"
, hfinfo->abbrev)
3673 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_INT8, FT_INT16, FT_INT24, or FT_INT32"
, hfinfo->abbrev)
;
3674 }
3675
3676 get_hfi_length_unsigned(hfinfo, ptvc->tvb, offset, &length, &item_length, encoding);
3677 test_length(hfinfo, ptvc->tvb, offset, item_length, encoding);
3678
3679 /* I believe it's ok if this is called with a NULL tree */
3680 /* XXX - modify if we ever support EBCDIC FT_CHAR */
3681 value = get_int_value(ptvc->tree, ptvc->tvb, offset, item_length, encoding);
3682
3683 if (retval) {
3684 int no_of_bits;
3685 *retval = value;
3686 if (hfinfo->bitmask) {
3687 /* Mask out irrelevant portions */
3688 *retval &= (uint32_t)(hfinfo->bitmask);
3689 /* Shift bits */
3690 *retval >>= hfinfo_bitshift(hfinfo);
3691 }
3692 no_of_bits = ws_count_ones(hfinfo->bitmask);
3693 *retval = ws_sign_ext32(*retval, no_of_bits);
3694 }
3695
3696 ptvcursor_advance(ptvc, get_full_length(hfinfo, ptvc->tvb, offset, length, item_length, encoding));
3697
3698 CHECK_FOR_NULL_TREE(ptvc->tree)if (!ptvc->tree) { ((void)0); return ((void*)0); };
3699
3700 /* Coast clear. Try and fake it */
3701 TRY_TO_FAKE_THIS_ITEM(ptvc->tree, hfindex, hfinfo)((ptvc->tree)->tree_data)->count++; if((hfindex == 0
|| (unsigned)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3701
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3701, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3701, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((ptvc->tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3701, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((ptvc->tree
)->tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((ptvc->tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((ptvc
->tree)->tree_data)->visible)) { if (proto_item_is_hidden
((ptvc->tree))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT
) && (hfinfo->ref_type != HF_REF_TYPE_PRINT) &&
(hfinfo->type != FT_PROTOCOL || ((ptvc->tree)->tree_data
)->fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(ptvc->tree, hfinfo); } } }
;
3702
3703 new_fi = new_field_info(ptvc->tree, hfinfo, ptvc->tvb, offset, item_length);
3704
3705 return proto_tree_new_item(new_fi, ptvc->tree, ptvc->tvb,
3706 offset, length, encoding);
3707}
3708
3709/* Gets data from tvbuff, adds it to proto_tree, increments offset,
3710 * and returns proto_item* and string value retrieved */
3711proto_item*
3712ptvcursor_add_ret_string(ptvcursor_t* ptvc, int hf, int length, const unsigned encoding, wmem_allocator_t *scope, const uint8_t **retval)
3713{
3714 header_field_info *hfinfo;
3715 field_info *new_fi;
3716 const uint8_t *value;
3717 unsigned item_length;
3718 unsigned offset;
3719
3720 offset = ptvc->offset;
3721
3722 PROTO_REGISTRAR_GET_NTH(hf, hfinfo)if((hf == 0 || (unsigned)hf > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3722
, __func__, "Unregistered hf! index=%d", hf); ((void) ((hf >
0 && (unsigned)hf < gpa_hfinfo.len) ? (void)0 : (
proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3722, "hf > 0 && (unsigned)hf < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hf] != ((
void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3722, "gpa_hfinfo.hfi[hf] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[hf];
;
3723
3724 switch (hfinfo->type) {
3725 case FT_STRING:
3726 value = get_string_value(scope, ptvc->tvb, offset, length, &item_length, encoding);
3727 break;
3728 case FT_STRINGZ:
3729 value = get_stringz_value(scope, ptvc->tree, ptvc->tvb, offset, length, &item_length, encoding);
3730 break;
3731 case FT_UINT_STRING:
3732 value = get_uint_string_value(scope, ptvc->tree, ptvc->tvb, offset, length, &item_length, encoding);
3733 break;
3734 case FT_STRINGZPAD:
3735 value = get_stringzpad_value(scope, ptvc->tvb, offset, length, &item_length, encoding);
3736 break;
3737 case FT_STRINGZTRUNC:
3738 value = get_stringztrunc_value(scope, ptvc->tvb, offset, length, &item_length, encoding);
3739 break;
3740 default:
3741 REPORT_DISSECTOR_BUG("field %s is not of type FT_STRING, FT_STRINGZ, FT_UINT_STRING, FT_STRINGZPAD, or FT_STRINGZTRUNC",proto_report_dissector_bug("field %s is not of type FT_STRING, FT_STRINGZ, FT_UINT_STRING, FT_STRINGZPAD, or FT_STRINGZTRUNC"
, hfinfo->abbrev)
3742 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_STRING, FT_STRINGZ, FT_UINT_STRING, FT_STRINGZPAD, or FT_STRINGZTRUNC"
, hfinfo->abbrev)
;
3743 }
3744
3745 if (retval)
3746 *retval = value;
3747
3748 ptvcursor_advance(ptvc, item_length);
3749
3750 CHECK_FOR_NULL_TREE(ptvc->tree)if (!ptvc->tree) { ((void)0); return ((void*)0); };
3751
3752 TRY_TO_FAKE_THIS_ITEM(ptvc->tree, hfinfo->id, hfinfo)((ptvc->tree)->tree_data)->count++; if((hfinfo->id
== 0 || (unsigned)hfinfo->id > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 3752, __func__, "Unregistered hf! index=%d"
, hfinfo->id); ((void) ((hfinfo->id > 0 && (
unsigned)hfinfo->id < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 3752,
"hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3752, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((ptvc->tree)->tree_data)->count > prefs
.gui_max_tree_items) { ((void)0); if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3752
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((ptvc->tree
)->tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((ptvc->tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((ptvc
->tree)->tree_data)->visible)) { if (proto_item_is_hidden
((ptvc->tree))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT
) && (hfinfo->ref_type != HF_REF_TYPE_PRINT) &&
(hfinfo->type != FT_PROTOCOL || ((ptvc->tree)->tree_data
)->fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(ptvc->tree, hfinfo); } } }
;
3753
3754 new_fi = new_field_info(ptvc->tree, hfinfo, ptvc->tvb, offset, item_length);
3755
3756 return proto_tree_new_item(new_fi, ptvc->tree, ptvc->tvb,
3757 offset, length, encoding);
3758}
3759
3760/* Gets data from tvbuff, adds it to proto_tree, increments offset,
3761 * and returns proto_item* and boolean value retrieved */
3762proto_item*
3763ptvcursor_add_ret_boolean(ptvcursor_t* ptvc, int hfindex, unsigned length, const unsigned encoding, bool_Bool *retval)
3764{
3765 header_field_info *hfinfo;
3766 field_info *new_fi;
3767 unsigned item_length;
3768 unsigned offset;
3769 uint64_t value, bitval;
3770
3771 offset = ptvc->offset;
3772 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 3772, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 3772,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3772, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
3773
3774 if (hfinfo->type != FT_BOOLEAN) {
3775 REPORT_DISSECTOR_BUG("field %s is not of type FT_BOOLEAN",proto_report_dissector_bug("field %s is not of type FT_BOOLEAN"
, hfinfo->abbrev)
3776 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_BOOLEAN"
, hfinfo->abbrev)
;
3777 }
3778
3779 CHECK_FOR_ZERO_LENGTH_AND_CLEANUP(length,if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3780 {if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3781 if(retval)if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3782 {if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3783 *retval = false;if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3784 }if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3785 } )if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
;
3786
3787 if (encoding & ENC_STRING0x07000000) {
3788 REPORT_DISSECTOR_BUG("wrong encoding")proto_report_dissector_bug("wrong encoding");
3789 }
3790
3791 get_hfi_length_unsigned(hfinfo, ptvc->tvb, offset, &length, &item_length, encoding);
3792 test_length(hfinfo, ptvc->tvb, offset, item_length, encoding);
3793
3794 /* I believe it's ok if this is called with a NULL tree */
3795 value = get_uint64_value(ptvc->tree, ptvc->tvb, offset, length, encoding);
3796
3797 if (retval) {
3798 bitval = value;
3799 if (hfinfo->bitmask) {
3800 /* Mask out irrelevant portions */
3801 bitval &= hfinfo->bitmask;
3802 }
3803 *retval = (bitval != 0);
3804 }
3805
3806 ptvcursor_advance(ptvc, get_full_length(hfinfo, ptvc->tvb, offset, length, item_length, encoding));
3807
3808 CHECK_FOR_NULL_TREE(ptvc->tree)if (!ptvc->tree) { ((void)0); return ((void*)0); };
3809
3810 TRY_TO_FAKE_THIS_ITEM(ptvc->tree, hfinfo->id, hfinfo)((ptvc->tree)->tree_data)->count++; if((hfinfo->id
== 0 || (unsigned)hfinfo->id > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 3810, __func__, "Unregistered hf! index=%d"
, hfinfo->id); ((void) ((hfinfo->id > 0 && (
unsigned)hfinfo->id < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 3810,
"hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3810, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((ptvc->tree)->tree_data)->count > prefs
.gui_max_tree_items) { ((void)0); if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3810
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((ptvc->tree
)->tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((ptvc->tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((ptvc
->tree)->tree_data)->visible)) { if (proto_item_is_hidden
((ptvc->tree))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT
) && (hfinfo->ref_type != HF_REF_TYPE_PRINT) &&
(hfinfo->type != FT_PROTOCOL || ((ptvc->tree)->tree_data
)->fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(ptvc->tree, hfinfo); } } }
;
3811
3812 new_fi = new_field_info(ptvc->tree, hfinfo, ptvc->tvb, offset, item_length);
3813
3814 return proto_tree_new_item(new_fi, ptvc->tree, ptvc->tvb,
3815 offset, length, encoding);
3816}
3817
3818proto_item *
3819proto_tree_add_item_ret_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb,
3820 const unsigned start, unsigned length, const unsigned encoding, uint64_t *retval)
3821{
3822 header_field_info *hfinfo;
3823 field_info *new_fi;
3824 uint64_t value;
3825
3826 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 3826, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 3826,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3826, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
3827
3828 switch (hfinfo->type) {
3829 case FT_UINT40:
3830 case FT_UINT48:
3831 case FT_UINT56:
3832 case FT_UINT64:
3833 break;
3834 default:
3835 REPORT_DISSECTOR_BUG("field %s is not of type FT_UINT40, FT_UINT48, FT_UINT56, or FT_UINT64",proto_report_dissector_bug("field %s is not of type FT_UINT40, FT_UINT48, FT_UINT56, or FT_UINT64"
, hfinfo->abbrev)
3836 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_UINT40, FT_UINT48, FT_UINT56, or FT_UINT64"
, hfinfo->abbrev)
;
3837 }
3838
3839 CHECK_FOR_ZERO_LENGTH_AND_CLEANUP(length,if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3840 {if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3841 if(retval)if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3842 {if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3843 *retval = 0;if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3844 }if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3845 } )if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
;
3846
3847 if (encoding & ENC_STRING0x07000000) {
3848 REPORT_DISSECTOR_BUG("wrong encoding")proto_report_dissector_bug("wrong encoding");
3849 }
3850 /* I believe it's ok if this is called with a NULL tree */
3851 if (encoding & ENC_VARINT_MASK(0x00000002|0x00000004|0x00000008|0x00000010)) {
3852 tvb_get_varint(tvb, start, length, &value, encoding);
3853 } else {
3854 value = get_uint64_value(tree, tvb, start, length, encoding);
3855 }
3856
3857 if (retval) {
3858 *retval = value;
3859 if (hfinfo->bitmask) {
3860 /* Mask out irrelevant portions */
3861 *retval &= hfinfo->bitmask;
3862 /* Shift bits */
3863 *retval >>= hfinfo_bitshift(hfinfo);
3864 }
3865 }
3866
3867 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
3868
3869 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3869
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3869, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3869, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3869, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
3870
3871 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
3872
3873 proto_tree_set_uint64(new_fi, value);
3874
3875 new_fi->flags |= (encoding & ENC_LITTLE_ENDIAN0x80000000) ? FI_LITTLE_ENDIAN0x00000008 : FI_BIG_ENDIAN0x00000010;
3876 if (encoding & (ENC_VARINT_PROTOBUF0x00000002|ENC_VARINT_ZIGZAG0x00000008|ENC_VARINT_SDNV0x00000010)) {
3877 new_fi->flags |= FI_VARINT0x00040000;
3878 }
3879
3880 return proto_tree_add_node(tree, new_fi);
3881}
3882
3883proto_item *
3884proto_tree_add_item_ret_int64(proto_tree *tree, int hfindex, tvbuff_t *tvb,
3885 const unsigned start, unsigned length, const unsigned encoding, int64_t *retval)
3886{
3887 header_field_info *hfinfo;
3888 field_info *new_fi;
3889 int64_t value;
3890
3891 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 3891, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 3891,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3891, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
3892
3893 switch (hfinfo->type) {
3894 case FT_INT40:
3895 case FT_INT48:
3896 case FT_INT56:
3897 case FT_INT64:
3898 break;
3899 default:
3900 REPORT_DISSECTOR_BUG("field %s is not of type FT_INT40, FT_INT48, FT_INT56, or FT_INT64",proto_report_dissector_bug("field %s is not of type FT_INT40, FT_INT48, FT_INT56, or FT_INT64"
, hfinfo->abbrev)
3901 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_INT40, FT_INT48, FT_INT56, or FT_INT64"
, hfinfo->abbrev)
;
3902 }
3903
3904 CHECK_FOR_ZERO_LENGTH_AND_CLEANUP(length,if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3905 {if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3906 if(retval)if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3907 {if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3908 *retval = 0;if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3909 }if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
3910 } )if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
;
3911
3912 if (encoding & ENC_STRING0x07000000) {
3913 REPORT_DISSECTOR_BUG("wrong encoding")proto_report_dissector_bug("wrong encoding");
3914 }
3915 /* I believe it's ok if this is called with a NULL tree */
3916 if (encoding & ENC_VARINT_MASK(0x00000002|0x00000004|0x00000008|0x00000010)) {
3917 tvb_get_varint(tvb, start, length, (uint64_t*)&value, encoding);
3918 }
3919 else {
3920 value = get_int64_value(tree, tvb, start, length, encoding);
3921 }
3922
3923 if (retval) {
3924 *retval = value;
3925 }
3926
3927 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
3928
3929 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3929
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3929, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3929, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 3929, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
3930
3931 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
3932
3933 proto_tree_set_int64(new_fi, value);
3934
3935 new_fi->flags |= (encoding & ENC_LITTLE_ENDIAN0x80000000) ? FI_LITTLE_ENDIAN0x00000008 : FI_BIG_ENDIAN0x00000010;
3936 if (encoding & (ENC_VARINT_PROTOBUF0x00000002|ENC_VARINT_ZIGZAG0x00000008|ENC_VARINT_SDNV0x00000010)) {
3937 new_fi->flags |= FI_VARINT0x00040000;
3938 }
3939
3940 return proto_tree_add_node(tree, new_fi);
3941}
3942
3943proto_item *
3944proto_tree_add_item_ret_varint(proto_tree *tree, int hfindex, tvbuff_t *tvb,
3945 const unsigned start, unsigned length, const unsigned encoding, uint64_t *retval, unsigned *lenretval)
3946{
3947 header_field_info *hfinfo;
3948 field_info *new_fi;
3949 uint64_t value;
3950
3951 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 3951, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 3951,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 3951, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
3952
3953 if ((!FT_IS_INT(hfinfo->type)(((hfinfo->type) == FT_INT8 || (hfinfo->type) == FT_INT16
|| (hfinfo->type) == FT_INT24 || (hfinfo->type) == FT_INT32
) || ((hfinfo->type) == FT_INT40 || (hfinfo->type) == FT_INT48
|| (hfinfo->type) == FT_INT56 || (hfinfo->type) == FT_INT64
))
) && (!FT_IS_UINT(hfinfo->type)(((hfinfo->type) == FT_CHAR || (hfinfo->type) == FT_UINT8
|| (hfinfo->type) == FT_UINT16 || (hfinfo->type) == FT_UINT24
|| (hfinfo->type) == FT_UINT32 || (hfinfo->type) == FT_FRAMENUM
) || ((hfinfo->type) == FT_UINT40 || (hfinfo->type) == FT_UINT48
|| (hfinfo->type) == FT_UINT56 || (hfinfo->type) == FT_UINT64
))
)) {
3954 REPORT_DISSECTOR_BUG("field %s is not of type FT_UINT or FT_INT",proto_report_dissector_bug("field %s is not of type FT_UINT or FT_INT"
, hfinfo->abbrev)
3955 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_UINT or FT_INT"
, hfinfo->abbrev)
;
3956 }
3957
3958 if (!(encoding & ENC_VARINT_MASK(0x00000002|0x00000004|0x00000008|0x00000010))) {
3959 REPORT_DISSECTOR_BUG("Encoding must be a VARINT")proto_report_dissector_bug("Encoding must be a VARINT");
3960 }
3961
3962 if (encoding & ENC_STRING0x07000000) {
3963 REPORT_DISSECTOR_BUG("wrong encoding")proto_report_dissector_bug("wrong encoding");
3964 }
3965
3966 /* tvb_get_varint clamps the max length to FT_VARINT_MAX_LEN (10)
3967 * It also handles length 0, setting both return values to 0.
3968 * XXX - Should the max length be affected by the field type and/or
3969 * encoding, e.g. 5 for FT_[U]INT32?
3970 * XXX - Should there be separate _varint and _varuint versions to
3971 * avoid the changing the sign when casting the return value?
3972 * XXX - Do we even need the length parameter? Every user of this
3973 * function passes in -1 or FT_VARINT_MAX_LEN. We could have a
3974 * separate function, but unlike some field types, variable length
3975 * is the typical case here, not the exception, and the typical
3976 * case should have the shorter, more convenient function name.
3977 * Having the length makes the signature more similar to other
3978 * functions, though. */
3979 length = tvb_get_varint(tvb, start, length, &value, encoding);
3980
3981 if (length == 0) {
3982 expert_add_info(NULL((void*)0), tree, &ei_varint_decoding_failed_error);
3983 THROW(ReportedBoundsError)except_throw(1, (3), ((void*)0));
3984 }
3985
3986 if (retval) {
3987 *retval = value;
3988 if (hfinfo->bitmask) {
3989 /* Mask out irrelevant portions */
3990 *retval &= hfinfo->bitmask;
3991 /* Shift bits */
3992 *retval >>= hfinfo_bitshift(hfinfo);
3993 }
3994 }
3995
3996 if (lenretval) {
3997 *lenretval = length;
3998 }
3999
4000 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4001
4002 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4002
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4002, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4002, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4002, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4003
4004 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
4005
4006 proto_tree_set_uint64(new_fi, value);
4007
4008 new_fi->flags |= (encoding & ENC_LITTLE_ENDIAN0x80000000) ? FI_LITTLE_ENDIAN0x00000008 : FI_BIG_ENDIAN0x00000010;
4009 if (encoding & (ENC_VARINT_PROTOBUF0x00000002|ENC_VARINT_ZIGZAG0x00000008|ENC_VARINT_SDNV0x00000010)) {
4010 new_fi->flags |= FI_VARINT0x00040000;
4011 }
4012
4013 return proto_tree_add_node(tree, new_fi);
4014
4015}
4016
4017proto_item *
4018proto_tree_add_item_ret_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb,
4019 const unsigned start, unsigned length,
4020 const unsigned encoding, bool_Bool *retval)
4021{
4022 header_field_info *hfinfo;
4023 field_info *new_fi;
4024 uint64_t value, bitval;
4025
4026 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 4026, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4026,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4026, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
4027
4028 if (hfinfo->type != FT_BOOLEAN) {
4029 REPORT_DISSECTOR_BUG("field %s is not of type FT_BOOLEAN",proto_report_dissector_bug("field %s is not of type FT_BOOLEAN"
, hfinfo->abbrev)
4030 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_BOOLEAN"
, hfinfo->abbrev)
;
4031 }
4032
4033 CHECK_FOR_ZERO_LENGTH_AND_CLEANUP(length,if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
4034 {if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
4035 if(retval)if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
4036 {if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
4037 *retval = false;if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
4038 }if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
4039 } )if (length == 0) { { if(retval) { *retval = 0; } }; return ((
void*)0); }
;
4040
4041 if (encoding & ENC_STRING0x07000000) {
4042 REPORT_DISSECTOR_BUG("wrong encoding")proto_report_dissector_bug("wrong encoding");
4043 }
4044 /* I believe it's ok if this is called with a NULL tree */
4045 value = get_uint64_value(tree, tvb, start, length, encoding);
4046
4047 if (retval) {
4048 bitval = value;
4049 if (hfinfo->bitmask) {
4050 /* Mask out irrelevant portions */
4051 bitval &= hfinfo->bitmask;
4052 }
4053 *retval = (bitval != 0);
4054 }
4055
4056 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4057
4058 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4058
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4058, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4058, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4058, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4059
4060 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
4061
4062 proto_tree_set_boolean(new_fi, value);
4063
4064 new_fi->flags |= (encoding & ENC_LITTLE_ENDIAN0x80000000) ? FI_LITTLE_ENDIAN0x00000008 : FI_BIG_ENDIAN0x00000010;
4065
4066 return proto_tree_add_node(tree, new_fi);
4067}
4068
4069proto_item *
4070proto_tree_add_item_ret_float(proto_tree *tree, int hfindex, tvbuff_t *tvb,
4071 const unsigned start, unsigned length,
4072 const unsigned encoding, float *retval)
4073{
4074 header_field_info *hfinfo = proto_registrar_get_nth(hfindex);
4075 field_info *new_fi;
4076 float value;
4077
4078 DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi.")((void) ((hfinfo != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4078,
"hfinfo != ((void*)0)", "Not passed hfi."))))
;
4079
4080 if (hfinfo->type != FT_FLOAT) {
4081 REPORT_DISSECTOR_BUG("field %s is not of type FT_FLOAT", hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_FLOAT"
, hfinfo->abbrev)
;
4082 }
4083
4084 if (length != 4) {
4085 report_type_length_mismatch(tree, "a single-precision floating point number", length, true1);
4086 }
4087
4088 /* treat any nonzero encoding as little endian for backwards compatibility */
4089 value = encoding ? tvb_get_letohieee_float(tvb, start) : tvb_get_ntohieee_float(tvb, start);
4090 if (retval) {
4091 *retval = value;
4092 }
4093
4094 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4095
4096 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4096
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4096, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4096, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4096, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4097
4098 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
4099 if (encoding) {
4100 new_fi->flags |= FI_LITTLE_ENDIAN0x00000008;
4101 }
4102
4103 proto_tree_set_float(new_fi, value);
4104
4105 return proto_tree_add_node(tree, new_fi);
4106}
4107
4108proto_item *
4109proto_tree_add_item_ret_double(proto_tree *tree, int hfindex, tvbuff_t *tvb,
4110 const unsigned start, unsigned length,
4111 const unsigned encoding, double *retval)
4112{
4113 header_field_info *hfinfo = proto_registrar_get_nth(hfindex);
4114 field_info *new_fi;
4115 double value;
4116
4117 DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi.")((void) ((hfinfo != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4117,
"hfinfo != ((void*)0)", "Not passed hfi."))))
;
4118
4119 if (hfinfo->type != FT_DOUBLE) {
4120 REPORT_DISSECTOR_BUG("field %s is not of type FT_DOUBLE", hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_DOUBLE"
, hfinfo->abbrev)
;
4121 }
4122
4123 if (length != 8) {
4124 report_type_length_mismatch(tree, "a double-precision floating point number", length, true1);
4125 }
4126
4127 /* treat any nonzero encoding as little endian for backwards compatibility */
4128 value = encoding ? tvb_get_letohieee_double(tvb, start) : tvb_get_ntohieee_double(tvb, start);
4129 if (retval) {
4130 *retval = value;
4131 }
4132
4133 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4134
4135 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4135
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4135, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4135, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4135, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4136
4137 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
4138 if (encoding) {
4139 new_fi->flags |= FI_LITTLE_ENDIAN0x00000008;
4140 }
4141
4142 proto_tree_set_double(new_fi, value);
4143
4144 return proto_tree_add_node(tree, new_fi);
4145}
4146
4147proto_item *
4148proto_tree_add_item_ret_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb,
4149 const unsigned start, unsigned length,
4150 const unsigned encoding, ws_in4_addr *retval)
4151{
4152 header_field_info *hfinfo;
4153 field_info *new_fi;
4154 ws_in4_addr value;
4155
4156 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 4156, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4156,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4156, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
4157
4158 switch (hfinfo->type) {
4159 case FT_IPv4:
4160 break;
4161 default:
4162 REPORT_DISSECTOR_BUG("field %s is not of type FT_IPv4",proto_report_dissector_bug("field %s is not of type FT_IPv4",
hfinfo->abbrev)
4163 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_IPv4",
hfinfo->abbrev)
;
4164 }
4165
4166 if (length != FT_IPv4_LEN4)
4167 REPORT_DISSECTOR_BUG("Invalid length %d passed to proto_tree_add_item_ret_ipv4",proto_report_dissector_bug("Invalid length %d passed to proto_tree_add_item_ret_ipv4"
, length)
4168 length)proto_report_dissector_bug("Invalid length %d passed to proto_tree_add_item_ret_ipv4"
, length)
;
4169
4170 if (encoding & (ENC_STRING0x07000000 | ENC_VARINT_MASK(0x00000002|0x00000004|0x00000008|0x00000010))) {
4171 REPORT_DISSECTOR_BUG("wrong encoding")proto_report_dissector_bug("wrong encoding");
4172 }
4173
4174 /*
4175 * NOTE: to support code written when proto_tree_add_item() took
4176 * a bool as its last argument, with false meaning "big-endian"
4177 * and true meaning "little-endian", we treat any non-zero value
4178 * of "encoding" as meaning "little-endian".
4179 */
4180 value = tvb_get_ipv4(tvb, start);
4181 if (encoding)
4182 value = GUINT32_SWAP_LE_BE(value)(((guint32) ( (((guint32) (value) & (guint32) 0x000000ffU
) << 24) | (((guint32) (value) & (guint32) 0x0000ff00U
) << 8) | (((guint32) (value) & (guint32) 0x00ff0000U
) >> 8) | (((guint32) (value) & (guint32) 0xff000000U
) >> 24))))
;
4183
4184 if (retval) {
4185 *retval = value;
4186 }
4187
4188 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4189
4190 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4190
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4190, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4190, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4190, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4191
4192 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
4193
4194 proto_tree_set_ipv4(new_fi, value);
4195
4196 new_fi->flags |= encoding ? FI_LITTLE_ENDIAN0x00000008 : FI_BIG_ENDIAN0x00000010;
4197 return proto_tree_add_node(tree, new_fi);
4198}
4199
4200proto_item *
4201proto_tree_add_item_ret_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb,
4202 const unsigned start, unsigned length,
4203 const unsigned encoding, ws_in6_addr *addr)
4204{
4205 header_field_info *hfinfo = proto_registrar_get_nth(hfindex);
4206 field_info *new_fi;
4207
4208 DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi.")((void) ((hfinfo != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4208,
"hfinfo != ((void*)0)", "Not passed hfi."))))
;
4209
4210 switch (hfinfo->type) {
4211 case FT_IPv6:
4212 break;
4213 default:
4214 REPORT_DISSECTOR_BUG("field %s is not of type FT_IPv6",proto_report_dissector_bug("field %s is not of type FT_IPv6",
hfinfo->abbrev)
4215 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_IPv6",
hfinfo->abbrev)
;
4216 }
4217
4218 if (length != FT_IPv6_LEN16)
4219 REPORT_DISSECTOR_BUG("Invalid length %d passed to proto_tree_add_item_ret_ipv6",proto_report_dissector_bug("Invalid length %d passed to proto_tree_add_item_ret_ipv6"
, length)
4220 length)proto_report_dissector_bug("Invalid length %d passed to proto_tree_add_item_ret_ipv6"
, length)
;
4221
4222 if (encoding) {
4223 REPORT_DISSECTOR_BUG("Encodings not yet implemented for proto_tree_add_item_ret_ipv6")proto_report_dissector_bug("Encodings not yet implemented for proto_tree_add_item_ret_ipv6"
)
;
4224 }
4225
4226 tvb_get_ipv6(tvb, start, addr);
4227
4228 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4229
4230 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4230
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4230, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4230, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4230, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4231
4232 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
4233
4234 proto_tree_set_ipv6(new_fi, addr);
4235
4236 return proto_tree_add_node(tree, new_fi);
4237}
4238
4239proto_item *
4240proto_tree_add_item_ret_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb,
4241 const unsigned start, unsigned length, const unsigned encoding, uint8_t *retval) {
4242
4243 header_field_info *hfinfo = proto_registrar_get_nth(hfindex);
4244 field_info *new_fi;
4245
4246 DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi.")((void) ((hfinfo != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4246,
"hfinfo != ((void*)0)", "Not passed hfi."))))
;
4247
4248 switch (hfinfo->type) {
4249 case FT_ETHER:
4250 break;
4251 default:
4252 REPORT_DISSECTOR_BUG("field %s is not of type FT_ETHER",proto_report_dissector_bug("field %s is not of type FT_ETHER"
, hfinfo->abbrev)
4253 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_ETHER"
, hfinfo->abbrev)
;
4254 }
4255
4256 if (length != FT_ETHER_LEN6)
4257 REPORT_DISSECTOR_BUG("Invalid length %d passed to proto_tree_add_item_ret_ether",proto_report_dissector_bug("Invalid length %d passed to proto_tree_add_item_ret_ether"
, length)
4258 length)proto_report_dissector_bug("Invalid length %d passed to proto_tree_add_item_ret_ether"
, length)
;
4259
4260 if (encoding) {
4261 REPORT_DISSECTOR_BUG("Encodings not yet implemented for proto_tree_add_item_ret_ether")proto_report_dissector_bug("Encodings not yet implemented for proto_tree_add_item_ret_ether"
)
;
4262 }
4263
4264 tvb_memcpy(tvb, retval, start, length);
4265
4266 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4267
4268 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4268
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4268, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4268, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4268, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4269
4270 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
4271
4272 proto_tree_set_ether(new_fi, retval);
4273
4274 return proto_tree_add_node(tree, new_fi);
4275}
4276
4277
4278proto_item *
4279proto_tree_add_item_ret_string_and_length(proto_tree *tree, int hfindex,
4280 tvbuff_t *tvb,
4281 const unsigned start, int length,
4282 const unsigned encoding,
4283 wmem_allocator_t *scope,
4284 const uint8_t **retval,
4285 unsigned *lenretval)
4286{
4287 proto_item *pi;
4288 header_field_info *hfinfo;
4289 field_info *new_fi;
4290 const uint8_t *value;
4291
4292 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 4292, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4292,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4292, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
4293
4294 switch (hfinfo->type) {
4295 case FT_STRING:
4296 value = get_string_value(scope, tvb, start, length, lenretval, encoding);
4297 break;
4298 case FT_STRINGZ:
4299 value = get_stringz_value(scope, tree, tvb, start, length, lenretval, encoding);
4300 break;
4301 case FT_UINT_STRING:
4302 value = get_uint_string_value(scope, tree, tvb, start, length, lenretval, encoding);
4303 break;
4304 case FT_STRINGZPAD:
4305 value = get_stringzpad_value(scope, tvb, start, length, lenretval, encoding);
4306 break;
4307 case FT_STRINGZTRUNC:
4308 value = get_stringztrunc_value(scope, tvb, start, length, lenretval, encoding);
4309 break;
4310 default:
4311 REPORT_DISSECTOR_BUG("field %s is not of type FT_STRING, FT_STRINGZ, FT_UINT_STRING, FT_STRINGZPAD, or FT_STRINGZTRUNC",proto_report_dissector_bug("field %s is not of type FT_STRING, FT_STRINGZ, FT_UINT_STRING, FT_STRINGZPAD, or FT_STRINGZTRUNC"
, hfinfo->abbrev)
4312 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_STRING, FT_STRINGZ, FT_UINT_STRING, FT_STRINGZPAD, or FT_STRINGZTRUNC"
, hfinfo->abbrev)
;
4313 }
4314
4315 if (retval)
4316 *retval = value;
4317
4318 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4319
4320 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4320
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4320, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4320, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4320, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4321
4322 new_fi = new_field_info(tree, hfinfo, tvb, start, *lenretval);
4323
4324 proto_tree_set_string(new_fi, (const char*)value);
4325
4326 new_fi->flags |= (encoding & ENC_LITTLE_ENDIAN0x80000000) ? FI_LITTLE_ENDIAN0x00000008 : FI_BIG_ENDIAN0x00000010;
4327
4328 pi = proto_tree_add_node(tree, new_fi);
4329
4330 switch (hfinfo->type) {
4331
4332 case FT_STRINGZ:
4333 case FT_STRINGZPAD:
4334 case FT_STRINGZTRUNC:
4335 case FT_UINT_STRING:
4336 break;
4337
4338 case FT_STRING:
4339 detect_trailing_stray_characters(encoding, (const char*)value, length, pi);
4340 break;
4341
4342 default:
4343 ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4343
, __func__, "assertion \"not reached\" failed")
;
4344 }
4345
4346 return pi;
4347}
4348
4349proto_item *
4350proto_tree_add_item_ret_string(proto_tree *tree, int hfindex, tvbuff_t *tvb,
4351 const unsigned start, int length,
4352 const unsigned encoding, wmem_allocator_t *scope,
4353 const uint8_t **retval)
4354{
4355 unsigned item_length; // Param cannot be NULL in function below
4356 return proto_tree_add_item_ret_string_and_length(tree, hfindex,
4357 tvb, start, length, encoding, scope, retval, &item_length);
4358}
4359
4360proto_item *
4361proto_tree_add_item_ret_display_string_and_length(proto_tree *tree, int hfindex,
4362 tvbuff_t *tvb,
4363 const unsigned start, int length,
4364 const unsigned encoding,
4365 wmem_allocator_t *scope,
4366 char **retval,
4367 unsigned *lenretval)
4368{
4369 proto_item *pi;
4370 header_field_info *hfinfo;
4371 field_info *new_fi;
4372 const uint8_t *value;
4373 uint32_t n = 0;
4374
4375 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 4375, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4375,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4375, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
4376
4377 switch (hfinfo->type) {
4378 case FT_STRING:
4379 value = get_string_value(scope, tvb, start, length, lenretval, encoding);
4380 *retval = wmem_alloc(scope, ITEM_LABEL_LENGTH240);
4381 ws_label_strcpy(*retval, ITEM_LABEL_LENGTH240, 0, value, label_strcat_flags(hfinfo));
4382 break;
4383 case FT_STRINGZ:
4384 value = get_stringz_value(scope, tree, tvb, start, length, lenretval, encoding);
4385 *retval = wmem_alloc(scope, ITEM_LABEL_LENGTH240);
4386 ws_label_strcpy(*retval, ITEM_LABEL_LENGTH240, 0, value, label_strcat_flags(hfinfo));
4387 break;
4388 case FT_UINT_STRING:
4389 value = get_uint_string_value(scope, tree, tvb, start, length, lenretval, encoding);
4390 *retval = wmem_alloc(scope, ITEM_LABEL_LENGTH240);
4391 ws_label_strcpy(*retval, ITEM_LABEL_LENGTH240, 0, value, label_strcat_flags(hfinfo));
4392 break;
4393 case FT_STRINGZPAD:
4394 value = get_stringzpad_value(scope, tvb, start, length, lenretval, encoding);
4395 *retval = wmem_alloc(scope, ITEM_LABEL_LENGTH240);
4396 ws_label_strcpy(*retval, ITEM_LABEL_LENGTH240, 0, value, label_strcat_flags(hfinfo));
4397 break;
4398 case FT_STRINGZTRUNC:
4399 value = get_stringztrunc_value(scope, tvb, start, length, lenretval, encoding);
4400 *retval = wmem_alloc(scope, ITEM_LABEL_LENGTH240);
4401 ws_label_strcpy(*retval, ITEM_LABEL_LENGTH240, 0, value, label_strcat_flags(hfinfo));
4402 break;
4403 case FT_BYTES:
4404 tvb_ensure_bytes_exist(tvb, start, length);
4405 value = tvb_get_ptr(tvb, start, length);
4406 *retval = format_bytes_hfinfo(scope, hfinfo, value, length);
4407 *lenretval = length;
4408 break;
4409 case FT_UINT_BYTES:
4410 n = get_uint_value(tree, tvb, start, length, encoding);
4411 tvb_ensure_bytes_exist(tvb, start + length, n);
4412 value = tvb_get_ptr(tvb, start + length, n);
4413 *retval = format_bytes_hfinfo(scope, hfinfo, value, n);
4414 *lenretval = length + n;
4415 break;
4416 default:
4417 REPORT_DISSECTOR_BUG("field %s is not of type FT_STRING, FT_STRINGZ, FT_UINT_STRING, FT_STRINGZPAD, FT_STRINGZTRUNC, FT_BYTES, or FT_UINT_BYTES",proto_report_dissector_bug("field %s is not of type FT_STRING, FT_STRINGZ, FT_UINT_STRING, FT_STRINGZPAD, FT_STRINGZTRUNC, FT_BYTES, or FT_UINT_BYTES"
, hfinfo->abbrev)
4418 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_STRING, FT_STRINGZ, FT_UINT_STRING, FT_STRINGZPAD, FT_STRINGZTRUNC, FT_BYTES, or FT_UINT_BYTES"
, hfinfo->abbrev)
;
4419 }
4420
4421 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4422
4423 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4423
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4423, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4423, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4423, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4424
4425 new_fi = new_field_info(tree, hfinfo, tvb, start, *lenretval);
4426
4427 switch (hfinfo->type) {
4428
4429 case FT_STRING:
4430 case FT_STRINGZ:
4431 case FT_UINT_STRING:
4432 case FT_STRINGZPAD:
4433 case FT_STRINGZTRUNC:
4434 proto_tree_set_string(new_fi, (const char*)value);
4435 break;
4436
4437 case FT_BYTES:
4438 proto_tree_set_bytes(new_fi, value, length);
4439 break;
4440
4441 case FT_UINT_BYTES:
4442 proto_tree_set_bytes(new_fi, value, n);
4443 break;
4444
4445 default:
4446 ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4446
, __func__, "assertion \"not reached\" failed")
;
4447 }
4448
4449 new_fi->flags |= (encoding & ENC_LITTLE_ENDIAN0x80000000) ? FI_LITTLE_ENDIAN0x00000008 : FI_BIG_ENDIAN0x00000010;
4450
4451 pi = proto_tree_add_node(tree, new_fi);
4452
4453 switch (hfinfo->type) {
4454
4455 case FT_STRINGZ:
4456 case FT_STRINGZPAD:
4457 case FT_STRINGZTRUNC:
4458 case FT_UINT_STRING:
4459 break;
4460
4461 case FT_STRING:
4462 detect_trailing_stray_characters(encoding, (const char*)value, length, pi);
4463 break;
4464
4465 case FT_BYTES:
4466 case FT_UINT_BYTES:
4467 break;
4468
4469 default:
4470 ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4470
, __func__, "assertion \"not reached\" failed")
;
4471 }
4472
4473 return pi;
4474}
4475
4476proto_item *
4477proto_tree_add_item_ret_display_string(proto_tree *tree, int hfindex,
4478 tvbuff_t *tvb,
4479 const unsigned start, int length,
4480 const unsigned encoding,
4481 wmem_allocator_t *scope,
4482 char **retval)
4483{
4484 unsigned item_length; // Param cannot be NULL in function below
4485 return proto_tree_add_item_ret_display_string_and_length(tree, hfindex,
4486 tvb, start, length, encoding, scope, retval, &item_length);
4487}
4488
4489proto_item *
4490proto_tree_add_item_ret_time_string(proto_tree *tree, int hfindex,
4491 tvbuff_t *tvb,
4492 const unsigned start, int length, const unsigned encoding,
4493 wmem_allocator_t *scope, char **retval)
4494{
4495 header_field_info *hfinfo;
4496 field_info *new_fi;
4497 nstime_t time_stamp;
4498 int flags;
4499
4500 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 4500, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4500,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4500, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
4501
4502 switch (hfinfo->type) {
4503 case FT_ABSOLUTE_TIME:
4504 get_time_value(tree, tvb, start, length, encoding, &time_stamp, false0);
4505 flags = ABS_TIME_TO_STR_SHOW_ZONE(1U << 0);
4506 if (prefs.display_abs_time_ascii < ABS_TIME_ASCII_TREE) {
4507 flags |= ABS_TIME_TO_STR_ISO8601(1U << 3);
4508 }
4509 *retval = abs_time_to_str_ex(scope, &time_stamp, hfinfo->display, flags);
4510 break;
4511 case FT_RELATIVE_TIME:
4512 get_time_value(tree, tvb, start, length, encoding, &time_stamp, true1);
4513 *retval = rel_time_to_secs_str(scope, &time_stamp);
4514 break;
4515 default:
4516 REPORT_DISSECTOR_BUG("field %s is not of type FT_ABSOLUTE_TIME or FT_RELATIVE_TIME",proto_report_dissector_bug("field %s is not of type FT_ABSOLUTE_TIME or FT_RELATIVE_TIME"
, hfinfo->abbrev)
4517 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_ABSOLUTE_TIME or FT_RELATIVE_TIME"
, hfinfo->abbrev)
;
4518 }
4519
4520 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4521
4522 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4522
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4522, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4522, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4522, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4523
4524 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
4525
4526 switch (hfinfo->type) {
4527
4528 case FT_ABSOLUTE_TIME:
4529 case FT_RELATIVE_TIME:
4530 proto_tree_set_time(new_fi, &time_stamp);
4531 break;
4532 default:
4533 ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4533
, __func__, "assertion \"not reached\" failed")
;
4534 }
4535
4536 new_fi->flags |= (encoding & ENC_LITTLE_ENDIAN0x80000000) ? FI_LITTLE_ENDIAN0x00000008 : FI_BIG_ENDIAN0x00000010;
4537
4538 return proto_tree_add_node(tree, new_fi);
4539}
4540
4541/* Gets data from tvbuff, adds it to proto_tree, increments offset,
4542 and returns proto_item* */
4543proto_item *
4544ptvcursor_add(ptvcursor_t *ptvc, int hfindex, int length,
4545 const unsigned encoding)
4546{
4547 field_info *new_fi;
4548 header_field_info *hfinfo;
4549 int item_length;
4550 unsigned offset;
4551
4552 offset = ptvc->offset;
4553 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 4553, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4553,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4553, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
4554 get_hfi_length(hfinfo, ptvc->tvb, offset, &length, &item_length, encoding);
4555 test_length(hfinfo, ptvc->tvb, offset, item_length, encoding);
4556
4557 ptvcursor_advance(ptvc, get_full_length(hfinfo, ptvc->tvb, offset, length, item_length, encoding));
4558
4559 CHECK_FOR_NULL_TREE(ptvc->tree)if (!ptvc->tree) { ((void)0); return ((void*)0); };
4560
4561 /* Coast clear. Try and fake it */
4562 TRY_TO_FAKE_THIS_ITEM(ptvc->tree, hfindex, hfinfo)((ptvc->tree)->tree_data)->count++; if((hfindex == 0
|| (unsigned)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4562
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4562, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4562, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((ptvc->tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4562, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((ptvc->tree
)->tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((ptvc->tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((ptvc
->tree)->tree_data)->visible)) { if (proto_item_is_hidden
((ptvc->tree))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT
) && (hfinfo->ref_type != HF_REF_TYPE_PRINT) &&
(hfinfo->type != FT_PROTOCOL || ((ptvc->tree)->tree_data
)->fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(ptvc->tree, hfinfo); } } }
;
4563
4564 new_fi = new_field_info(ptvc->tree, hfinfo, ptvc->tvb, offset, item_length);
4565
4566 return proto_tree_new_item(new_fi, ptvc->tree, ptvc->tvb,
4567 offset, length, encoding);
4568}
4569
4570/* Add an item to a proto_tree, using the text label registered to that item;
4571 the item is extracted from the tvbuff handed to it. */
4572proto_item *
4573proto_tree_add_item_new(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
4574 const unsigned start, int length, const unsigned encoding)
4575{
4576 field_info *new_fi;
4577 int item_length;
4578
4579 DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi.")((void) ((hfinfo != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4579,
"hfinfo != ((void*)0)", "Not passed hfi."))))
;
4580
4581 get_hfi_length(hfinfo, tvb, start, &length, &item_length, encoding);
4582 test_length(hfinfo, tvb, start, item_length, encoding);
4583
4584 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4585
4586 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4586
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4586, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4586, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4586, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4587
4588 new_fi = new_field_info(tree, hfinfo, tvb, start, item_length);
4589
4590 return proto_tree_new_item(new_fi, tree, tvb, start, length, encoding);
4591}
4592
4593proto_item *
4594proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
4595 const unsigned start, int length, const unsigned encoding)
4596{
4597 register header_field_info *hfinfo;
4598
4599 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 4599, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4599,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4599, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
4600 return proto_tree_add_item_new(tree, hfinfo, tvb, start, length, encoding);
4601}
4602
4603/* Add an item to a proto_tree, using the text label registered to that item;
4604 the item is extracted from the tvbuff handed to it.
4605
4606 Return the length of the item through the pointer. */
4607proto_item *
4608proto_tree_add_item_new_ret_length(proto_tree *tree, header_field_info *hfinfo,
4609 tvbuff_t *tvb, const unsigned start,
4610 int length, const unsigned encoding,
4611 unsigned *lenretval)
4612{
4613 field_info *new_fi;
4614 int item_length;
4615 proto_item *item;
4616
4617 DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi.")((void) ((hfinfo != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4617,
"hfinfo != ((void*)0)", "Not passed hfi."))))
;
4618
4619 get_hfi_length(hfinfo, tvb, start, &length, &item_length, encoding);
4620 test_length(hfinfo, tvb, start, item_length, encoding);
4621
4622 if (!tree) {
4623 /*
4624 * We need to get the correct item length here.
4625 * That's normally done by proto_tree_new_item(),
4626 * but we won't be calling it.
4627 */
4628 *lenretval = get_full_length(hfinfo, tvb, start, length,
4629 item_length, encoding);
4630 return NULL((void*)0);
4631 }
4632
4633 TRY_TO_FAKE_THIS_ITEM_OR_FREE(tree, hfinfo->id, hfinfo, {((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; return proto_tree_add_fake_node(
tree, hfinfo); } } }
4634 /*((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; return proto_tree_add_fake_node(
tree, hfinfo); } } }
4635 * Even if the tree item is not referenced (and thus faked),((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; return proto_tree_add_fake_node(
tree, hfinfo); } } }
4636 * the caller must still be informed of the actual length.((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; return proto_tree_add_fake_node(
tree, hfinfo); } } }
4637 */((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; return proto_tree_add_fake_node(
tree, hfinfo); } } }
4638 *lenretval = get_full_length(hfinfo, tvb, start, length,((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; return proto_tree_add_fake_node(
tree, hfinfo); } } }
4639 item_length, encoding);((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; return proto_tree_add_fake_node(
tree, hfinfo); } } }
4640 })((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4640, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4640
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { *lenretval = get_full_length(hfinfo, tvb, start, length
, item_length, encoding); }; return proto_tree_add_fake_node(
tree, hfinfo); } } }
;
4641
4642 new_fi = new_field_info(tree, hfinfo, tvb, start, item_length);
4643
4644 item = proto_tree_new_item(new_fi, tree, tvb, start, length, encoding);
4645 *lenretval = new_fi->length;
4646 return item;
4647}
4648
4649proto_item *
4650proto_tree_add_item_ret_length(proto_tree *tree, int hfindex, tvbuff_t *tvb,
4651 const unsigned start, int length,
4652 const unsigned encoding, unsigned *lenretval)
4653{
4654 register header_field_info *hfinfo;
4655
4656 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 4656, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4656,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4656, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
4657 return proto_tree_add_item_new_ret_length(tree, hfinfo, tvb, start, length, encoding, lenretval);
4658}
4659
4660/* which FT_ types can use proto_tree_add_bytes_item() */
4661static inline bool_Bool
4662validate_proto_tree_add_bytes_ftype(const enum ftenum type)
4663{
4664 return (type == FT_BYTES ||
4665 type == FT_UINT_BYTES ||
4666 type == FT_OID ||
4667 type == FT_REL_OID ||
4668 type == FT_SYSTEM_ID );
4669}
4670
4671/* Note: this does no validation that the byte array of an FT_OID or
4672 FT_REL_OID is actually valid; and neither does proto_tree_add_item(),
4673 so I think it's ok to continue not validating it?
4674 */
4675proto_item *
4676proto_tree_add_bytes_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
4677 const unsigned start, unsigned length,
4678 const unsigned encoding,
4679 GByteArray *retval, unsigned *endoff, int *err)
4680{
4681 field_info *new_fi;
4682 GByteArray *bytes = retval;
4683 GByteArray *created_bytes = NULL((void*)0);
4684 bool_Bool failed = false0;
4685 uint32_t n = 0;
4686 header_field_info *hfinfo;
4687 bool_Bool generate = (bytes || tree) ? true1 : false0;
4688
4689 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 4689, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4689,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4689, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
4690
4691 DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi.")((void) ((hfinfo != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4691,
"hfinfo != ((void*)0)", "Not passed hfi."))))
;
4692
4693 DISSECTOR_ASSERT_HINT(validate_proto_tree_add_bytes_ftype(hfinfo->type),((void) ((validate_proto_tree_add_bytes_ftype(hfinfo->type
)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4694, "validate_proto_tree_add_bytes_ftype(hfinfo->type)"
, "Called proto_tree_add_bytes_item but not a bytes-based FT_XXX type"
))))
4694 "Called proto_tree_add_bytes_item but not a bytes-based FT_XXX type")((void) ((validate_proto_tree_add_bytes_ftype(hfinfo->type
)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4694, "validate_proto_tree_add_bytes_ftype(hfinfo->type)"
, "Called proto_tree_add_bytes_item but not a bytes-based FT_XXX type"
))))
;
4695
4696 if (length == 0) {
4697 return NULL((void*)0);
4698 }
4699
4700 if (encoding & ENC_STR_NUM0x01000000) {
4701 REPORT_DISSECTOR_BUG("Decoding number strings for byte arrays is not supported")proto_report_dissector_bug("Decoding number strings for byte arrays is not supported"
)
;
4702 }
4703
4704 if (generate && (encoding & ENC_STR_HEX0x02000000)) {
4705 if (hfinfo->type == FT_UINT_BYTES) {
4706 /* can't decode FT_UINT_BYTES from strings */
4707 REPORT_DISSECTOR_BUG("proto_tree_add_bytes_item called for "proto_report_dissector_bug("proto_tree_add_bytes_item called for "
"FT_UINT_BYTES type, but as ENC_STR_HEX")
4708 "FT_UINT_BYTES type, but as ENC_STR_HEX")proto_report_dissector_bug("proto_tree_add_bytes_item called for "
"FT_UINT_BYTES type, but as ENC_STR_HEX")
;
4709 }
4710
4711 unsigned hex_encoding = encoding;
4712 if (!(encoding & ENC_SEP_MASK0x001F0000)) {
4713 /* If none of the separator values are used,
4714 * assume no separator (the common case). */
4715 hex_encoding |= ENC_SEP_NONE0x00010000;
4716#if 0
4717 REPORT_DISSECTOR_BUG("proto_tree_add_bytes_item called "proto_report_dissector_bug("proto_tree_add_bytes_item called "
"with ENC_STR_HEX but no ENC_SEP_XXX value")
4718 "with ENC_STR_HEX but no ENC_SEP_XXX value")proto_report_dissector_bug("proto_tree_add_bytes_item called "
"with ENC_STR_HEX but no ENC_SEP_XXX value")
;
4719#endif
4720 }
4721
4722 if (!bytes) {
4723 /* caller doesn't care about return value, but we need it to
4724 call tvb_get_string_bytes() and set the tree later */
4725 bytes = created_bytes = g_byte_array_new();
4726 }
4727
4728 /*
4729 * bytes might be NULL after this, but can't add expert
4730 * error until later; if it's NULL, just note that
4731 * it failed.
4732 */
4733 bytes = tvb_get_string_bytes(tvb, start, length, hex_encoding, bytes, endoff);
4734 if (bytes == NULL((void*)0))
4735 failed = true1;
4736 }
4737 else if (generate) {
4738 tvb_ensure_bytes_exist(tvb, start, length);
4739
4740 if (hfinfo->type == FT_UINT_BYTES) {
4741 n = length; /* n is now the "header" length */
4742 length = get_uint_value(tree, tvb, start, n, encoding);
4743 /* length is now the value's length; only store the value in the array */
4744 tvb_ensure_bytes_exist(tvb, start + n, length);
4745 if (!bytes) {
4746 /* caller doesn't care about return value, but
4747 * we may need it to set the tree later */
4748 bytes = created_bytes = g_byte_array_new();
4749 }
4750 g_byte_array_append(bytes, tvb_get_ptr(tvb, start + n, length), length);
4751 }
4752 else if (length > 0) {
4753 if (!bytes) {
4754 /* caller doesn't care about return value, but
4755 * we may need it to set the tree later */
4756 bytes = created_bytes = g_byte_array_new();
4757 }
4758 g_byte_array_append(bytes, tvb_get_ptr(tvb, start, length), length);
4759 }
4760
4761 if (endoff)
4762 *endoff = start + n + length;
4763 }
4764
4765 if (err)
4766 *err = failed ? EINVAL22 : 0;
4767
4768 CHECK_FOR_NULL_TREE_AND_FREE(tree,if (!tree) { { if (created_bytes) g_byte_array_free(created_bytes
, 1); created_bytes = ((void*)0); bytes = ((void*)0); }; return
((void*)0); }
4769 {if (!tree) { { if (created_bytes) g_byte_array_free(created_bytes
, 1); created_bytes = ((void*)0); bytes = ((void*)0); }; return
((void*)0); }
4770 if (created_bytes)if (!tree) { { if (created_bytes) g_byte_array_free(created_bytes
, 1); created_bytes = ((void*)0); bytes = ((void*)0); }; return
((void*)0); }
4771 g_byte_array_free(created_bytes, true);if (!tree) { { if (created_bytes) g_byte_array_free(created_bytes
, 1); created_bytes = ((void*)0); bytes = ((void*)0); }; return
((void*)0); }
4772 created_bytes = NULL;if (!tree) { { if (created_bytes) g_byte_array_free(created_bytes
, 1); created_bytes = ((void*)0); bytes = ((void*)0); }; return
((void*)0); }
4773 bytes = NULL;if (!tree) { { if (created_bytes) g_byte_array_free(created_bytes
, 1); created_bytes = ((void*)0); bytes = ((void*)0); }; return
((void*)0); }
4774 } )if (!tree) { { if (created_bytes) g_byte_array_free(created_bytes
, 1); created_bytes = ((void*)0); bytes = ((void*)0); }; return
((void*)0); }
;
4775
4776 TRY_TO_FAKE_THIS_ITEM_OR_FREE(tree, hfinfo->id, hfinfo,((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { if (created_bytes) g_byte_array_free(created_bytes, 1);
created_bytes = ((void*)0); bytes = ((void*)0); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { if (created_bytes) g_byte_array_free(created_bytes, 1)
; created_bytes = ((void*)0); bytes = ((void*)0); }; return proto_tree_add_fake_node
(tree, hfinfo); } } }
4777 {((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { if (created_bytes) g_byte_array_free(created_bytes, 1);
created_bytes = ((void*)0); bytes = ((void*)0); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { if (created_bytes) g_byte_array_free(created_bytes, 1)
; created_bytes = ((void*)0); bytes = ((void*)0); }; return proto_tree_add_fake_node
(tree, hfinfo); } } }
4778 if (created_bytes)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { if (created_bytes) g_byte_array_free(created_bytes, 1);
created_bytes = ((void*)0); bytes = ((void*)0); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { if (created_bytes) g_byte_array_free(created_bytes, 1)
; created_bytes = ((void*)0); bytes = ((void*)0); }; return proto_tree_add_fake_node
(tree, hfinfo); } } }
4779 g_byte_array_free(created_bytes, true);((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { if (created_bytes) g_byte_array_free(created_bytes, 1);
created_bytes = ((void*)0); bytes = ((void*)0); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { if (created_bytes) g_byte_array_free(created_bytes, 1)
; created_bytes = ((void*)0); bytes = ((void*)0); }; return proto_tree_add_fake_node
(tree, hfinfo); } } }
4780 created_bytes = NULL;((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { if (created_bytes) g_byte_array_free(created_bytes, 1);
created_bytes = ((void*)0); bytes = ((void*)0); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { if (created_bytes) g_byte_array_free(created_bytes, 1)
; created_bytes = ((void*)0); bytes = ((void*)0); }; return proto_tree_add_fake_node
(tree, hfinfo); } } }
4781 bytes = NULL;((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { if (created_bytes) g_byte_array_free(created_bytes, 1);
created_bytes = ((void*)0); bytes = ((void*)0); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { if (created_bytes) g_byte_array_free(created_bytes, 1)
; created_bytes = ((void*)0); bytes = ((void*)0); }; return proto_tree_add_fake_node
(tree, hfinfo); } } }
4782 } )((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4782, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { { if (created_bytes) g_byte_array_free(created_bytes, 1);
created_bytes = ((void*)0); bytes = ((void*)0); }; if (wireshark_abort_on_too_many_items
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4782
, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { { if (created_bytes) g_byte_array_free(created_bytes, 1)
; created_bytes = ((void*)0); bytes = ((void*)0); }; return proto_tree_add_fake_node
(tree, hfinfo); } } }
;
4783
4784 /* n will be zero except when it's a FT_UINT_BYTES */
4785 new_fi = new_field_info(tree, hfinfo, tvb, start, n + length);
4786
4787 if (encoding & ENC_STRING0x07000000) {
4788 if (failed)
4789 expert_add_info(NULL((void*)0), tree, &ei_byte_array_string_decoding_failed_error);
4790
4791 if (bytes)
4792 proto_tree_set_bytes_gbytearray(new_fi, bytes);
4793 else
4794 proto_tree_set_bytes(new_fi, NULL((void*)0), 0);
4795
4796 if (created_bytes)
4797 g_byte_array_free(created_bytes, true1);
4798 }
4799 else {
4800 /* n will be zero except when it's a FT_UINT_BYTES */
4801 proto_tree_set_bytes_tvb(new_fi, tvb, start + n, length);
4802
4803 /* XXX: If we have a non-NULL tree but NULL retval, we don't
4804 * use the byte array created above in this case.
4805 */
4806 if (created_bytes)
4807 g_byte_array_free(created_bytes, true1);
4808
4809 FI_SET_FLAG(new_fi,do { if (new_fi) (new_fi)->flags = (new_fi)->flags | ((
encoding & 0x80000000) ? 0x00000008 : 0x00000010); } while
(0)
4810 (encoding & ENC_LITTLE_ENDIAN) ? FI_LITTLE_ENDIAN : FI_BIG_ENDIAN)do { if (new_fi) (new_fi)->flags = (new_fi)->flags | ((
encoding & 0x80000000) ? 0x00000008 : 0x00000010); } while
(0)
;
4811 }
4812
4813 return proto_tree_add_node(tree, new_fi);
4814}
4815
4816
4817proto_item *
4818proto_tree_add_time_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
4819 const unsigned start, const unsigned length,
4820 const unsigned encoding,
4821 nstime_t *retval, unsigned *endoff, int *err)
4822{
4823 field_info *new_fi;
4824 nstime_t time_stamp;
4825 int saved_err = 0;
4826 header_field_info *hfinfo;
4827
4828 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 4828, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4828,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4828, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
4829
4830 DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi.")((void) ((hfinfo != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 4830,
"hfinfo != ((void*)0)", "Not passed hfi."))))
;
4831
4832 if (length == 0) {
4833 if(retval) {
4834 nstime_set_zero(retval);
4835 }
4836 return NULL((void*)0);
4837 }
4838
4839 nstime_set_zero(&time_stamp);
4840
4841 if (encoding & ENC_STR_TIME_MASK0x001F0000) {
4842 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_ABSOLUTE_TIME)((void) (((hfinfo)->type == FT_ABSOLUTE_TIME) ? (void)0 : (
proto_report_dissector_bug("%s:%u: field %s is not of type ""FT_ABSOLUTE_TIME"
, "epan/proto.c", 4842, ((hfinfo))->abbrev))))
;
4843 /* The only string format that could be a relative time is
4844 * ENC_ISO_8601_TIME, and that is treated as an absolute time
4845 * relative to "now" currently.
4846 */
4847 if (!tvb_get_string_time(tvb, start, length, encoding, &time_stamp, endoff))
4848 saved_err = EINVAL22;
4849 }
4850 else {
4851 DISSECTOR_ASSERT_FIELD_TYPE_IS_TIME(hfinfo)((void) (((hfinfo)->type == FT_ABSOLUTE_TIME || (hfinfo)->
type == FT_RELATIVE_TIME) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type FT_ABSOLUTE_TIME or FT_RELATIVE_TIME"
, "epan/proto.c", 4851, ((hfinfo))->abbrev))))
;
4852 const bool_Bool is_relative = (hfinfo->type == FT_RELATIVE_TIME) ? true1 : false0;
4853
4854 tvb_ensure_bytes_exist(tvb, start, length);
4855 get_time_value(tree, tvb, start, length, encoding, &time_stamp, is_relative);
4856 if (endoff) *endoff = start + length;
4857 }
4858
4859 if (err) *err = saved_err;
4860
4861 if (retval) {
4862 retval->secs = time_stamp.secs;
4863 retval->nsecs = time_stamp.nsecs;
4864 }
4865
4866 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4867
4868 TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo)((tree)->tree_data)->count++; if((hfinfo->id == 0 ||
(unsigned)hfinfo->id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4868
, __func__, "Unregistered hf! index=%d", hfinfo->id); ((void
) ((hfinfo->id > 0 && (unsigned)hfinfo->id <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4868, "hfinfo->id > 0 && (unsigned)hfinfo->id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4868, "gpa_hfinfo.hfi[hfinfo->id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
id];; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4868, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4869
4870 new_fi = new_field_info(tree, hfinfo, tvb, start, length);
4871
4872 proto_tree_set_time(new_fi, &time_stamp);
4873
4874 if (encoding & ENC_STRING0x07000000) {
4875 if (saved_err)
4876 expert_add_info(NULL((void*)0), tree, &ei_date_time_string_decoding_failed_error);
4877 }
4878 else {
4879 FI_SET_FLAG(new_fi,do { if (new_fi) (new_fi)->flags = (new_fi)->flags | ((
encoding & 0x80000000) ? 0x00000008 : 0x00000010); } while
(0)
4880 (encoding & ENC_LITTLE_ENDIAN) ? FI_LITTLE_ENDIAN : FI_BIG_ENDIAN)do { if (new_fi) (new_fi)->flags = (new_fi)->flags | ((
encoding & 0x80000000) ? 0x00000008 : 0x00000010); } while
(0)
;
4881 }
4882
4883 return proto_tree_add_node(tree, new_fi);
4884}
4885
4886/* Add a FT_NONE to a proto_tree */
4887proto_item *
4888proto_tree_add_none_format(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
4889 const unsigned start, int length, const char *format,
4890 ...)
4891{
4892 proto_item *pi;
4893 va_list ap;
4894 header_field_info *hfinfo;
4895
4896 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4897
4898 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4898
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4898, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4898, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4898, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4899
4900 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_NONE)((void) (((hfinfo)->type == FT_NONE) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_NONE", "epan/proto.c", 4900
, ((hfinfo))->abbrev))))
;
4901
4902 pi = proto_tree_add_pi(tree, hfinfo, tvb, start, &length);
4903
4904 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 4904, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
4905
4906 va_start(ap, format)__builtin_va_start(ap, format);
4907 proto_tree_set_representation(pi, format, ap);
4908 va_end(ap)__builtin_va_end(ap);
4909
4910 /* no value to set for FT_NONE */
4911 return pi;
4912}
4913
4914/* Gets data from tvbuff, adds it to proto_tree, *DOES NOT* increment
4915 * offset, and returns proto_item* */
4916proto_item *
4917ptvcursor_add_no_advance(ptvcursor_t* ptvc, int hf, int length,
4918 const unsigned encoding)
4919{
4920 proto_item *item;
4921
4922 item = proto_tree_add_item(ptvc->tree, hf, ptvc->tvb, ptvc->offset,
4923 length, encoding);
4924
4925 return item;
4926}
4927
4928/* Advance the ptvcursor's offset within its tvbuff without
4929 * adding anything to the proto_tree. */
4930void
4931ptvcursor_advance(ptvcursor_t* ptvc, unsigned length)
4932{
4933 if (ckd_add(&ptvc->offset, ptvc->offset, length)__builtin_add_overflow((ptvc->offset), (length), (&ptvc
->offset))
) {
4934 THROW(ReportedBoundsError)except_throw(1, (3), ((void*)0));
4935 }
4936}
4937
4938
4939static void
4940proto_tree_set_protocol_tvb(field_info *fi, tvbuff_t *tvb, const char* field_data, int length)
4941{
4942 ws_assert(length >= 0)do { if ((1) && !(length >= 0)) ws_log_fatal_full(
"Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4942, __func__, "assertion failed: %s"
, "length >= 0"); } while (0)
;
4943 fvalue_set_protocol(fi->value, tvb, field_data, (unsigned)length);
4944}
4945
4946/* Add a FT_PROTOCOL to a proto_tree */
4947proto_item *
4948proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
4949 unsigned start, int length, const char *format, ...)
4950{
4951 proto_item *pi;
4952 field_info *new_fi;
4953 tvbuff_t *protocol_tvb;
4954 va_list ap;
4955 header_field_info *hfinfo;
4956 char* protocol_rep;
4957
4958 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
4959
4960 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4960
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4960, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 4960, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 4960, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
4961
4962 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_PROTOCOL)((void) (((hfinfo)->type == FT_PROTOCOL) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_PROTOCOL", "epan/proto.c"
, 4962, ((hfinfo))->abbrev))))
;
4963
4964 /*
4965 * This can throw an exception when it calls get_hfi_length before
4966 * it allocates anything, if length is nonzero and start is past
4967 * the end of the tvb. Afterwards it can't throw an exception,
4968 * as length is clamped to the captured length remaining.
4969 */
4970 pi = proto_tree_add_pi(tree, hfinfo, tvb, start, &length);
4971 new_fi = PNODE_FINFO(pi)((pi)->finfo);
4972 /* Start the protocol_tvb at the correct start offset, but allow it
4973 * to be lengthened later via finfo_set_len. */
4974 protocol_tvb = new_fi->ds_tvb ? tvb_new_subset_remaining(new_fi->ds_tvb, new_fi->start) : NULL((void*)0);
4975
4976 va_start(ap, format)__builtin_va_start(ap, format);
4977 protocol_rep = ws_strdup_vprintf(format, ap)wmem_strdup_vprintf(((void*)0), format, ap);
4978 proto_tree_set_protocol_tvb(new_fi, protocol_tvb, protocol_rep, length);
4979 g_free(protocol_rep)(__builtin_object_size ((protocol_rep), 0) != ((size_t) - 1))
? g_free_sized (protocol_rep, __builtin_object_size ((protocol_rep
), 0)) : (g_free) (protocol_rep)
;
4980 va_end(ap)__builtin_va_end(ap);
4981
4982 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 4982, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
4983
4984 va_start(ap, format)__builtin_va_start(ap, format);
4985 proto_tree_set_representation(pi, format, ap);
4986 va_end(ap)__builtin_va_end(ap);
4987
4988 return pi;
4989}
4990
4991/* Add a FT_BYTES to a proto_tree */
4992proto_item *
4993proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
4994 int length, const uint8_t *start_ptr)
4995{
4996 proto_item *pi;
4997 header_field_info *hfinfo;
4998 int item_length;
4999
5000 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5000, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 5000,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5000, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
5001 get_hfi_length(hfinfo, tvb, start, &length, &item_length, ENC_NA0x00000000);
5002 test_length(hfinfo, tvb, start, item_length, ENC_NA0x00000000);
5003
5004 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
5005
5006 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5006
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5006, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5006, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5006, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
5007
5008 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_BYTES)((void) (((hfinfo)->type == FT_BYTES) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_BYTES", "epan/proto.c",
5008, ((hfinfo))->abbrev))))
;
5009
5010 if (start_ptr == NULL((void*)0) && tvb != NULL((void*)0))
5011 start_ptr = tvb_get_ptr(tvb, start, length);
5012
5013 pi = proto_tree_add_pi(tree, hfinfo, tvb, start, &length);
5014 proto_tree_set_bytes(PNODE_FINFO(pi)((pi)->finfo), start_ptr, length);
5015
5016 return pi;
5017}
5018
5019/* Add a FT_BYTES to a proto_tree */
5020proto_item *
5021proto_tree_add_bytes_with_length(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
5022 int tvbuff_length, const uint8_t *start_ptr, int ptr_length)
5023{
5024 proto_item *pi;
5025 header_field_info *hfinfo;
5026 int item_length;
5027
5028 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5028, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 5028,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5028, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
5029 get_hfi_length(hfinfo, tvb, start, &tvbuff_length, &item_length, ENC_NA0x00000000);
5030 test_length(hfinfo, tvb, start, item_length, ENC_NA0x00000000);
5031
5032 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
5033
5034 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5034
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5034, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5034, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5034, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
5035
5036 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_BYTES)((void) (((hfinfo)->type == FT_BYTES) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_BYTES", "epan/proto.c",
5036, ((hfinfo))->abbrev))))
;
5037
5038 pi = proto_tree_add_pi(tree, hfinfo, tvb, start, &tvbuff_length);
5039 proto_tree_set_bytes(PNODE_FINFO(pi)((pi)->finfo), start_ptr, ptr_length);
5040
5041 return pi;
5042}
5043
5044proto_item *
5045proto_tree_add_bytes_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5046 unsigned start, int length,
5047 const uint8_t *start_ptr,
5048 const char *format, ...)
5049{
5050 proto_item *pi;
5051 va_list ap;
5052
5053 pi = proto_tree_add_bytes(tree, hfindex, tvb, start, length, start_ptr);
5054
5055 TRY_TO_FAKE_THIS_REPR_NESTED(pi)if ((pi == ((void*)0)) || (((pi)->finfo) == ((void*)0)) ||
(!(((pi)->tree_data)->visible) && proto_item_is_hidden
((pi)))) { return pi; }
;
5056
5057 va_start(ap, format)__builtin_va_start(ap, format);
5058 proto_tree_set_representation_value(pi, format, ap);
5059 va_end(ap)__builtin_va_end(ap);
5060
5061 return pi;
5062}
5063
5064proto_item *
5065proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5066 unsigned start, int length, const uint8_t *start_ptr,
5067 const char *format, ...)
5068{
5069 proto_item *pi;
5070 va_list ap;
5071
5072 pi = proto_tree_add_bytes(tree, hfindex, tvb, start, length, start_ptr);
5073
5074 TRY_TO_FAKE_THIS_REPR_NESTED(pi)if ((pi == ((void*)0)) || (((pi)->finfo) == ((void*)0)) ||
(!(((pi)->tree_data)->visible) && proto_item_is_hidden
((pi)))) { return pi; }
;
5075
5076 va_start(ap, format)__builtin_va_start(ap, format);
5077 proto_tree_set_representation(pi, format, ap);
5078 va_end(ap)__builtin_va_end(ap);
5079
5080 return pi;
5081}
5082
5083static void
5084proto_tree_set_bytes(field_info *fi, const uint8_t* start_ptr, int length)
5085{
5086 DISSECTOR_ASSERT(length >= 0)((void) ((length >= 0) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 5086, "length >= 0"
))))
;
5087 DISSECTOR_ASSERT(start_ptr != NULL || length == 0)((void) ((start_ptr != ((void*)0) || length == 0) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 5087, "start_ptr != ((void*)0) || length == 0"
))))
;
5088
5089 fvalue_set_bytes_data(fi->value, start_ptr, length);
5090}
5091
5092
5093static void
5094proto_tree_set_bytes_tvb(field_info *fi, tvbuff_t *tvb, unsigned offset, int length)
5095{
5096 tvb_ensure_bytes_exist(tvb, offset, length);
5097 proto_tree_set_bytes(fi, tvb_get_ptr(tvb, offset, length), length);
5098}
5099
5100static void
5101proto_tree_set_bytes_gbytearray(field_info *fi, const GByteArray *value)
5102{
5103 GByteArray *bytes;
5104
5105 DISSECTOR_ASSERT(value != NULL)((void) ((value != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 5105, "value != ((void*)0)"
))))
;
5106
5107 bytes = byte_array_dup(value);
5108
5109 fvalue_set_byte_array(fi->value, bytes);
5110}
5111
5112/* Add a FT_*TIME to a proto_tree */
5113proto_item *
5114proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
5115 unsigned length, const nstime_t *value_ptr)
5116{
5117 proto_item *pi;
5118 header_field_info *hfinfo;
5119
5120 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
5121
5122 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5122
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5122, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5122, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5122, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
5123
5124 DISSECTOR_ASSERT_FIELD_TYPE_IS_TIME(hfinfo)((void) (((hfinfo)->type == FT_ABSOLUTE_TIME || (hfinfo)->
type == FT_RELATIVE_TIME) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type FT_ABSOLUTE_TIME or FT_RELATIVE_TIME"
, "epan/proto.c", 5124, ((hfinfo))->abbrev))))
;
5125
5126 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
5127 proto_tree_set_time(PNODE_FINFO(pi)((pi)->finfo), value_ptr);
5128
5129 return pi;
5130}
5131
5132proto_item *
5133proto_tree_add_time_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5134 unsigned start, unsigned length, nstime_t *value_ptr,
5135 const char *format, ...)
5136{
5137 proto_item *pi;
5138 va_list ap;
5139
5140 pi = proto_tree_add_time(tree, hfindex, tvb, start, length, value_ptr);
5141 if (pi != tree) {
5142 va_start(ap, format)__builtin_va_start(ap, format);
5143 proto_tree_set_representation_value(pi, format, ap);
5144 va_end(ap)__builtin_va_end(ap);
5145 }
5146
5147 return pi;
5148}
5149
5150proto_item *
5151proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5152 unsigned start, unsigned length, nstime_t *value_ptr,
5153 const char *format, ...)
5154{
5155 proto_item *pi;
5156 va_list ap;
5157
5158 pi = proto_tree_add_time(tree, hfindex, tvb, start, length, value_ptr);
5159 if (pi != tree) {
5160 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5160, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
5161
5162 va_start(ap, format)__builtin_va_start(ap, format);
5163 proto_tree_set_representation(pi, format, ap);
5164 va_end(ap)__builtin_va_end(ap);
5165 }
5166
5167 return pi;
5168}
5169
5170/* Set the FT_*TIME value */
5171static void
5172proto_tree_set_time(field_info *fi, const nstime_t *value_ptr)
5173{
5174 DISSECTOR_ASSERT(value_ptr != NULL)((void) ((value_ptr != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 5174, "value_ptr != ((void*)0)"
))))
;
5175
5176 fvalue_set_time(fi->value, value_ptr);
5177}
5178
5179/* Add a FT_IPXNET to a proto_tree */
5180proto_item *
5181proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
5182 unsigned length, uint32_t value)
5183{
5184 proto_item *pi;
5185 header_field_info *hfinfo;
5186
5187 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
5188
5189 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5189
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5189, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5189, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5189, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
5190
5191 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_IPXNET)((void) (((hfinfo)->type == FT_IPXNET) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_IPXNET", "epan/proto.c"
, 5191, ((hfinfo))->abbrev))))
;
5192
5193 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
5194 proto_tree_set_ipxnet(PNODE_FINFO(pi)((pi)->finfo), value);
5195
5196 return pi;
5197}
5198
5199proto_item *
5200proto_tree_add_ipxnet_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5201 unsigned start, unsigned length, uint32_t value,
5202 const char *format, ...)
5203{
5204 proto_item *pi;
5205 va_list ap;
5206
5207 pi = proto_tree_add_ipxnet(tree, hfindex, tvb, start, length, value);
5208 if (pi != tree) {
5209 va_start(ap, format)__builtin_va_start(ap, format);
5210 proto_tree_set_representation_value(pi, format, ap);
5211 va_end(ap)__builtin_va_end(ap);
5212 }
5213
5214 return pi;
5215}
5216
5217proto_item *
5218proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5219 unsigned start, unsigned length, uint32_t value,
5220 const char *format, ...)
5221{
5222 proto_item *pi;
5223 va_list ap;
5224
5225 pi = proto_tree_add_ipxnet(tree, hfindex, tvb, start, length, value);
5226 if (pi != tree) {
5227 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5227, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
5228
5229 va_start(ap, format)__builtin_va_start(ap, format);
5230 proto_tree_set_representation(pi, format, ap);
5231 va_end(ap)__builtin_va_end(ap);
5232 }
5233
5234 return pi;
5235}
5236
5237/* Set the FT_IPXNET value */
5238static void
5239proto_tree_set_ipxnet(field_info *fi, uint32_t value)
5240{
5241 fvalue_set_uinteger(fi->value, value);
5242}
5243
5244/* Add a FT_IPv4 to a proto_tree */
5245proto_item *
5246proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
5247 unsigned length, ws_in4_addr value)
5248{
5249 proto_item *pi;
5250 header_field_info *hfinfo;
5251
5252 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
5253
5254 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5254
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5254, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5254, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5254, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
5255
5256 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_IPv4)((void) (((hfinfo)->type == FT_IPv4) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_IPv4", "epan/proto.c", 5256
, ((hfinfo))->abbrev))))
;
5257
5258 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
5259 proto_tree_set_ipv4(PNODE_FINFO(pi)((pi)->finfo), value);
5260
5261 return pi;
5262}
5263
5264proto_item *
5265proto_tree_add_ipv4_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5266 unsigned start, unsigned length, ws_in4_addr value,
5267 const char *format, ...)
5268{
5269 proto_item *pi;
5270 va_list ap;
5271
5272 pi = proto_tree_add_ipv4(tree, hfindex, tvb, start, length, value);
5273 if (pi != tree) {
5274 va_start(ap, format)__builtin_va_start(ap, format);
5275 proto_tree_set_representation_value(pi, format, ap);
5276 va_end(ap)__builtin_va_end(ap);
5277 }
5278
5279 return pi;
5280}
5281
5282proto_item *
5283proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5284 unsigned start, unsigned length, ws_in4_addr value,
5285 const char *format, ...)
5286{
5287 proto_item *pi;
5288 va_list ap;
5289
5290 pi = proto_tree_add_ipv4(tree, hfindex, tvb, start, length, value);
5291 if (pi != tree) {
5292 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5292, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
5293
5294 va_start(ap, format)__builtin_va_start(ap, format);
5295 proto_tree_set_representation(pi, format, ap);
5296 va_end(ap)__builtin_va_end(ap);
5297 }
5298
5299 return pi;
5300}
5301
5302/* Set the FT_IPv4 value */
5303static void
5304proto_tree_set_ipv4(field_info *fi, ws_in4_addr value)
5305{
5306 ipv4_addr_and_mask ipv4;
5307 ws_ipv4_addr_and_mask_init(&ipv4, value, 32);
5308 fvalue_set_ipv4(fi->value, &ipv4);
5309}
5310
5311/* Add a FT_IPv6 to a proto_tree */
5312proto_item *
5313proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
5314 unsigned length, const ws_in6_addr *value)
5315{
5316 proto_item *pi;
5317 header_field_info *hfinfo;
5318
5319 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
5320
5321 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5321
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5321, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5321, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5321, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
5322
5323 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_IPv6)((void) (((hfinfo)->type == FT_IPv6) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_IPv6", "epan/proto.c", 5323
, ((hfinfo))->abbrev))))
;
5324
5325 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
5326 proto_tree_set_ipv6(PNODE_FINFO(pi)((pi)->finfo), value);
5327
5328 return pi;
5329}
5330
5331proto_item *
5332proto_tree_add_ipv6_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5333 unsigned start, unsigned length,
5334 const ws_in6_addr *value_ptr,
5335 const char *format, ...)
5336{
5337 proto_item *pi;
5338 va_list ap;
5339
5340 pi = proto_tree_add_ipv6(tree, hfindex, tvb, start, length, value_ptr);
5341 if (pi != tree) {
5342 va_start(ap, format)__builtin_va_start(ap, format);
5343 proto_tree_set_representation_value(pi, format, ap);
5344 va_end(ap)__builtin_va_end(ap);
5345 }
5346
5347 return pi;
5348}
5349
5350proto_item *
5351proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5352 unsigned start, unsigned length,
5353 const ws_in6_addr *value_ptr,
5354 const char *format, ...)
5355{
5356 proto_item *pi;
5357 va_list ap;
5358
5359 pi = proto_tree_add_ipv6(tree, hfindex, tvb, start, length, value_ptr);
5360 if (pi != tree) {
5361 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5361, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
5362
5363 va_start(ap, format)__builtin_va_start(ap, format);
5364 proto_tree_set_representation(pi, format, ap);
5365 va_end(ap)__builtin_va_end(ap);
5366 }
5367
5368 return pi;
5369}
5370
5371/* Set the FT_IPv6 value */
5372static void
5373proto_tree_set_ipv6(field_info *fi, const ws_in6_addr *value)
5374{
5375 DISSECTOR_ASSERT(value != NULL)((void) ((value != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 5375, "value != ((void*)0)"
))))
;
5376 ipv6_addr_and_prefix ipv6;
5377 ipv6.addr = *value;
5378 ipv6.prefix = 128;
5379 fvalue_set_ipv6(fi->value, &ipv6);
5380}
5381
5382static void
5383proto_tree_set_ipv6_tvb(field_info *fi, tvbuff_t *tvb, unsigned start, unsigned length)
5384{
5385 proto_tree_set_ipv6(fi, (const ws_in6_addr *)tvb_get_ptr(tvb, start, length));
5386}
5387
5388/* Set the FT_FCWWN value */
5389static void
5390proto_tree_set_fcwwn(field_info *fi, const uint8_t* value_ptr)
5391{
5392 DISSECTOR_ASSERT(value_ptr != NULL)((void) ((value_ptr != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 5392, "value_ptr != ((void*)0)"
))))
;
5393 fvalue_set_fcwwn(fi->value, value_ptr);
5394}
5395
5396static void
5397proto_tree_set_fcwwn_tvb(field_info *fi, tvbuff_t *tvb, unsigned start, unsigned length)
5398{
5399 proto_tree_set_fcwwn(fi, tvb_get_ptr(tvb, start, length));
5400}
5401
5402/* Add a FT_GUID to a proto_tree */
5403proto_item *
5404proto_tree_add_guid(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
5405 unsigned length, const e_guid_t *value_ptr)
5406{
5407 proto_item *pi;
5408 header_field_info *hfinfo;
5409
5410 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
5411
5412 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5412
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5412, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5412, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5412, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
5413
5414 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_GUID)((void) (((hfinfo)->type == FT_GUID) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_GUID", "epan/proto.c", 5414
, ((hfinfo))->abbrev))))
;
5415
5416 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
5417 proto_tree_set_guid(PNODE_FINFO(pi)((pi)->finfo), value_ptr);
5418
5419 return pi;
5420}
5421
5422proto_item *
5423proto_tree_add_guid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5424 unsigned start, unsigned length,
5425 const e_guid_t *value_ptr,
5426 const char *format, ...)
5427{
5428 proto_item *pi;
5429 va_list ap;
5430
5431 pi = proto_tree_add_guid(tree, hfindex, tvb, start, length, value_ptr);
5432 if (pi != tree) {
5433 va_start(ap, format)__builtin_va_start(ap, format);
5434 proto_tree_set_representation_value(pi, format, ap);
5435 va_end(ap)__builtin_va_end(ap);
5436 }
5437
5438 return pi;
5439}
5440
5441proto_item *
5442proto_tree_add_guid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5443 unsigned start, unsigned length, const e_guid_t *value_ptr,
5444 const char *format, ...)
5445{
5446 proto_item *pi;
5447 va_list ap;
5448
5449 pi = proto_tree_add_guid(tree, hfindex, tvb, start, length, value_ptr);
5450 if (pi != tree) {
5451 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5451, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
5452
5453 va_start(ap, format)__builtin_va_start(ap, format);
5454 proto_tree_set_representation(pi, format, ap);
5455 va_end(ap)__builtin_va_end(ap);
5456 }
5457
5458 return pi;
5459}
5460
5461/* Set the FT_GUID value */
5462static void
5463proto_tree_set_guid(field_info *fi, const e_guid_t *value_ptr)
5464{
5465 DISSECTOR_ASSERT(value_ptr != NULL)((void) ((value_ptr != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 5465, "value_ptr != ((void*)0)"
))))
;
5466 fvalue_set_guid(fi->value, value_ptr);
5467}
5468
5469static void
5470proto_tree_set_guid_tvb(field_info *fi, tvbuff_t *tvb, unsigned start,
5471 const unsigned encoding)
5472{
5473 e_guid_t guid;
5474
5475 tvb_get_guid(tvb, start, &guid, encoding);
5476 proto_tree_set_guid(fi, &guid);
5477}
5478
5479/* Add a FT_OID to a proto_tree */
5480proto_item *
5481proto_tree_add_oid(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
5482 unsigned length, const uint8_t* value_ptr)
5483{
5484 proto_item *pi;
5485 header_field_info *hfinfo;
5486
5487 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
5488
5489 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5489
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5489, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5489, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5489, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
5490
5491 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_OID)((void) (((hfinfo)->type == FT_OID) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_OID", "epan/proto.c", 5491
, ((hfinfo))->abbrev))))
;
5492
5493 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
5494 proto_tree_set_oid(PNODE_FINFO(pi)((pi)->finfo), value_ptr, length);
5495
5496 return pi;
5497}
5498
5499proto_item *
5500proto_tree_add_oid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5501 unsigned start, unsigned length,
5502 const uint8_t* value_ptr,
5503 const char *format, ...)
5504{
5505 proto_item *pi;
5506 va_list ap;
5507
5508 pi = proto_tree_add_oid(tree, hfindex, tvb, start, length, value_ptr);
5509 if (pi != tree) {
5510 va_start(ap, format)__builtin_va_start(ap, format);
5511 proto_tree_set_representation_value(pi, format, ap);
5512 va_end(ap)__builtin_va_end(ap);
5513 }
5514
5515 return pi;
5516}
5517
5518proto_item *
5519proto_tree_add_oid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5520 unsigned start, unsigned length, const uint8_t* value_ptr,
5521 const char *format, ...)
5522{
5523 proto_item *pi;
5524 va_list ap;
5525
5526 pi = proto_tree_add_oid(tree, hfindex, tvb, start, length, value_ptr);
5527 if (pi != tree) {
5528 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5528, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
5529
5530 va_start(ap, format)__builtin_va_start(ap, format);
5531 proto_tree_set_representation(pi, format, ap);
5532 va_end(ap)__builtin_va_end(ap);
5533 }
5534
5535 return pi;
5536}
5537
5538/* Set the FT_OID value */
5539static void
5540proto_tree_set_oid(field_info *fi, const uint8_t* value_ptr, unsigned length)
5541{
5542 GByteArray *bytes;
5543
5544 DISSECTOR_ASSERT(value_ptr != NULL || length == 0)((void) ((value_ptr != ((void*)0) || length == 0) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 5544, "value_ptr != ((void*)0) || length == 0"
))))
;
5545
5546 bytes = g_byte_array_new();
5547 if (length > 0) {
5548 g_byte_array_append(bytes, value_ptr, length);
5549 }
5550 fvalue_set_byte_array(fi->value, bytes);
5551}
5552
5553static void
5554proto_tree_set_oid_tvb(field_info *fi, tvbuff_t *tvb, unsigned start, unsigned length)
5555{
5556 proto_tree_set_oid(fi, tvb_get_ptr(tvb, start, length), length);
5557}
5558
5559/* Set the FT_SYSTEM_ID value */
5560static void
5561proto_tree_set_system_id(field_info *fi, const uint8_t* value_ptr, unsigned length)
5562{
5563 GByteArray *bytes;
5564
5565 DISSECTOR_ASSERT(value_ptr != NULL || length == 0)((void) ((value_ptr != ((void*)0) || length == 0) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 5565, "value_ptr != ((void*)0) || length == 0"
))))
;
5566
5567 bytes = g_byte_array_new();
5568 if (length > 0) {
5569 g_byte_array_append(bytes, value_ptr, length);
5570 }
5571 fvalue_set_byte_array(fi->value, bytes);
5572}
5573
5574static void
5575proto_tree_set_system_id_tvb(field_info *fi, tvbuff_t *tvb, unsigned start, unsigned length)
5576{
5577 proto_tree_set_system_id(fi, tvb_get_ptr(tvb, start, length), length);
5578}
5579
5580/* Add a FT_STRING, FT_STRINGZ, FT_STRINGZPAD, or FT_STRINGZTRUNC to a
5581 * proto_tree. Creates own copy of string, and frees it when the proto_tree
5582 * is destroyed. */
5583proto_item *
5584proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
5585 int length, const char* value)
5586{
5587 proto_item *pi;
5588 header_field_info *hfinfo;
5589 int item_length;
5590
5591 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5591, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 5591,
"hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5591, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
5592 get_hfi_length(hfinfo, tvb, start, &length, &item_length, ENC_NA0x00000000);
5593 /*
5594 * Special case - if the length is 0, skip the test, so that
5595 * we can have an empty string right after the end of the
5596 * packet. (This handles URL-encoded forms where the last field
5597 * has no value so the form ends right after the =.)
5598 *
5599 * XXX - length zero makes sense for FT_STRING, and more or less
5600 * for FT_STRINGZTRUNC, and FT_STRINGZPAD, but doesn't make sense
5601 * for FT_STRINGZ (except that a number of fields that should be
5602 * one of the others are actually registered as FT_STRINGZ.)
5603 */
5604 if (item_length != 0)
5605 test_length(hfinfo, tvb, start, item_length, ENC_NA0x00000000);
5606
5607 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
5608
5609 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5609
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5609, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5609, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5609, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
5610
5611 DISSECTOR_ASSERT_FIELD_TYPE_IS_STRING(hfinfo)((void) ((((hfinfo)->type) == FT_STRING || ((hfinfo)->type
) == FT_STRINGZ || ((hfinfo)->type) == FT_STRINGZPAD || ((
hfinfo)->type) == FT_STRINGZTRUNC || ((hfinfo)->type) ==
FT_UINT_STRING || ((hfinfo)->type) == FT_AX25) ? (void)0 :
(proto_report_dissector_bug("%s:%u: field %s is not of type FT_STRING, FT_STRINGZ, FT_STRINGZPAD, FT_STRINGZTRUNC, or FT_UINT_STRING"
, "epan/proto.c", 5611, ((hfinfo))->abbrev))))
;
5612
5613 pi = proto_tree_add_pi(tree, hfinfo, tvb, start, &length);
5614 DISSECTOR_ASSERT(length >= 0)((void) ((length >= 0) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 5614, "length >= 0"
))))
;
5615
5616 WS_UTF_8_CHECK(value, -1)do { const char *__uni_endptr; if (1 && (value) != ((
void*)0) && !g_utf8_validate(value, -1, &__uni_endptr
)) { do { if (1) { ws_log_utf8_full("UTF-8", LOG_LEVEL_DEBUG,
"epan/proto.c", 5616, __func__, value, -1, __uni_endptr); } }
while (0); } } while (0)
;
5617 proto_tree_set_string(PNODE_FINFO(pi)((pi)->finfo), value);
5618
5619 return pi;
5620}
5621
5622proto_item *
5623proto_tree_add_string_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5624 unsigned start, int length, const char* value,
5625 const char *format,
5626 ...)
5627{
5628 proto_item *pi;
5629 va_list ap;
5630
5631 pi = proto_tree_add_string(tree, hfindex, tvb, start, length, value);
5632 if (pi != tree) {
5633 va_start(ap, format)__builtin_va_start(ap, format);
5634 proto_tree_set_representation_value(pi, format, ap);
5635 va_end(ap)__builtin_va_end(ap);
5636 }
5637
5638 return pi;
5639}
5640
5641proto_item *
5642proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5643 unsigned start, int length, const char* value,
5644 const char *format, ...)
5645{
5646 proto_item *pi;
5647 va_list ap;
5648
5649 pi = proto_tree_add_string(tree, hfindex, tvb, start, length, value);
5650 if (pi != tree) {
5651 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5651, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
5652
5653 va_start(ap, format)__builtin_va_start(ap, format);
5654 proto_tree_set_representation(pi, format, ap);
5655 va_end(ap)__builtin_va_end(ap);
5656 }
5657
5658 return pi;
5659}
5660
5661/* Set the FT_STRING value */
5662static void
5663proto_tree_set_string(field_info *fi, const char* value)
5664{
5665 if (value) {
5666 fvalue_set_string(fi->value, value);
5667 } else {
5668 /*
5669 * XXX - why is a null value for a string field
5670 * considered valid?
5671 */
5672 fvalue_set_string(fi->value, "[ Null ]");
5673 }
5674}
5675
5676/* Set the FT_AX25 value */
5677static void
5678proto_tree_set_ax25(field_info *fi, const uint8_t* value)
5679{
5680 fvalue_set_ax25(fi->value, value);
5681}
5682
5683static void
5684proto_tree_set_ax25_tvb(field_info *fi, tvbuff_t *tvb, unsigned start)
5685{
5686 proto_tree_set_ax25(fi, tvb_get_ptr(tvb, start, 7));
5687}
5688
5689/* Set the FT_VINES value */
5690static void
5691proto_tree_set_vines(field_info *fi, const uint8_t* value)
5692{
5693 fvalue_set_vines(fi->value, value);
5694}
5695
5696static void
5697proto_tree_set_vines_tvb(field_info *fi, tvbuff_t *tvb, unsigned start)
5698{
5699 proto_tree_set_vines(fi, tvb_get_ptr(tvb, start, FT_VINES_ADDR_LEN6));
5700}
5701
5702/* Add a FT_ETHER to a proto_tree */
5703proto_item *
5704proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
5705 unsigned length, const uint8_t* value)
5706{
5707 proto_item *pi;
5708 header_field_info *hfinfo;
5709
5710 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
5711
5712 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5712
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5712, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5712, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5712, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
5713
5714 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_ETHER)((void) (((hfinfo)->type == FT_ETHER) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_ETHER", "epan/proto.c",
5714, ((hfinfo))->abbrev))))
;
5715
5716 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
5717 proto_tree_set_ether(PNODE_FINFO(pi)((pi)->finfo), value);
5718
5719 return pi;
5720}
5721
5722proto_item *
5723proto_tree_add_ether_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5724 unsigned start, unsigned length, const uint8_t* value,
5725 const char *format, ...)
5726{
5727 proto_item *pi;
5728 va_list ap;
5729
5730 pi = proto_tree_add_ether(tree, hfindex, tvb, start, length, value);
5731 if (pi != tree) {
5732 va_start(ap, format)__builtin_va_start(ap, format);
5733 proto_tree_set_representation_value(pi, format, ap);
5734 va_end(ap)__builtin_va_end(ap);
5735 }
5736
5737 return pi;
5738}
5739
5740proto_item *
5741proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5742 unsigned start, unsigned length, const uint8_t* value,
5743 const char *format, ...)
5744{
5745 proto_item *pi;
5746 va_list ap;
5747
5748 pi = proto_tree_add_ether(tree, hfindex, tvb, start, length, value);
5749 if (pi != tree) {
5750 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5750, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
5751
5752 va_start(ap, format)__builtin_va_start(ap, format);
5753 proto_tree_set_representation(pi, format, ap);
5754 va_end(ap)__builtin_va_end(ap);
5755 }
5756
5757 return pi;
5758}
5759
5760/* Set the FT_ETHER value */
5761static void
5762proto_tree_set_ether(field_info *fi, const uint8_t* value)
5763{
5764 fvalue_set_ether(fi->value, value);
5765}
5766
5767static void
5768proto_tree_set_ether_tvb(field_info *fi, tvbuff_t *tvb, unsigned start)
5769{
5770 proto_tree_set_ether(fi, tvb_get_ptr(tvb, start, FT_ETHER_LEN6));
5771}
5772
5773/* Add a FT_BOOLEAN to a proto_tree */
5774proto_item *
5775proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
5776 unsigned length, uint64_t value)
5777{
5778 proto_item *pi;
5779 header_field_info *hfinfo;
5780
5781 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
5782
5783 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5783
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5783, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5783, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5783, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
5784
5785 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_BOOLEAN)((void) (((hfinfo)->type == FT_BOOLEAN) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_BOOLEAN", "epan/proto.c"
, 5785, ((hfinfo))->abbrev))))
;
5786
5787 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
5788 proto_tree_set_boolean(PNODE_FINFO(pi)((pi)->finfo), value);
5789
5790 return pi;
5791}
5792
5793proto_item *
5794proto_tree_add_boolean_format_value(proto_tree *tree, int hfindex,
5795 tvbuff_t *tvb, unsigned start, unsigned length,
5796 uint64_t value, const char *format, ...)
5797{
5798 proto_item *pi;
5799 va_list ap;
5800
5801 pi = proto_tree_add_boolean(tree, hfindex, tvb, start, length, value);
5802 if (pi != tree) {
5803 va_start(ap, format)__builtin_va_start(ap, format);
5804 proto_tree_set_representation_value(pi, format, ap);
5805 va_end(ap)__builtin_va_end(ap);
5806 }
5807
5808 return pi;
5809}
5810
5811proto_item *
5812proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5813 unsigned start, unsigned length, uint64_t value,
5814 const char *format, ...)
5815{
5816 proto_item *pi;
5817 va_list ap;
5818
5819 pi = proto_tree_add_boolean(tree, hfindex, tvb, start, length, value);
5820 if (pi != tree) {
5821 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5821, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
5822
5823 va_start(ap, format)__builtin_va_start(ap, format);
5824 proto_tree_set_representation(pi, format, ap);
5825 va_end(ap)__builtin_va_end(ap);
5826 }
5827
5828 return pi;
5829}
5830
5831/* Set the FT_BOOLEAN value */
5832static void
5833proto_tree_set_boolean(field_info *fi, uint64_t value)
5834{
5835 proto_tree_set_uint64(fi, value);
5836}
5837
5838/* Generate, into "buf", a string showing the bits of a bitfield.
5839 Return a pointer to the character after that string. */
5840static char *
5841other_decode_bitfield_value(char *buf, const uint64_t val, const uint64_t mask, const int width)
5842{
5843 int i = 0;
5844 uint64_t bit;
5845 char *p;
5846
5847 p = buf;
5848
5849 /* This is a devel error. It is safer to stop here. */
5850 DISSECTOR_ASSERT(width >= 1)((void) ((width >= 1) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 5850, "width >= 1"
))))
;
5851
5852 bit = UINT64_C(1)1UL << (width - 1);
5853 for (;;) {
5854 if (mask & bit) {
5855 /* This bit is part of the field. Show its value. */
5856 if (val & bit)
5857 *p++ = '1';
5858 else
5859 *p++ = '0';
5860 } else {
5861 /* This bit is not part of the field. */
5862 *p++ = '.';
5863 }
5864 bit >>= 1;
5865 i++;
5866 if (i >= width)
5867 break;
5868 if (i % 4 == 0)
5869 *p++ = ' ';
5870 }
5871 *p = '\0';
5872 return p;
5873}
5874
5875static char *
5876decode_bitfield_value(char *buf, const uint64_t val, const uint64_t mask, const int width)
5877{
5878 char *p;
5879
5880 p = other_decode_bitfield_value(buf, val, mask, width);
5881 p = g_stpcpy(p, " = ");
5882
5883 return p;
5884}
5885
5886static char *
5887other_decode_bitfield_varint_value(char *buf, uint64_t val, uint64_t mask, const int width)
5888{
5889 int i = 0;
5890 uint64_t bit;
5891 char *p;
5892
5893 p = buf;
5894
5895 /* This is a devel error. It is safer to stop here. */
5896 DISSECTOR_ASSERT(width >= 1)((void) ((width >= 1) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 5896, "width >= 1"
))))
;
5897
5898 bit = UINT64_C(1)1UL << (width - 1);
5899 for (;;) {
5900 if (((8-(i % 8)) != 8) && /* MSB is never used for value. */
5901 (mask & bit)) {
5902 /* This bit is part of the field. Show its value. */
5903 if (val & bit)
5904 *p++ = '1';
5905 else
5906 *p++ = '0';
5907 } else {
5908 /* This bit is not part of the field. */
5909 *p++ = '.';
5910 }
5911 bit >>= 1;
5912 i++;
5913 if (i >= width)
5914 break;
5915 if (i % 4 == 0)
5916 *p++ = ' ';
5917 }
5918
5919 *p = '\0';
5920 return p;
5921}
5922
5923static char *
5924decode_bitfield_varint_value(char *buf, const uint64_t val, const uint64_t mask, const int width)
5925{
5926 char *p;
5927
5928 p = other_decode_bitfield_varint_value(buf, val, mask, width);
5929 p = g_stpcpy(p, " = ");
5930
5931 return p;
5932}
5933
5934/* Add a FT_FLOAT to a proto_tree */
5935proto_item *
5936proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
5937 unsigned length, float value)
5938{
5939 proto_item *pi;
5940 header_field_info *hfinfo;
5941
5942 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
5943
5944 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5944
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5944, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 5944, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 5944, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
5945
5946 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_FLOAT)((void) (((hfinfo)->type == FT_FLOAT) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_FLOAT", "epan/proto.c",
5946, ((hfinfo))->abbrev))))
;
5947
5948 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
5949 proto_tree_set_float(PNODE_FINFO(pi)((pi)->finfo), value);
5950
5951 return pi;
5952}
5953
5954proto_item *
5955proto_tree_add_float_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5956 unsigned start, unsigned length, float value,
5957 const char *format, ...)
5958{
5959 proto_item *pi;
5960 va_list ap;
5961
5962 pi = proto_tree_add_float(tree, hfindex, tvb, start, length, value);
5963 if (pi != tree) {
5964 va_start(ap, format)__builtin_va_start(ap, format);
5965 proto_tree_set_representation_value(pi, format, ap);
5966 va_end(ap)__builtin_va_end(ap);
5967 }
5968
5969 return pi;
5970}
5971
5972proto_item *
5973proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
5974 unsigned start, unsigned length, float value,
5975 const char *format, ...)
5976{
5977 proto_item *pi;
5978 va_list ap;
5979
5980 pi = proto_tree_add_float(tree, hfindex, tvb, start, length, value);
5981 if (pi != tree) {
5982 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 5982, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
5983
5984 va_start(ap, format)__builtin_va_start(ap, format);
5985 proto_tree_set_representation(pi, format, ap);
5986 va_end(ap)__builtin_va_end(ap);
5987 }
5988
5989 return pi;
5990}
5991
5992/* Set the FT_FLOAT value */
5993static void
5994proto_tree_set_float(field_info *fi, float value)
5995{
5996 fvalue_set_floating(fi->value, value);
5997}
5998
5999/* Add a FT_DOUBLE to a proto_tree */
6000proto_item *
6001proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
6002 unsigned length, double value)
6003{
6004 proto_item *pi;
6005 header_field_info *hfinfo;
6006
6007 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
6008
6009 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6009
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 6009, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 6009, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6009, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
6010
6011 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_DOUBLE)((void) (((hfinfo)->type == FT_DOUBLE) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_DOUBLE", "epan/proto.c"
, 6011, ((hfinfo))->abbrev))))
;
6012
6013 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
6014 proto_tree_set_double(PNODE_FINFO(pi)((pi)->finfo), value);
6015
6016 return pi;
6017}
6018
6019proto_item *
6020proto_tree_add_double_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
6021 unsigned start, unsigned length, double value,
6022 const char *format, ...)
6023{
6024 proto_item *pi;
6025 va_list ap;
6026
6027 pi = proto_tree_add_double(tree, hfindex, tvb, start, length, value);
6028 if (pi != tree) {
6029 va_start(ap, format)__builtin_va_start(ap, format);
6030 proto_tree_set_representation_value(pi, format, ap);
6031 va_end(ap)__builtin_va_end(ap);
6032 }
6033
6034 return pi;
6035}
6036
6037proto_item *
6038proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
6039 unsigned start, unsigned length, double value,
6040 const char *format, ...)
6041{
6042 proto_item *pi;
6043 va_list ap;
6044
6045 pi = proto_tree_add_double(tree, hfindex, tvb, start, length, value);
6046 if (pi != tree) {
6047 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 6047, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
6048
6049 va_start(ap, format)__builtin_va_start(ap, format);
6050 proto_tree_set_representation(pi, format, ap);
6051 va_end(ap)__builtin_va_end(ap);
6052 }
6053
6054 return pi;
6055}
6056
6057/* Set the FT_DOUBLE value */
6058static void
6059proto_tree_set_double(field_info *fi, double value)
6060{
6061 fvalue_set_floating(fi->value, value);
6062}
6063
6064/* Add FT_CHAR or FT_UINT{8,16,24,32} to a proto_tree */
6065proto_item *
6066proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
6067 unsigned length, uint32_t value)
6068{
6069 proto_item *pi = NULL((void*)0);
6070 header_field_info *hfinfo;
6071
6072 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
6073
6074 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6074
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 6074, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 6074, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6074, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
6075
6076 switch (hfinfo->type) {
6077 case FT_CHAR:
6078 case FT_UINT8:
6079 case FT_UINT16:
6080 case FT_UINT24:
6081 case FT_UINT32:
6082 case FT_FRAMENUM:
6083 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
6084 proto_tree_set_uint(PNODE_FINFO(pi)((pi)->finfo), value);
6085 break;
6086
6087 default:
6088 REPORT_DISSECTOR_BUG("field %s is not of type FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, FT_UINT32, or FT_FRAMENUM",proto_report_dissector_bug("field %s is not of type FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, FT_UINT32, or FT_FRAMENUM"
, hfinfo->abbrev)
6089 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_CHAR, FT_UINT8, FT_UINT16, FT_UINT24, FT_UINT32, or FT_FRAMENUM"
, hfinfo->abbrev)
;
6090 }
6091
6092 return pi;
6093}
6094
6095proto_item *
6096proto_tree_add_uint_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
6097 unsigned start, unsigned length, uint32_t value,
6098 const char *format, ...)
6099{
6100 proto_item *pi;
6101 va_list ap;
6102
6103 pi = proto_tree_add_uint(tree, hfindex, tvb, start, length, value);
6104 if (pi != tree) {
6105 va_start(ap, format)__builtin_va_start(ap, format);
6106 proto_tree_set_representation_value(pi, format, ap);
6107 va_end(ap)__builtin_va_end(ap);
6108 }
6109
6110 return pi;
6111}
6112
6113proto_item *
6114proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
6115 unsigned start, unsigned length, uint32_t value,
6116 const char *format, ...)
6117{
6118 proto_item *pi;
6119 va_list ap;
6120
6121 pi = proto_tree_add_uint(tree, hfindex, tvb, start, length, value);
6122 if (pi != tree) {
6123 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 6123, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
6124
6125 va_start(ap, format)__builtin_va_start(ap, format);
6126 proto_tree_set_representation(pi, format, ap);
6127 va_end(ap)__builtin_va_end(ap);
6128 }
6129
6130 return pi;
6131}
6132
6133/* Set the FT_UINT{8,16,24,32} value */
6134static void
6135proto_tree_set_uint(field_info *fi, uint32_t value)
6136{
6137 const header_field_info *hfinfo;
6138 uint32_t integer;
6139
6140 hfinfo = fi->hfinfo;
6141 integer = value;
6142
6143 if (hfinfo->bitmask) {
6144 /* Mask out irrelevant portions */
6145 integer &= (uint32_t)(hfinfo->bitmask);
6146
6147 /* Shift bits */
6148 integer >>= hfinfo_bitshift(hfinfo);
6149
6150 FI_SET_FLAG(fi, FI_BITS_OFFSET(hfinfo_bitoffset(hfinfo)))do { if (fi) (fi)->flags = (fi)->flags | ((((hfinfo_bitoffset
(hfinfo)) & 63) << 5)); } while(0)
;
6151 FI_SET_FLAG(fi, FI_BITS_SIZE(hfinfo_mask_bitwidth(hfinfo)))do { if (fi) (fi)->flags = (fi)->flags | ((((hfinfo_mask_bitwidth
(hfinfo)) & 63) << 12)); } while(0)
;
6152 }
6153
6154 fvalue_set_uinteger(fi->value, integer);
6155}
6156
6157/* Add FT_UINT{40,48,56,64} to a proto_tree */
6158proto_item *
6159proto_tree_add_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
6160 unsigned length, uint64_t value)
6161{
6162 proto_item *pi = NULL((void*)0);
6163 header_field_info *hfinfo;
6164
6165 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
6166
6167 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6167
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 6167, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 6167, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6167, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
6168
6169 switch (hfinfo->type) {
6170 case FT_UINT40:
6171 case FT_UINT48:
6172 case FT_UINT56:
6173 case FT_UINT64:
6174 case FT_FRAMENUM:
6175 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
6176 proto_tree_set_uint64(PNODE_FINFO(pi)((pi)->finfo), value);
6177 break;
6178
6179 default:
6180 REPORT_DISSECTOR_BUG("field %s is not of type FT_UINT40, FT_UINT48, FT_UINT56, FT_UINT64, or FT_FRAMENUM",proto_report_dissector_bug("field %s is not of type FT_UINT40, FT_UINT48, FT_UINT56, FT_UINT64, or FT_FRAMENUM"
, hfinfo->abbrev)
6181 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_UINT40, FT_UINT48, FT_UINT56, FT_UINT64, or FT_FRAMENUM"
, hfinfo->abbrev)
;
6182 }
6183
6184 return pi;
6185}
6186
6187proto_item *
6188proto_tree_add_uint64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
6189 unsigned start, unsigned length, uint64_t value,
6190 const char *format, ...)
6191{
6192 proto_item *pi;
6193 va_list ap;
6194
6195 pi = proto_tree_add_uint64(tree, hfindex, tvb, start, length, value);
6196 if (pi != tree) {
6197 va_start(ap, format)__builtin_va_start(ap, format);
6198 proto_tree_set_representation_value(pi, format, ap);
6199 va_end(ap)__builtin_va_end(ap);
6200 }
6201
6202 return pi;
6203}
6204
6205proto_item *
6206proto_tree_add_uint64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
6207 unsigned start, unsigned length, uint64_t value,
6208 const char *format, ...)
6209{
6210 proto_item *pi;
6211 va_list ap;
6212
6213 pi = proto_tree_add_uint64(tree, hfindex, tvb, start, length, value);
6214 if (pi != tree) {
6215 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 6215, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
6216
6217 va_start(ap, format)__builtin_va_start(ap, format);
6218 proto_tree_set_representation(pi, format, ap);
6219 va_end(ap)__builtin_va_end(ap);
6220 }
6221
6222 return pi;
6223}
6224
6225/* Set the FT_UINT{40,48,56,64} value */
6226static void
6227proto_tree_set_uint64(field_info *fi, uint64_t value)
6228{
6229 const header_field_info *hfinfo;
6230 uint64_t integer;
6231
6232 hfinfo = fi->hfinfo;
6233 integer = value;
6234
6235 if (hfinfo->bitmask) {
6236 /* Mask out irrelevant portions */
6237 integer &= hfinfo->bitmask;
6238
6239 /* Shift bits */
6240 integer >>= hfinfo_bitshift(hfinfo);
6241
6242 FI_SET_FLAG(fi, FI_BITS_OFFSET(hfinfo_bitoffset(hfinfo)))do { if (fi) (fi)->flags = (fi)->flags | ((((hfinfo_bitoffset
(hfinfo)) & 63) << 5)); } while(0)
;
6243 FI_SET_FLAG(fi, FI_BITS_SIZE(hfinfo_mask_bitwidth(hfinfo)))do { if (fi) (fi)->flags = (fi)->flags | ((((hfinfo_mask_bitwidth
(hfinfo)) & 63) << 12)); } while(0)
;
6244 }
6245
6246 fvalue_set_uinteger64(fi->value, integer);
6247}
6248
6249/* Add FT_INT{8,16,24,32} to a proto_tree */
6250proto_item *
6251proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
6252 unsigned length, int32_t value)
6253{
6254 proto_item *pi = NULL((void*)0);
6255 header_field_info *hfinfo;
6256
6257 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
6258
6259 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6259
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 6259, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 6259, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6259, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
6260
6261 switch (hfinfo->type) {
6262 case FT_INT8:
6263 case FT_INT16:
6264 case FT_INT24:
6265 case FT_INT32:
6266 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
6267 proto_tree_set_int(PNODE_FINFO(pi)((pi)->finfo), value);
6268 break;
6269
6270 default:
6271 REPORT_DISSECTOR_BUG("field %s is not of type FT_INT8, FT_INT16, FT_INT24, or FT_INT32",proto_report_dissector_bug("field %s is not of type FT_INT8, FT_INT16, FT_INT24, or FT_INT32"
, hfinfo->abbrev)
6272 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_INT8, FT_INT16, FT_INT24, or FT_INT32"
, hfinfo->abbrev)
;
6273 }
6274
6275 return pi;
6276}
6277
6278proto_item *
6279proto_tree_add_int_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
6280 unsigned start, unsigned length, int32_t value,
6281 const char *format, ...)
6282{
6283 proto_item *pi;
6284 va_list ap;
6285
6286 pi = proto_tree_add_int(tree, hfindex, tvb, start, length, value);
6287 if (pi != tree) {
6288 va_start(ap, format)__builtin_va_start(ap, format);
6289 proto_tree_set_representation_value(pi, format, ap);
6290 va_end(ap)__builtin_va_end(ap);
6291 }
6292
6293 return pi;
6294}
6295
6296proto_item *
6297proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
6298 unsigned start, unsigned length, int32_t value,
6299 const char *format, ...)
6300{
6301 proto_item *pi;
6302 va_list ap;
6303
6304 pi = proto_tree_add_int(tree, hfindex, tvb, start, length, value);
6305 if (pi != tree) {
6306 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 6306, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
6307
6308 va_start(ap, format)__builtin_va_start(ap, format);
6309 proto_tree_set_representation(pi, format, ap);
6310 va_end(ap)__builtin_va_end(ap);
6311 }
6312
6313 return pi;
6314}
6315
6316/* Set the FT_INT{8,16,24,32} value */
6317static void
6318proto_tree_set_int(field_info *fi, int32_t value)
6319{
6320 const header_field_info *hfinfo;
6321 uint32_t integer;
6322 int no_of_bits;
6323
6324 hfinfo = fi->hfinfo;
6325 integer = (uint32_t) value;
6326
6327 if (hfinfo->bitmask) {
6328 /* Mask out irrelevant portions */
6329 integer &= (uint32_t)(hfinfo->bitmask);
6330
6331 /* Shift bits */
6332 integer >>= hfinfo_bitshift(hfinfo);
6333
6334 no_of_bits = ws_count_ones(hfinfo->bitmask);
6335 integer = ws_sign_ext32(integer, no_of_bits);
6336
6337 FI_SET_FLAG(fi, FI_BITS_OFFSET(hfinfo_bitoffset(hfinfo)))do { if (fi) (fi)->flags = (fi)->flags | ((((hfinfo_bitoffset
(hfinfo)) & 63) << 5)); } while(0)
;
6338 FI_SET_FLAG(fi, FI_BITS_SIZE(hfinfo_mask_bitwidth(hfinfo)))do { if (fi) (fi)->flags = (fi)->flags | ((((hfinfo_mask_bitwidth
(hfinfo)) & 63) << 12)); } while(0)
;
6339 }
6340
6341 fvalue_set_sinteger(fi->value, integer);
6342}
6343
6344/* Add FT_INT{40,48,56,64} to a proto_tree */
6345proto_item *
6346proto_tree_add_int64(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
6347 unsigned length, int64_t value)
6348{
6349 proto_item *pi = NULL((void*)0);
6350 header_field_info *hfinfo;
6351
6352 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
6353
6354 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6354
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 6354, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 6354, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6354, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
6355
6356 switch (hfinfo->type) {
6357 case FT_INT40:
6358 case FT_INT48:
6359 case FT_INT56:
6360 case FT_INT64:
6361 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
6362 proto_tree_set_int64(PNODE_FINFO(pi)((pi)->finfo), value);
6363 break;
6364
6365 default:
6366 REPORT_DISSECTOR_BUG("field %s is not of type FT_INT40, FT_INT48, FT_INT56, or FT_INT64",proto_report_dissector_bug("field %s is not of type FT_INT40, FT_INT48, FT_INT56, or FT_INT64"
, hfinfo->abbrev)
6367 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_INT40, FT_INT48, FT_INT56, or FT_INT64"
, hfinfo->abbrev)
;
6368 }
6369
6370 return pi;
6371}
6372
6373proto_item *
6374proto_tree_add_int64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
6375 unsigned start, unsigned length, int64_t value,
6376 const char *format, ...)
6377{
6378 proto_item *pi;
6379 va_list ap;
6380
6381 pi = proto_tree_add_int64(tree, hfindex, tvb, start, length, value);
6382 if (pi != tree) {
6383 va_start(ap, format)__builtin_va_start(ap, format);
6384 proto_tree_set_representation_value(pi, format, ap);
6385 va_end(ap)__builtin_va_end(ap);
6386 }
6387
6388 return pi;
6389}
6390
6391/* Set the FT_INT{40,48,56,64} value */
6392static void
6393proto_tree_set_int64(field_info *fi, int64_t value)
6394{
6395 const header_field_info *hfinfo;
6396 uint64_t integer;
6397 int no_of_bits;
6398
6399 hfinfo = fi->hfinfo;
6400 integer = value;
6401
6402 if (hfinfo->bitmask) {
6403 /* Mask out irrelevant portions */
6404 integer &= hfinfo->bitmask;
6405
6406 /* Shift bits */
6407 integer >>= hfinfo_bitshift(hfinfo);
6408
6409 no_of_bits = ws_count_ones(hfinfo->bitmask);
6410 integer = ws_sign_ext64(integer, no_of_bits);
6411
6412 FI_SET_FLAG(fi, FI_BITS_OFFSET(hfinfo_bitoffset(hfinfo)))do { if (fi) (fi)->flags = (fi)->flags | ((((hfinfo_bitoffset
(hfinfo)) & 63) << 5)); } while(0)
;
6413 FI_SET_FLAG(fi, FI_BITS_SIZE(hfinfo_mask_bitwidth(hfinfo)))do { if (fi) (fi)->flags = (fi)->flags | ((((hfinfo_mask_bitwidth
(hfinfo)) & 63) << 12)); } while(0)
;
6414 }
6415
6416 fvalue_set_sinteger64(fi->value, integer);
6417}
6418
6419proto_item *
6420proto_tree_add_int64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
6421 unsigned start, unsigned length, int64_t value,
6422 const char *format, ...)
6423{
6424 proto_item *pi;
6425 va_list ap;
6426
6427 pi = proto_tree_add_int64(tree, hfindex, tvb, start, length, value);
6428 if (pi != tree) {
6429 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 6429, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
6430
6431 va_start(ap, format)__builtin_va_start(ap, format);
6432 proto_tree_set_representation(pi, format, ap);
6433 va_end(ap)__builtin_va_end(ap);
6434 }
6435
6436 return pi;
6437}
6438
6439/* Add a FT_EUI64 to a proto_tree */
6440proto_item *
6441proto_tree_add_eui64(proto_tree *tree, int hfindex, tvbuff_t *tvb, unsigned start,
6442 unsigned length, const uint64_t value)
6443{
6444 proto_item *pi;
6445 header_field_info *hfinfo;
6446
6447 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
6448
6449 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6449
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 6449, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 6449, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6449, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
6450
6451 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_EUI64)((void) (((hfinfo)->type == FT_EUI64) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_EUI64", "epan/proto.c",
6451, ((hfinfo))->abbrev))))
;
6452
6453 pi = proto_tree_add_pi_unsigned(tree, hfinfo, tvb, start, &length);
6454 proto_tree_set_eui64(PNODE_FINFO(pi)((pi)->finfo), value);
6455
6456 return pi;
6457}
6458
6459proto_item *
6460proto_tree_add_eui64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
6461 unsigned start, unsigned length, const uint64_t value,
6462 const char *format, ...)
6463{
6464 proto_item *pi;
6465 va_list ap;
6466
6467 pi = proto_tree_add_eui64(tree, hfindex, tvb, start, length, value);
6468 if (pi != tree) {
6469 va_start(ap, format)__builtin_va_start(ap, format);
6470 proto_tree_set_representation_value(pi, format, ap);
6471 va_end(ap)__builtin_va_end(ap);
6472 }
6473
6474 return pi;
6475}
6476
6477proto_item *
6478proto_tree_add_eui64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb,
6479 unsigned start, unsigned length, const uint64_t value,
6480 const char *format, ...)
6481{
6482 proto_item *pi;
6483 va_list ap;
6484
6485 pi = proto_tree_add_eui64(tree, hfindex, tvb, start, length, value);
6486 if (pi != tree) {
6487 TRY_TO_FAKE_THIS_REPR(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 6487, __func__, "assertion failed: %s", "pi"
); } while (0); if (!((pi)->finfo)) return pi; if (!(((pi)
->tree_data)->visible) && proto_item_is_hidden(
(pi))) { return pi; }
;
6488
6489 va_start(ap, format)__builtin_va_start(ap, format);
6490 proto_tree_set_representation(pi, format, ap);
6491 va_end(ap)__builtin_va_end(ap);
6492 }
6493
6494 return pi;
6495}
6496
6497/* Set the FT_EUI64 value */
6498static void
6499proto_tree_set_eui64(field_info *fi, const uint64_t value)
6500{
6501 uint8_t v[FT_EUI64_LEN8];
6502 phtonu64(v, value);
6503 fvalue_set_bytes_data(fi->value, v, FT_EUI64_LEN8);
6504}
6505
6506static void
6507proto_tree_set_eui64_tvb(field_info *fi, tvbuff_t *tvb, unsigned start, const unsigned encoding)
6508{
6509 if (encoding)
6510 {
6511 proto_tree_set_eui64(fi, tvb_get_letoh64(tvb, start));
6512 } else {
6513 proto_tree_set_eui64(fi, tvb_get_ntoh64(tvb, start));
6514 }
6515}
6516
6517proto_item *
6518proto_tree_add_mac48_detail(const mac_hf_list_t *list_specific,
6519 const mac_hf_list_t *list_generic,
6520 int idx, tvbuff_t *tvb,
6521 proto_tree *tree, unsigned offset)
6522{
6523 uint8_t addr[6];
6524 const char *addr_name = NULL((void*)0);
6525 const char *oui_name = NULL((void*)0);
6526 proto_item *addr_item = NULL((void*)0);
6527 proto_tree *addr_tree = NULL((void*)0);
6528 proto_item *ret_val = NULL((void*)0);
6529
6530 if (tree == NULL((void*)0) || list_specific == NULL((void*)0)) {
6531 return NULL((void*)0);
6532 }
6533
6534 /* Resolve what we can of the address */
6535 tvb_memcpy(tvb, addr, offset, sizeof addr);
6536 if (list_specific->hf_addr_resolved || (list_generic && list_generic->hf_addr_resolved)) {
6537 addr_name = get_ether_name(addr);
6538 }
6539 if (list_specific->hf_oui_resolved || (list_generic && list_generic->hf_oui_resolved)) {
6540 oui_name = get_manuf_name_if_known(addr, sizeof(addr));
6541 }
6542
6543 /* Add the item for the specific address type */
6544 ret_val = proto_tree_add_item(tree, *list_specific->hf_addr, tvb, offset, 6, ENC_BIG_ENDIAN0x00000000);
6545 if (idx >= 0) {
6546 addr_tree = proto_item_add_subtree(ret_val, idx);
6547 }
6548 else {
6549 addr_tree = tree;
6550 }
6551
6552 if (list_specific->hf_addr_resolved != NULL((void*)0)) {
6553 addr_item = proto_tree_add_string(addr_tree, *list_specific->hf_addr_resolved,
6554 tvb, offset, 6, addr_name);
6555 proto_item_set_generated(addr_item);
6556 proto_item_set_hidden(addr_item);
6557 }
6558
6559 if (list_specific->hf_oui != NULL((void*)0)) {
6560 addr_item = proto_tree_add_item(addr_tree, *list_specific->hf_oui, tvb, offset, 3, ENC_BIG_ENDIAN0x00000000);
6561 proto_item_set_generated(addr_item);
6562 proto_item_set_hidden(addr_item);
6563
6564 if (oui_name != NULL((void*)0) && list_specific->hf_oui_resolved != NULL((void*)0)) {
6565 addr_item = proto_tree_add_string(addr_tree, *list_specific->hf_oui_resolved, tvb, offset, 6, oui_name);
6566 proto_item_set_generated(addr_item);
6567 proto_item_set_hidden(addr_item);
6568 }
6569 }
6570
6571 if (list_specific->hf_lg != NULL((void*)0)) {
6572 proto_tree_add_item(addr_tree, *list_specific->hf_lg, tvb, offset, 3, ENC_BIG_ENDIAN0x00000000);
6573 }
6574 if (list_specific->hf_ig != NULL((void*)0)) {
6575 proto_tree_add_item(addr_tree, *list_specific->hf_ig, tvb, offset, 3, ENC_BIG_ENDIAN0x00000000);
6576 }
6577
6578 /* Were we given a list for generic address fields? If not, stop here */
6579 if (list_generic == NULL((void*)0)) {
6580 return ret_val;
6581 }
6582
6583 addr_item = proto_tree_add_item(addr_tree, *list_generic->hf_addr, tvb, offset, 6, ENC_BIG_ENDIAN0x00000000);
6584 proto_item_set_hidden(addr_item);
6585
6586 if (list_generic->hf_addr_resolved != NULL((void*)0)) {
6587 addr_item = proto_tree_add_string(addr_tree, *list_generic->hf_addr_resolved,
6588 tvb, offset, 6, addr_name);
6589 proto_item_set_generated(addr_item);
6590 proto_item_set_hidden(addr_item);
6591 }
6592
6593 if (list_generic->hf_oui != NULL((void*)0)) {
6594 addr_item = proto_tree_add_item(addr_tree, *list_generic->hf_oui, tvb, offset, 3, ENC_BIG_ENDIAN0x00000000);
6595 proto_item_set_generated(addr_item);
6596 proto_item_set_hidden(addr_item);
6597
6598 if (oui_name != NULL((void*)0) && list_generic->hf_oui_resolved != NULL((void*)0)) {
6599 addr_item = proto_tree_add_string(addr_tree, *list_generic->hf_oui_resolved, tvb, offset, 6, oui_name);
6600 proto_item_set_generated(addr_item);
6601 proto_item_set_hidden(addr_item);
6602 }
6603 }
6604
6605 if (list_generic->hf_lg != NULL((void*)0)) {
6606 addr_item = proto_tree_add_item(addr_tree, *list_generic->hf_lg, tvb, offset, 3, ENC_BIG_ENDIAN0x00000000);
6607 proto_item_set_hidden(addr_item);
6608 }
6609 if (list_generic->hf_ig != NULL((void*)0)) {
6610 addr_item = proto_tree_add_item(addr_tree, *list_generic->hf_ig, tvb, offset, 3, ENC_BIG_ENDIAN0x00000000);
6611 proto_item_set_hidden(addr_item);
6612 }
6613 return ret_val;
6614}
6615
6616static proto_item *
6617proto_tree_add_fake_node(proto_tree *tree, const header_field_info *hfinfo)
6618{
6619 proto_node *pnode, *tnode, *sibling;
6620 field_info *tfi;
6621 unsigned depth = 1;
6622
6623 ws_assert(tree)do { if ((1) && !(tree)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 6623, __func__, "assertion failed: %s", "tree"
); } while (0)
;
6624
6625 /*
6626 * Restrict our depth. proto_tree_traverse_pre_order and
6627 * proto_tree_traverse_post_order (and possibly others) are recursive
6628 * so we need to be mindful of our stack size.
6629 */
6630 if (tree->first_child == NULL((void*)0)) {
6631 for (tnode = tree; tnode != NULL((void*)0); tnode = tnode->parent) {
6632 depth++;
6633 if (G_UNLIKELY(depth > prefs.gui_max_tree_depth)(depth > prefs.gui_max_tree_depth)) {
6634 THROW_MESSAGE(DissectorError, wmem_strdup_printf(PNODE_POOL(tree),except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Maximum tree depth %d exceeded for \"%s\" - \"%s\" (%s:%u) (Maximum depth can be increased in advanced preferences)"
, prefs.gui_max_tree_depth, hfinfo->name, hfinfo->abbrev
, ((const char*) (__func__)), 6637)))
6635 "Maximum tree depth %d exceeded for \"%s\" - \"%s\" (%s:%u) (Maximum depth can be increased in advanced preferences)",except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Maximum tree depth %d exceeded for \"%s\" - \"%s\" (%s:%u) (Maximum depth can be increased in advanced preferences)"
, prefs.gui_max_tree_depth, hfinfo->name, hfinfo->abbrev
, ((const char*) (__func__)), 6637)))
6636 prefs.gui_max_tree_depth,except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Maximum tree depth %d exceeded for \"%s\" - \"%s\" (%s:%u) (Maximum depth can be increased in advanced preferences)"
, prefs.gui_max_tree_depth, hfinfo->name, hfinfo->abbrev
, ((const char*) (__func__)), 6637)))
6637 hfinfo->name, hfinfo->abbrev, G_STRFUNC, __LINE__))except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Maximum tree depth %d exceeded for \"%s\" - \"%s\" (%s:%u) (Maximum depth can be increased in advanced preferences)"
, prefs.gui_max_tree_depth, hfinfo->name, hfinfo->abbrev
, ((const char*) (__func__)), 6637)))
;
6638 }
6639 }
6640 }
6641
6642 /*
6643 * Make sure "tree" is ready to have subtrees under it, by
6644 * checking whether it's been given an ett_ value.
6645 *
6646 * "PNODE_FINFO(tnode)" may be null; that's the case for the root
6647 * node of the protocol tree. That node is not displayed,
6648 * so it doesn't need an ett_ value to remember whether it
6649 * was expanded.
6650 */
6651 tnode = tree;
6652 tfi = PNODE_FINFO(tnode)((tnode)->finfo);
6653 if (tfi != NULL((void*)0) && (tfi->tree_type < 0 || tfi->tree_type >= num_tree_types)) {
6654 REPORT_DISSECTOR_BUG("\"%s\" - \"%s\" tfi->tree_type: %d invalid (%s:%u)",proto_report_dissector_bug("\"%s\" - \"%s\" tfi->tree_type: %d invalid (%s:%u)"
, hfinfo->name, hfinfo->abbrev, tfi->tree_type, "epan/proto.c"
, 6655)
6655 hfinfo->name, hfinfo->abbrev, tfi->tree_type, __FILE__, __LINE__)proto_report_dissector_bug("\"%s\" - \"%s\" tfi->tree_type: %d invalid (%s:%u)"
, hfinfo->name, hfinfo->abbrev, tfi->tree_type, "epan/proto.c"
, 6655)
;
6656 /* XXX - is it safe to continue here? */
6657 }
6658
6659 pnode = wmem_new(PNODE_POOL(tree), proto_node)((proto_node*)wmem_alloc((((tree)->tree_data->pinfo->
pool)), sizeof(proto_node)))
;
6660 PROTO_NODE_INIT(pnode)pnode->first_child = ((void*)0); pnode->last_child = ((
void*)0); pnode->next = ((void*)0);
;
6661 pnode->parent = tnode;
6662 PNODE_HFINFO(pnode)((pnode)->hfinfo) = hfinfo;
6663 PNODE_FINFO(pnode)((pnode)->finfo) = NULL((void*)0); // Faked
6664 pnode->tree_data = PTREE_DATA(tree)((tree)->tree_data);
6665
6666 if (tnode->last_child != NULL((void*)0)) {
6667 sibling = tnode->last_child;
6668 DISSECTOR_ASSERT(sibling->next == NULL)((void) ((sibling->next == ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 6668, "sibling->next == ((void*)0)"
))))
;
6669 sibling->next = pnode;
6670 } else
6671 tnode->first_child = pnode;
6672 tnode->last_child = pnode;
6673
6674 /* We should not be adding a fake node for an interesting field */
6675 ws_assert(hfinfo->ref_type != HF_REF_TYPE_DIRECT && hfinfo->ref_type != HF_REF_TYPE_PRINT)do { if ((1) && !(hfinfo->ref_type != HF_REF_TYPE_DIRECT
&& hfinfo->ref_type != HF_REF_TYPE_PRINT)) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 6675, __func__, "assertion failed: %s"
, "hfinfo->ref_type != HF_REF_TYPE_DIRECT && hfinfo->ref_type != HF_REF_TYPE_PRINT"
); } while (0)
;
6676
6677 /* XXX - Should the proto_item have a header_field_info member, at least
6678 * for faked items, to know what hfi was faked? (Some dissectors look at
6679 * the tree items directly.)
6680 */
6681 return (proto_item *)pnode;
6682}
6683
6684/* Add a field_info struct to the proto_tree, encapsulating it in a proto_node */
6685static proto_item *
6686proto_tree_add_node(proto_tree *tree, field_info *fi)
6687{
6688 proto_node *pnode, *tnode, *sibling;
6689 field_info *tfi;
6690 unsigned depth = 1;
6691
6692 ws_assert(tree)do { if ((1) && !(tree)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 6692, __func__, "assertion failed: %s", "tree"
); } while (0)
;
6693
6694 /*
6695 * Restrict our depth. proto_tree_traverse_pre_order and
6696 * proto_tree_traverse_post_order (and possibly others) are recursive
6697 * so we need to be mindful of our stack size.
6698 */
6699 if (tree->first_child == NULL((void*)0)) {
6700 for (tnode = tree; tnode != NULL((void*)0); tnode = tnode->parent) {
6701 depth++;
6702 if (G_UNLIKELY(depth > prefs.gui_max_tree_depth)(depth > prefs.gui_max_tree_depth)) {
6703 /* The fvalue_t is pool-allocated; just release the
6704 * type-specific data it owns (see new_field_info()). */
6705 fvalue_cleanup(fi->value);
6706 fi->value = NULL((void*)0);
6707 THROW_MESSAGE(DissectorError, wmem_strdup_printf(PNODE_POOL(tree),except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Maximum tree depth %d exceeded for \"%s\" - \"%s\" (%s:%u) (Maximum depth can be increased in advanced preferences)"
, prefs.gui_max_tree_depth, fi->hfinfo->name, fi->hfinfo
->abbrev, ((const char*) (__func__)), 6710)))
6708 "Maximum tree depth %d exceeded for \"%s\" - \"%s\" (%s:%u) (Maximum depth can be increased in advanced preferences)",except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Maximum tree depth %d exceeded for \"%s\" - \"%s\" (%s:%u) (Maximum depth can be increased in advanced preferences)"
, prefs.gui_max_tree_depth, fi->hfinfo->name, fi->hfinfo
->abbrev, ((const char*) (__func__)), 6710)))
6709 prefs.gui_max_tree_depth,except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Maximum tree depth %d exceeded for \"%s\" - \"%s\" (%s:%u) (Maximum depth can be increased in advanced preferences)"
, prefs.gui_max_tree_depth, fi->hfinfo->name, fi->hfinfo
->abbrev, ((const char*) (__func__)), 6710)))
6710 fi->hfinfo->name, fi->hfinfo->abbrev, G_STRFUNC, __LINE__))except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Maximum tree depth %d exceeded for \"%s\" - \"%s\" (%s:%u) (Maximum depth can be increased in advanced preferences)"
, prefs.gui_max_tree_depth, fi->hfinfo->name, fi->hfinfo
->abbrev, ((const char*) (__func__)), 6710)))
;
6711 }
6712 }
6713 }
6714
6715 /*
6716 * Make sure "tree" is ready to have subtrees under it, by
6717 * checking whether it's been given an ett_ value.
6718 *
6719 * "PNODE_FINFO(tnode)" may be null; that's the case for the root
6720 * node of the protocol tree. That node is not displayed,
6721 * so it doesn't need an ett_ value to remember whether it
6722 * was expanded.
6723 */
6724 tnode = tree;
6725 tfi = PNODE_FINFO(tnode)((tnode)->finfo);
6726 if (tfi != NULL((void*)0) && (tfi->tree_type < 0 || tfi->tree_type >= num_tree_types)) {
6727 /* Since we are not adding fi to a node, its fvalue won't get
6728 * cleaned up by proto_tree_free_node(), so release the
6729 * type-specific data it owns now. The fvalue_t structure itself
6730 * is pool-allocated (see new_field_info()).
6731 */
6732 fvalue_cleanup(fi->value);
6733 fi->value = NULL((void*)0);
6734 REPORT_DISSECTOR_BUG("\"%s\" - \"%s\" tfi->tree_type: %d invalid (%s:%u)",proto_report_dissector_bug("\"%s\" - \"%s\" tfi->tree_type: %d invalid (%s:%u)"
, fi->hfinfo->name, fi->hfinfo->abbrev, tfi->tree_type
, "epan/proto.c", 6735)
6735 fi->hfinfo->name, fi->hfinfo->abbrev, tfi->tree_type, __FILE__, __LINE__)proto_report_dissector_bug("\"%s\" - \"%s\" tfi->tree_type: %d invalid (%s:%u)"
, fi->hfinfo->name, fi->hfinfo->abbrev, tfi->tree_type
, "epan/proto.c", 6735)
;
6736 /* XXX - is it safe to continue here? */
6737 }
6738
6739 pnode = wmem_new(PNODE_POOL(tree), proto_node)((proto_node*)wmem_alloc((((tree)->tree_data->pinfo->
pool)), sizeof(proto_node)))
;
6740 PROTO_NODE_INIT(pnode)pnode->first_child = ((void*)0); pnode->last_child = ((
void*)0); pnode->next = ((void*)0);
;
6741 pnode->parent = tnode;
6742 PNODE_HFINFO(pnode)((pnode)->hfinfo) = fi->hfinfo;
6743 PNODE_FINFO(pnode)((pnode)->finfo) = fi;
6744 pnode->tree_data = PTREE_DATA(tree)((tree)->tree_data);
6745
6746 if (tnode->last_child != NULL((void*)0)) {
6747 sibling = tnode->last_child;
6748 DISSECTOR_ASSERT(sibling->next == NULL)((void) ((sibling->next == ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 6748, "sibling->next == ((void*)0)"
))))
;
6749 sibling->next = pnode;
6750 } else
6751 tnode->first_child = pnode;
6752 tnode->last_child = pnode;
6753
6754 tree_data_add_maybe_interesting_field(pnode->tree_data, fi);
6755
6756 return (proto_item *)pnode;
6757}
6758
6759
6760/* Generic way to allocate field_info and add to proto_tree.
6761 * Sets *pfi to address of newly-allocated field_info struct */
6762static proto_item *
6763proto_tree_add_pi(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb, unsigned start,
6764 int *length)
6765{
6766 proto_item *pi;
6767 field_info *fi;
6768 int item_length;
6769
6770 get_hfi_length(hfinfo, tvb, start, length, &item_length, ENC_NA0x00000000);
6771 fi = new_field_info(tree, hfinfo, tvb, start, item_length);
6772 pi = proto_tree_add_node(tree, fi);
6773
6774 return pi;
6775}
6776
6777/* Generic way to allocate field_info and add to proto_tree with unsigned length.
6778 * Eventually this should replace the other function.
6779 * Sets *pfi to address of newly-allocated field_info struct */
6780static proto_item *
6781proto_tree_add_pi_unsigned(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb, unsigned start,
6782 unsigned *length)
6783{
6784 proto_item *pi;
6785 field_info *fi;
6786 unsigned item_length;
6787
6788 get_hfi_length_unsigned(hfinfo, tvb, start, length, &item_length, ENC_NA0x00000000);
6789 fi = new_field_info(tree, hfinfo, tvb, start, item_length);
6790 pi = proto_tree_add_node(tree, fi);
6791
6792 return pi;
6793}
6794
6795static void
6796get_hfi_length(header_field_info *hfinfo, tvbuff_t *tvb, const unsigned start, int *length,
6797 int *item_length, const unsigned encoding)
6798{
6799 int length_remaining;
6800
6801 /*
6802 * We only allow a null tvbuff if the item has a zero length,
6803 * i.e. if there's no data backing it.
6804 */
6805 DISSECTOR_ASSERT(tvb != NULL || *length == 0)((void) ((tvb != ((void*)0) || *length == 0) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 6805, "tvb != ((void*)0) || *length == 0"
))))
;
6806
6807 /*
6808 * XXX - in some protocols, there are 32-bit unsigned length
6809 * fields, so lengths in protocol tree and tvbuff routines
6810 * should really be unsigned. We should have, for those
6811 * field types for which "to the end of the tvbuff" makes sense,
6812 * additional routines that take no length argument and
6813 * add fields that run to the end of the tvbuff.
6814 */
6815 if (*length == -1) {
6816 /*
6817 * For FT_NONE, FT_PROTOCOL, FT_BYTES, FT_STRING,
6818 * FT_STRINGZPAD, and FT_STRINGZTRUNC fields, a length
6819 * of -1 means "set the length to what remains in the
6820 * tvbuff".
6821 *
6822 * The assumption is either that
6823 *
6824 * 1) the length of the item can only be determined
6825 * by dissection (typically true of items with
6826 * subitems, which are probably FT_NONE or
6827 * FT_PROTOCOL)
6828 *
6829 * or
6830 *
6831 * 2) if the tvbuff is "short" (either due to a short
6832 * snapshot length or due to lack of reassembly of
6833 * fragments/segments/whatever), we want to display
6834 * what's available in the field (probably FT_BYTES
6835 * or FT_STRING) and then throw an exception later
6836 *
6837 * or
6838 *
6839 * 3) the field is defined to be "what's left in the
6840 * packet"
6841 *
6842 * so we set the length to what remains in the tvbuff so
6843 * that, if we throw an exception while dissecting, it
6844 * has what is probably the right value.
6845 *
6846 * For FT_STRINGZ, it means "the string is null-terminated,
6847 * not null-padded; set the length to the actual length
6848 * of the string", and if the tvbuff if short, we just
6849 * throw an exception.
6850 *
6851 * For ENC_VARINT_PROTOBUF|ENC_VARINT_QUIC|ENC_VARIANT_ZIGZAG|ENC_VARINT_SDNV,
6852 * it means "find the end of the string",
6853 * and if the tvbuff if short, we just throw an exception.
6854 *
6855 * It's not valid for any other type of field. For those
6856 * fields, we treat -1 the same way we treat other
6857 * negative values - we assume the length is a Really
6858 * Big Positive Number, and throw a ReportedBoundsError
6859 * exception, under the assumption that the Really Big
6860 * Length would run past the end of the packet.
6861 */
6862 if ((FT_IS_INT(hfinfo->type)(((hfinfo->type) == FT_INT8 || (hfinfo->type) == FT_INT16
|| (hfinfo->type) == FT_INT24 || (hfinfo->type) == FT_INT32
) || ((hfinfo->type) == FT_INT40 || (hfinfo->type) == FT_INT48
|| (hfinfo->type) == FT_INT56 || (hfinfo->type) == FT_INT64
))
) || (FT_IS_UINT(hfinfo->type)(((hfinfo->type) == FT_CHAR || (hfinfo->type) == FT_UINT8
|| (hfinfo->type) == FT_UINT16 || (hfinfo->type) == FT_UINT24
|| (hfinfo->type) == FT_UINT32 || (hfinfo->type) == FT_FRAMENUM
) || ((hfinfo->type) == FT_UINT40 || (hfinfo->type) == FT_UINT48
|| (hfinfo->type) == FT_UINT56 || (hfinfo->type) == FT_UINT64
))
)) {
6863 if (encoding & (ENC_VARINT_PROTOBUF0x00000002|ENC_VARINT_ZIGZAG0x00000008|ENC_VARINT_SDNV0x00000010)) {
6864 /*
6865 * Leave the length as -1, so our caller knows
6866 * it was -1.
6867 */
6868 *item_length = *length;
6869 return;
6870 } else if (encoding & ENC_VARINT_QUIC0x00000004) {
6871 switch (tvb_get_uint8(tvb, start) >> 6)
6872 {
6873 case 0: /* 0b00 => 1 byte length (6 bits Usable) */
6874 *item_length = 1;
6875 break;
6876 case 1: /* 0b01 => 2 bytes length (14 bits Usable) */
6877 *item_length = 2;
6878 break;
6879 case 2: /* 0b10 => 4 bytes length (30 bits Usable) */
6880 *item_length = 4;
6881 break;
6882 case 3: /* 0b11 => 8 bytes length (62 bits Usable) */
6883 *item_length = 8;
6884 break;
6885 }
6886 }
6887 }
6888
6889 switch (hfinfo->type) {
6890
6891 case FT_PROTOCOL:
6892 case FT_NONE:
6893 case FT_BYTES:
6894 case FT_STRING:
6895 case FT_STRINGZPAD:
6896 case FT_STRINGZTRUNC:
6897 /*
6898 * We allow FT_PROTOCOLs to be zero-length -
6899 * for example, an ONC RPC NULL procedure has
6900 * neither arguments nor reply, so the
6901 * payload for that protocol is empty.
6902 *
6903 * We also allow the others to be zero-length -
6904 * because that's the way the code has been for a
6905 * long, long time.
6906 *
6907 * However, we want to ensure that the start
6908 * offset is not *past* the byte past the end
6909 * of the tvbuff: we throw an exception in that
6910 * case.
6911 */
6912 *length = tvb_captured_length(tvb) ? tvb_ensure_captured_length_remaining(tvb, start) : 0;
6913 DISSECTOR_ASSERT(*length >= 0)((void) ((*length >= 0) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 6913, "*length >= 0"
))))
;
6914 break;
6915
6916 case FT_STRINGZ:
6917 /*
6918 * Leave the length as -1, so our caller knows
6919 * it was -1.
6920 */
6921 break;
6922
6923 default:
6924 THROW(ReportedBoundsError)except_throw(1, (3), ((void*)0));
6925 DISSECTOR_ASSERT_NOT_REACHED()(proto_report_dissector_bug("%s:%u: failed assertion \"DISSECTOR_ASSERT_NOT_REACHED\""
, "epan/proto.c", 6925))
;
6926 }
6927 *item_length = *length;
6928 } else {
6929 if (hfinfo->type == FT_PROTOCOL || hfinfo->type == FT_NONE) {
6930 /*
6931 * These types are for interior nodes of the
6932 * tree, and don't have data associated with
6933 * them; if the length is negative (XXX - see
6934 * above) or goes past the end of the tvbuff,
6935 * cut it short at the end of the tvbuff.
6936 * That way, if this field is selected in
6937 * Wireshark, we don't highlight stuff past
6938 * the end of the data.
6939 *
6940 * If we don't have a tvb, then length must be zero,
6941 * per the DISSECTOR_ASSERT() above.
6942 *
6943 * If we do have a tvb, and the length requested is
6944 * nonzero, we want to ensure that the start offset
6945 * is not *past* the byte past the end of the tvbuff
6946 * data: we throw an exception in that case as above.
6947 */
6948 if (tvb && *length) {
6949 length_remaining = tvb_ensure_captured_length_remaining(tvb, start);
6950 if (*length < 0 ||
6951 (*length > 0 &&
6952 (length_remaining < *length)))
6953 *length = length_remaining;
6954 }
6955 }
6956 *item_length = *length;
6957 if (*item_length < 0) {
6958 THROW(ReportedBoundsError)except_throw(1, (3), ((void*)0));
6959 }
6960 }
6961}
6962
6963static void
6964get_hfi_length_unsigned(header_field_info* hfinfo, tvbuff_t* tvb, const unsigned start, unsigned* length,
6965 unsigned* item_length, const unsigned encoding _U___attribute__((unused)))
6966{
6967 unsigned length_remaining;
6968
6969 /*
6970 * We only allow a null tvbuff if the item has a zero length,
6971 * i.e. if there's no data backing it.
6972 */
6973 DISSECTOR_ASSERT(tvb != NULL || *length == 0)((void) ((tvb != ((void*)0) || *length == 0) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 6973, "tvb != ((void*)0) || *length == 0"
))))
;
6974
6975
6976 if (hfinfo->type == FT_PROTOCOL || hfinfo->type == FT_NONE) {
6977 /*
6978 * These types are for interior nodes of the
6979 * tree, and don't have data associated with
6980 * them; if the length is negative (XXX - see
6981 * above) or goes past the end of the tvbuff,
6982 * cut it short at the end of the tvbuff.
6983 * That way, if this field is selected in
6984 * Wireshark, we don't highlight stuff past
6985 * the end of the data.
6986 *
6987 * If we don't have a tvb, then length must be zero,
6988 * per the DISSECTOR_ASSERT() above.
6989 *
6990 * If we do have a tvb, and the length requested is
6991 * nonzero, we want to ensure that the start offset
6992 * is not *past* the byte past the end of the tvbuff
6993 * data: we throw an exception in that case as above.
6994 * (If the length requested is zero, then it's quite
6995 * likely that the start offset is the byte past the
6996 * end, but that's ok.)
6997 */
6998 if (tvb && *length) {
6999 length_remaining = tvb_ensure_captured_length_remaining(tvb, start);
7000 if (length_remaining < *length) {
7001 *length = length_remaining;
7002 }
7003 }
7004 }
7005 *item_length = *length;
7006}
7007
7008static int
7009get_full_length(header_field_info *hfinfo, tvbuff_t *tvb, const unsigned start,
7010 int length, unsigned item_length, const int encoding)
7011{
7012 uint32_t n;
7013
7014 /*
7015 * We need to get the correct item length here.
7016 * That's normally done by proto_tree_new_item(),
7017 * but we won't be calling it.
7018 */
7019 switch (hfinfo->type) {
7020
7021 case FT_NONE:
7022 case FT_PROTOCOL:
7023 case FT_BYTES:
7024 /*
7025 * The length is the specified length.
7026 */
7027 break;
7028
7029 case FT_UINT_BYTES:
7030 n = get_uint_value(NULL((void*)0), tvb, start, length, encoding);
7031 item_length += n;
7032 if ((int)item_length < length) {
7033 THROW(ReportedBoundsError)except_throw(1, (3), ((void*)0));
7034 }
7035 break;
7036
7037 /* XXX - make these just FT_UINT? */
7038 case FT_UINT8:
7039 case FT_UINT16:
7040 case FT_UINT24:
7041 case FT_UINT32:
7042 case FT_UINT40:
7043 case FT_UINT48:
7044 case FT_UINT56:
7045 case FT_UINT64:
7046 /* XXX - make these just FT_INT? */
7047 case FT_INT8:
7048 case FT_INT16:
7049 case FT_INT24:
7050 case FT_INT32:
7051 case FT_INT40:
7052 case FT_INT48:
7053 case FT_INT56:
7054 case FT_INT64:
7055 if (encoding & ENC_VARINT_MASK(0x00000002|0x00000004|0x00000008|0x00000010)) {
7056 if (length < -1) {
7057 report_type_length_mismatch(NULL((void*)0), "a FT_[U]INT", length, true1);
7058 }
7059 if (length == -1) {
7060 uint64_t dummy;
7061 /* This can throw an exception */
7062 /* XXX - do this without fetching the varint? */
7063 length = tvb_get_varint(tvb, start, FT_VARINT_MAX_LEN10, &dummy, encoding);
7064 if (length == 0) {
7065 THROW(ReportedBoundsError)except_throw(1, (3), ((void*)0));
7066 }
7067 }
7068 item_length = length;
7069 break;
7070 }
7071
7072 /*
7073 * The length is the specified length.
7074 */
7075 break;
7076
7077 case FT_BOOLEAN:
7078 case FT_CHAR:
7079 case FT_IPv4:
7080 case FT_IPXNET:
7081 case FT_IPv6:
7082 case FT_FCWWN:
7083 case FT_AX25:
7084 case FT_VINES:
7085 case FT_ETHER:
7086 case FT_EUI64:
7087 case FT_GUID:
7088 case FT_OID:
7089 case FT_REL_OID:
7090 case FT_SYSTEM_ID:
7091 case FT_FLOAT:
7092 case FT_DOUBLE:
7093 case FT_STRING:
7094 /*
7095 * The length is the specified length.
7096 */
7097 break;
7098
7099 case FT_STRINGZ:
7100 if (length < -1) {
7101 report_type_length_mismatch(NULL((void*)0), "a string", length, true1);
7102 }
7103 if (length == -1) {
7104 /* This can throw an exception */
7105 item_length = tvb_strsize_enc(tvb, start, encoding);
7106 }
7107 break;
7108
7109 case FT_UINT_STRING:
7110 n = get_uint_value(NULL((void*)0), tvb, start, length, encoding & ~ENC_CHARENCODING_MASK0x0000FFFE);
7111 item_length += n;
7112 if ((int)item_length < length) {
7113 THROW(ReportedBoundsError)except_throw(1, (3), ((void*)0));
7114 }
7115 break;
7116
7117 case FT_STRINGZPAD:
7118 case FT_STRINGZTRUNC:
7119 case FT_ABSOLUTE_TIME:
7120 case FT_RELATIVE_TIME:
7121 case FT_IEEE_11073_SFLOAT:
7122 case FT_IEEE_11073_FLOAT:
7123 /*
7124 * The length is the specified length.
7125 */
7126 break;
7127
7128 default:
7129 REPORT_DISSECTOR_BUG("field %s has type %d (%s) not handled in gset_full_length()",proto_report_dissector_bug("field %s has type %d (%s) not handled in gset_full_length()"
, hfinfo->abbrev, hfinfo->type, ftype_name(hfinfo->type
))
7130 hfinfo->abbrev,proto_report_dissector_bug("field %s has type %d (%s) not handled in gset_full_length()"
, hfinfo->abbrev, hfinfo->type, ftype_name(hfinfo->type
))
7131 hfinfo->type,proto_report_dissector_bug("field %s has type %d (%s) not handled in gset_full_length()"
, hfinfo->abbrev, hfinfo->type, ftype_name(hfinfo->type
))
7132 ftype_name(hfinfo->type))proto_report_dissector_bug("field %s has type %d (%s) not handled in gset_full_length()"
, hfinfo->abbrev, hfinfo->type, ftype_name(hfinfo->type
))
;
7133 break;
7134 }
7135 return item_length;
7136}
7137
7138// This was arbitrarily chosen, but if you're adding 50K items to the tree
7139// without advancing the offset you should probably take a long, hard look
7140// at what you're doing.
7141// We *could* make this a configurable option, but I (Gerald) would like to
7142// avoid adding yet another nerd knob.
7143# define PROTO_TREE_MAX_IDLE50000 50000
7144static field_info *
7145new_field_info(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
7146 const unsigned start, const int item_length)
7147{
7148 field_info *fi;
7149
7150 FIELD_INFO_NEW(PNODE_POOL(tree), fi)fi = ((field_info*)wmem_alloc((((tree)->tree_data->pinfo
->pool)), sizeof(field_info)))
;
7151
7152 fi->hfinfo = hfinfo;
7153 fi->start = start;
7154 fi->start += (tvb)?tvb_raw_offset(tvb):0;
7155 /* add the data source tvbuff */
7156 fi->ds_tvb = tvb ? tvb_get_ds_tvb(tvb) : NULL((void*)0);
7157
7158 // If our start offset hasn't advanced after adding many items it probably
7159 // means we're in a large or infinite loop.
7160 if (fi->start > 0) {
7161 if (fi->ds_tvb == PTREE_DATA(tree)((tree)->tree_data)->idle_count_ds_tvb && fi->start <= PTREE_DATA(tree)((tree)->tree_data)->max_start) {
7162 PTREE_DATA(tree)((tree)->tree_data)->start_idle_count++;
7163 if (PTREE_DATA(tree)((tree)->tree_data)->start_idle_count > PROTO_TREE_MAX_IDLE50000) {
7164 if (wireshark_abort_on_too_many_items) {
7165 ws_error("Adding %s would be the %dth consecutive item that doesn't advance the maximum start offset - possible infinite loop",ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 7166
, __func__, "Adding %s would be the %dth consecutive item that doesn't advance the maximum start offset - possible infinite loop"
, hfinfo->abbrev, 50000)
7166 hfinfo->abbrev, PROTO_TREE_MAX_IDLE)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 7166
, __func__, "Adding %s would be the %dth consecutive item that doesn't advance the maximum start offset - possible infinite loop"
, hfinfo->abbrev, 50000)
;
7167 }
7168 /* PROTO_TREE_MAX_IDLE should be < pref.gui_max_tree_items,
7169 * but if not, we should hit the max item error earlier,
7170 * so we shouldn't need to reset the tree count to
7171 * ensure that the exception handler can add the item. */
7172 THROW_MESSAGE(DissectorError,except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Adding %s would be the %dth consecutive item that doesn't advance the maximum start offset - possible infinite loop"
, hfinfo->abbrev, 50000)))
7173 wmem_strdup_printf(PNODE_POOL(tree),except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Adding %s would be the %dth consecutive item that doesn't advance the maximum start offset - possible infinite loop"
, hfinfo->abbrev, 50000)))
7174 "Adding %s would be the %dth consecutive item that doesn't advance the maximum start offset - possible infinite loop",except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Adding %s would be the %dth consecutive item that doesn't advance the maximum start offset - possible infinite loop"
, hfinfo->abbrev, 50000)))
7175 hfinfo->abbrev, PROTO_TREE_MAX_IDLE))except_throw(1, (6), (wmem_strdup_printf(((tree)->tree_data
->pinfo->pool), "Adding %s would be the %dth consecutive item that doesn't advance the maximum start offset - possible infinite loop"
, hfinfo->abbrev, 50000)))
;
7176 }
7177 } else {
7178 PTREE_DATA(tree)((tree)->tree_data)->idle_count_ds_tvb = fi->ds_tvb;
7179 PTREE_DATA(tree)((tree)->tree_data)->max_start = fi->start;
7180 PTREE_DATA(tree)((tree)->tree_data)->start_idle_count = 0;
7181 }
7182 }
7183 fi->length = item_length;
7184 fi->tree_type = -1;
7185 fi->flags = 0;
7186 if (!PTREE_DATA(tree)((tree)->tree_data)->visible) {
7187 /* If the tree is not visible, set the item hidden, unless we
7188 * need the representation or length and can't fake them.
7189 */
7190 if (hfinfo->ref_type != HF_REF_TYPE_PRINT && (hfinfo->type != FT_PROTOCOL || PTREE_DATA(tree)((tree)->tree_data)->fake_protocols)) {
7191 FI_SET_FLAG(fi, FI_HIDDEN)do { if (fi) (fi)->flags = (fi)->flags | (0x00000001); }
while(0)
;
7192 }
7193 }
7194 fi->value = fvalue_new_pool(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool), fi->hfinfo->type);
7195 fi->rep = NULL((void*)0);
7196
7197 fi->appendix_start = 0;
7198 fi->appendix_length = 0;
7199
7200 fi->total_layer_num = tree->tree_data->pinfo->curr_layer_num;
7201 fi->proto_layer_num = tree->tree_data->pinfo->curr_proto_layer_num;
7202
7203 return fi;
7204}
7205
7206static size_t proto_find_value_pos(const header_field_info *hfinfo, const char *representation)
7207{
7208 if (hfinfo->display & BASE_NO_DISPLAY_VALUE0x00002000) {
7209 return 0;
7210 }
7211
7212 /* Search for field name */
7213 char *ptr = strstr(representation, hfinfo->name);
7214 if (!ptr) {
7215 return 0;
7216 }
7217
7218 /* Check if field name ends with the ": " delimiter */
7219 ptr += strlen(hfinfo->name);
7220 if (strncmp(ptr, ": ", 2) == 0) {
7221 ptr += 2;
7222 }
7223
7224 /* Return offset to after field name */
7225 return ptr - representation;
7226}
7227
7228static size_t label_find_name_pos(const item_label_t *rep)
7229{
7230 size_t name_pos = 0;
7231
7232 /* If the value_pos is too small or too large, we can't find the expected format */
7233 if (rep->value_pos <= 2 || rep->value_pos >= sizeof(rep->representation)) {
7234 return 0;
7235 }
7236
7237 /* Check if the format looks like "label: value", then set name_pos before ':'. */
7238 if (rep->representation[rep->value_pos-2] == ':') {
7239 name_pos = rep->value_pos - 2;
7240 }
7241
7242 return name_pos;
7243}
7244
7245/* If the protocol tree is to be visible, set the representation of a
7246 proto_tree entry with the name of the field for the item and with
7247 the value formatted with the supplied printf-style format and
7248 argument list. */
7249static void
7250proto_tree_set_representation_value(proto_item *pi, const char *format, va_list ap)
7251{
7252 ws_assert(pi)do { if ((1) && !(pi)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 7252, __func__, "assertion failed: %s", "pi"
); } while (0)
;
7253
7254 /* If the tree (GUI) or item isn't visible it's pointless for us to generate the protocol
7255 * items string representation */
7256 if (PTREE_DATA(pi)((pi)->tree_data)->visible || !proto_item_is_hidden(pi)) {
7257 size_t name_pos, ret = 0;
7258 char *str;
7259 field_info *fi = PITEM_FINFO(pi)((pi)->finfo);
7260 const header_field_info *hf;
7261
7262 DISSECTOR_ASSERT(fi)((void) ((fi) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 7262, "fi"))))
;
7263
7264 hf = fi->hfinfo;
7265
7266 ITEM_LABEL_NEW(PNODE_POOL(pi), fi->rep)fi->rep = ((item_label_t*)wmem_alloc((((pi)->tree_data->
pinfo->pool)), sizeof(item_label_t))); fi->rep->value_pos
= 0; fi->rep->value_len = 0;
;
7267 if (hf->bitmask && (hf->type == FT_BOOLEAN || FT_IS_UINT(hf->type)(((hf->type) == FT_CHAR || (hf->type) == FT_UINT8 || (hf
->type) == FT_UINT16 || (hf->type) == FT_UINT24 || (hf->
type) == FT_UINT32 || (hf->type) == FT_FRAMENUM) || ((hf->
type) == FT_UINT40 || (hf->type) == FT_UINT48 || (hf->type
) == FT_UINT56 || (hf->type) == FT_UINT64))
)) {
7268 uint64_t val;
7269 char *p;
7270
7271 if (FT_IS_UINT32(hf->type)((hf->type) == FT_CHAR || (hf->type) == FT_UINT8 || (hf
->type) == FT_UINT16 || (hf->type) == FT_UINT24 || (hf->
type) == FT_UINT32 || (hf->type) == FT_FRAMENUM)
)
7272 val = fvalue_get_uinteger(fi->value);
7273 else
7274 val = fvalue_get_uinteger64(fi->value);
7275
7276 val <<= hfinfo_bitshift(hf);
7277
7278 p = decode_bitfield_value(fi->rep->representation, val, hf->bitmask, hfinfo_container_bitwidth(hf));
7279 ret = (p - fi->rep->representation);
7280 }
7281
7282 /* put in the hf name */
7283 name_pos = ret = label_concat(fi->rep->representation, ret, (const uint8_t*)hf->name)ws_label_strcpy(fi->rep->representation, 240, ret, (const
uint8_t*)hf->name, 0)
;
7284
7285 ret = label_concat(fi->rep->representation, ret, (const uint8_t*)": ")ws_label_strcpy(fi->rep->representation, 240, ret, (const
uint8_t*)": ", 0)
;
7286 /* If possible, Put in the value of the string */
7287 str = wmem_strdup_vprintf(PNODE_POOL(pi)((pi)->tree_data->pinfo->pool), format, ap);
7288 WS_UTF_8_CHECK(str, -1)do { const char *__uni_endptr; if (1 && (str) != ((void
*)0) && !g_utf8_validate(str, -1, &__uni_endptr))
{ do { if (1) { ws_log_utf8_full("UTF-8", LOG_LEVEL_DEBUG, "epan/proto.c"
, 7288, __func__, str, -1, __uni_endptr); } } while (0); } } while
(0)
;
7289 fi->rep->value_pos = ret;
7290 ret = ws_label_strcpy(fi->rep->representation, ITEM_LABEL_LENGTH240, ret, (const uint8_t*)str, 0);
7291 if (ret >= ITEM_LABEL_LENGTH240) {
7292 /* Uh oh, we don't have enough room. Tell the user
7293 * that the field is truncated.
7294 */
7295 label_mark_truncated(fi->rep->representation, name_pos, &fi->rep->value_pos);
7296 }
7297 fi->rep->value_len = strlen(fi->rep->representation) - fi->rep->value_pos;
7298 }
7299}
7300
7301/* If the protocol tree is to be visible, set the representation of a
7302 proto_tree entry with the representation formatted with the supplied
7303 printf-style format and argument list. */
7304static void
7305proto_tree_set_representation(proto_item *pi, const char *format, va_list ap)
7306{
7307 size_t ret; /*tmp return value */
7308 char *str;
7309 field_info *fi = PITEM_FINFO(pi)((pi)->finfo);
7310
7311 DISSECTOR_ASSERT(fi)((void) ((fi) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 7311, "fi"))))
;
7312
7313 if (!proto_item_is_hidden(pi)) {
7314 ITEM_LABEL_NEW(PNODE_POOL(pi), fi->rep)fi->rep = ((item_label_t*)wmem_alloc((((pi)->tree_data->
pinfo->pool)), sizeof(item_label_t))); fi->rep->value_pos
= 0; fi->rep->value_len = 0;
;
7315
7316 str = wmem_strdup_vprintf(PNODE_POOL(pi)((pi)->tree_data->pinfo->pool), format, ap);
7317 WS_UTF_8_CHECK(str, -1)do { const char *__uni_endptr; if (1 && (str) != ((void
*)0) && !g_utf8_validate(str, -1, &__uni_endptr))
{ do { if (1) { ws_log_utf8_full("UTF-8", LOG_LEVEL_DEBUG, "epan/proto.c"
, 7317, __func__, str, -1, __uni_endptr); } } while (0); } } while
(0)
;
7318 fi->rep->value_pos = proto_find_value_pos(fi->hfinfo, str);
7319 ret = ws_label_strcpy(fi->rep->representation, ITEM_LABEL_LENGTH240, 0, (const uint8_t*)str, 0);
7320 if (ret >= ITEM_LABEL_LENGTH240) {
7321 /* Uh oh, we don't have enough room. Tell the user that the field is truncated. */
7322 size_t name_pos = label_find_name_pos(fi->rep);
7323 label_mark_truncated(fi->rep->representation, name_pos, &fi->rep->value_pos);
7324 }
7325 fi->rep->value_len = strlen(fi->rep->representation) - fi->rep->value_pos;
7326 }
7327}
7328
7329static int
7330proto_strlcpy(char *dest, const char *src, size_t dest_size)
7331{
7332 if (dest_size == 0) return 0;
7333
7334 size_t res = g_strlcpy(dest, src, dest_size);
7335
7336 /* At most dest_size - 1 characters will be copied
7337 * (unless dest_size is 0). */
7338 if (res >= dest_size)
7339 res = dest_size - 1;
7340 return (int) res;
7341}
7342
7343static header_field_info *
7344hfinfo_same_name_get_prev(const header_field_info *hfinfo)
7345{
7346 header_field_info *dup_hfinfo;
7347
7348 if (hfinfo->same_name_prev_id == -1)
7349 return NULL((void*)0);
7350 PROTO_REGISTRAR_GET_NTH(hfinfo->same_name_prev_id, dup_hfinfo)if((hfinfo->same_name_prev_id == 0 || (unsigned)hfinfo->
same_name_prev_id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 7350
, __func__, "Unregistered hf! index=%d", hfinfo->same_name_prev_id
); ((void) ((hfinfo->same_name_prev_id > 0 && (
unsigned)hfinfo->same_name_prev_id < gpa_hfinfo.len) ? (
void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 7350, "hfinfo->same_name_prev_id > 0 && (unsigned)hfinfo->same_name_prev_id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
same_name_prev_id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 7350,
"gpa_hfinfo.hfi[hfinfo->same_name_prev_id] != ((void*)0)"
, "Unregistered hf.")))) ; dup_hfinfo = gpa_hfinfo.hfi[hfinfo
->same_name_prev_id];
;
7351 return dup_hfinfo;
7352}
7353
7354static void
7355hfinfo_remove_from_gpa_name_map(const header_field_info *hfinfo)
7356{
7357 g_free(last_field_name)(__builtin_object_size ((last_field_name), 0) != ((size_t) - 1
)) ? g_free_sized (last_field_name, __builtin_object_size ((last_field_name
), 0)) : (g_free) (last_field_name)
;
7358 last_field_name = NULL((void*)0);
7359
7360 if (!hfinfo->same_name_next && hfinfo->same_name_prev_id == -1) {
7361 /* No hfinfo with the same name */
7362 wmem_map_remove(gpa_name_map, hfinfo->abbrev);
7363 return;
7364 }
7365
7366 if (hfinfo->same_name_next) {
7367 hfinfo->same_name_next->same_name_prev_id = hfinfo->same_name_prev_id;
7368 }
7369
7370 if (hfinfo->same_name_prev_id != -1) {
7371 header_field_info *same_name_prev = hfinfo_same_name_get_prev(hfinfo);
7372 same_name_prev->same_name_next = hfinfo->same_name_next;
7373 if (!hfinfo->same_name_next) {
7374 /* It's always the latest added hfinfo which is stored in gpa_name_map */
7375 wmem_map_insert(gpa_name_map, (void *) (same_name_prev->abbrev), same_name_prev);
7376 }
7377 }
7378}
7379
7380int
7381proto_item_fill_display_label(const field_info *finfo, char *display_label_str, const int label_str_size)
7382{
7383 const header_field_info *hfinfo = finfo->hfinfo;
7384 int label_len = 0;
7385 char *tmp_str;
7386 const char *str;
7387 const uint8_t *bytes;
7388 uint32_t number;
7389 uint64_t number64;
7390 const char *hf_str_val;
7391 char number_buf[NUMBER_LABEL_LENGTH80];
7392 const char *number_out;
7393 address addr;
7394 const ipv4_addr_and_mask *ipv4;
7395 const ipv6_addr_and_prefix *ipv6;
7396
7397 switch (hfinfo->type) {
7398
7399 case FT_NONE:
7400 case FT_PROTOCOL:
7401 return proto_strlcpy(display_label_str, UTF8_CHECK_MARK"\u2713", label_str_size);
7402
7403 case FT_UINT_BYTES:
7404 case FT_BYTES:
7405 tmp_str = format_bytes_hfinfo_maxlen(NULL((void*)0),
7406 hfinfo,
7407 fvalue_get_bytes_data(finfo->value),
7408 (unsigned)fvalue_length2(finfo->value),
7409 label_str_size);
7410 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7411 wmem_free(NULL((void*)0), tmp_str);
7412 break;
7413
7414 case FT_ABSOLUTE_TIME:
7415 {
7416 const nstime_t *value = fvalue_get_time(finfo->value);
7417 int flags = ABS_TIME_TO_STR_SHOW_ZONE(1U << 0);
7418 if (prefs.display_abs_time_ascii < ABS_TIME_ASCII_COLUMN) {
7419 flags |= ABS_TIME_TO_STR_ISO8601(1U << 3);
7420 }
7421 if (hfinfo->strings) {
7422 const char *time_string = try_time_val_to_str(value, (const time_value_string*)hfinfo->strings);
7423 if (time_string != NULL((void*)0)) {
7424 label_len = proto_strlcpy(display_label_str, time_string, label_str_size);
7425 break;
7426 }
7427 }
7428 tmp_str = abs_time_to_str_ex(NULL((void*)0), value, hfinfo->display, flags);
7429 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7430 wmem_free(NULL((void*)0), tmp_str);
7431 break;
7432 }
7433
7434 case FT_RELATIVE_TIME:
7435 tmp_str = rel_time_to_secs_str(NULL((void*)0), fvalue_get_time(finfo->value));
7436 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7437 wmem_free(NULL((void*)0), tmp_str);
7438 break;
7439
7440 case FT_BOOLEAN:
7441 number64 = fvalue_get_uinteger64(finfo->value);
7442 label_len = proto_strlcpy(display_label_str,
7443 tfs_get_string(!!number64, hfinfo->strings), label_str_size);
7444 break;
7445
7446 case FT_CHAR:
7447 number = fvalue_get_uinteger(finfo->value);
7448
7449 if (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF) == BASE_CUSTOM) {
7450 char tmp[ITEM_LABEL_LENGTH240];
7451 custom_fmt_func_t fmtfunc = (custom_fmt_func_t)hfinfo->strings;
7452
7453 DISSECTOR_ASSERT(fmtfunc)((void) ((fmtfunc) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 7453, "fmtfunc"))))
;
7454 fmtfunc(tmp, number);
7455
7456 label_len = proto_strlcpy(display_label_str, tmp, label_str_size);
7457
7458 } else if (hfinfo->strings) {
7459 number_out = hf_try_val_to_str(number, hfinfo);
7460
7461 if (!number_out) {
7462 number_out = hfinfo_char_value_format_display(BASE_HEX, number_buf, number);
7463 }
7464
7465 label_len = proto_strlcpy(display_label_str, number_out, label_str_size);
7466
7467 } else {
7468 number_out = hfinfo_char_value_format(hfinfo, number_buf, number);
7469
7470 label_len = proto_strlcpy(display_label_str, number_out, label_str_size);
7471 }
7472
7473 break;
7474
7475 /* XXX - make these just FT_NUMBER? */
7476 case FT_INT8:
7477 case FT_INT16:
7478 case FT_INT24:
7479 case FT_INT32:
7480 case FT_UINT8:
7481 case FT_UINT16:
7482 case FT_UINT24:
7483 case FT_UINT32:
7484 case FT_FRAMENUM:
7485 hf_str_val = NULL((void*)0);
7486 number = FT_IS_INT(hfinfo->type)(((hfinfo->type) == FT_INT8 || (hfinfo->type) == FT_INT16
|| (hfinfo->type) == FT_INT24 || (hfinfo->type) == FT_INT32
) || ((hfinfo->type) == FT_INT40 || (hfinfo->type) == FT_INT48
|| (hfinfo->type) == FT_INT56 || (hfinfo->type) == FT_INT64
))
?
7487 (uint32_t) fvalue_get_sinteger(finfo->value) :
7488 fvalue_get_uinteger(finfo->value);
7489
7490 if (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF) == BASE_CUSTOM) {
7491 char tmp[ITEM_LABEL_LENGTH240];
7492 custom_fmt_func_t fmtfunc = (custom_fmt_func_t)hfinfo->strings;
7493
7494 DISSECTOR_ASSERT(fmtfunc)((void) ((fmtfunc) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 7494, "fmtfunc"))))
;
7495 fmtfunc(tmp, number);
7496
7497 label_len = proto_strlcpy(display_label_str, tmp, label_str_size);
7498
7499 } else if (hfinfo->strings && hfinfo->type != FT_FRAMENUM) {
7500 if (hfinfo->display & BASE_UNIT_STRING0x00001000) {
7501 number_out = hfinfo_numeric_value_format(hfinfo, number_buf, number);
7502 label_len = proto_strlcpy(display_label_str, number_out, label_str_size);
7503 hf_str_val = hf_try_val_to_str(number, hfinfo);
7504 if (hf_str_val)
7505 label_len += proto_strlcpy(display_label_str+label_len, hf_str_val, label_str_size-label_len);
7506 } else {
7507 number_out = hf_try_val_to_str(number, hfinfo);
7508
7509 if (!number_out) {
7510 number_out = hfinfo_number_value_format_display(hfinfo, hfinfo->display, number_buf, number);
7511 }
7512
7513 label_len = proto_strlcpy(display_label_str, number_out, label_str_size);
7514 }
7515 } else {
7516 number_out = hfinfo_number_value_format(hfinfo, number_buf, number);
7517
7518 label_len = proto_strlcpy(display_label_str, number_out, label_str_size);
7519 }
7520
7521 break;
7522
7523 case FT_INT40:
7524 case FT_INT48:
7525 case FT_INT56:
7526 case FT_INT64:
7527 case FT_UINT40:
7528 case FT_UINT48:
7529 case FT_UINT56:
7530 case FT_UINT64:
7531 hf_str_val = NULL((void*)0);
7532 number64 = FT_IS_INT(hfinfo->type)(((hfinfo->type) == FT_INT8 || (hfinfo->type) == FT_INT16
|| (hfinfo->type) == FT_INT24 || (hfinfo->type) == FT_INT32
) || ((hfinfo->type) == FT_INT40 || (hfinfo->type) == FT_INT48
|| (hfinfo->type) == FT_INT56 || (hfinfo->type) == FT_INT64
))
?
7533 (uint64_t) fvalue_get_sinteger64(finfo->value) :
7534 fvalue_get_uinteger64(finfo->value);
7535
7536 if (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF) == BASE_CUSTOM) {
7537 char tmp[ITEM_LABEL_LENGTH240];
7538 custom_fmt_func_64_t fmtfunc64 = (custom_fmt_func_64_t)hfinfo->strings;
7539
7540 DISSECTOR_ASSERT(fmtfunc64)((void) ((fmtfunc64) ? (void)0 : (proto_report_dissector_bug(
"%s:%u: failed assertion \"%s\"", "epan/proto.c", 7540, "fmtfunc64"
))))
;
7541 fmtfunc64(tmp, number64);
7542
7543 label_len = proto_strlcpy(display_label_str, tmp, label_str_size);
7544 } else if (hfinfo->strings) {
7545 if (hfinfo->display & BASE_UNIT_STRING0x00001000) {
7546 number_out = hfinfo_numeric_value_format64(hfinfo, number_buf, number64);
7547 label_len = proto_strlcpy(display_label_str, number_out, label_str_size);
7548 hf_str_val = hf_try_val64_to_str(number64, hfinfo);
7549 if (hf_str_val)
7550 label_len += proto_strlcpy(display_label_str+label_len, hf_str_val, label_str_size-label_len);
7551 } else {
7552 number_out = hf_try_val64_to_str(number64, hfinfo);
7553
7554 if (!number_out)
7555 number_out = hfinfo_number_value_format_display64(hfinfo, hfinfo->display, number_buf, number64);
7556
7557 label_len = proto_strlcpy(display_label_str, number_out, label_str_size);
7558 }
7559 } else {
7560 number_out = hfinfo_number_value_format64(hfinfo, number_buf, number64);
7561
7562 label_len = proto_strlcpy(display_label_str, number_out, label_str_size);
7563 }
7564
7565 break;
7566
7567 case FT_EUI64:
7568 set_address (&addr, AT_EUI64, EUI64_ADDR_LEN8, fvalue_get_bytes_data(finfo->value));
7569 tmp_str = address_to_display(NULL((void*)0), &addr);
7570 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7571 wmem_free(NULL((void*)0), tmp_str);
7572 break;
7573
7574 case FT_IPv4:
7575 ipv4 = fvalue_get_ipv4(finfo->value);
7576 //XXX: Should we ignore the mask?
7577 set_address_ipv4(&addr, ipv4);
7578 tmp_str = address_to_display(NULL((void*)0), &addr);
7579 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7580 wmem_free(NULL((void*)0), tmp_str);
7581 free_address(&addr);
7582 break;
7583
7584 case FT_IPv6:
7585 ipv6 = fvalue_get_ipv6(finfo->value);
7586 set_address_ipv6(&addr, ipv6);
7587 tmp_str = address_to_display(NULL((void*)0), &addr);
7588 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7589 wmem_free(NULL((void*)0), tmp_str);
7590 free_address(&addr);
7591 break;
7592
7593 case FT_FCWWN:
7594 set_address (&addr, AT_FCWWN, FCWWN_ADDR_LEN8, fvalue_get_bytes_data(finfo->value));
7595 tmp_str = address_to_display(NULL((void*)0), &addr);
7596 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7597 wmem_free(NULL((void*)0), tmp_str);
7598 break;
7599
7600 case FT_ETHER:
7601 set_address (&addr, AT_ETHER, FT_ETHER_LEN6, fvalue_get_bytes_data(finfo->value));
7602 tmp_str = address_to_display(NULL((void*)0), &addr);
7603 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7604 wmem_free(NULL((void*)0), tmp_str);
7605 break;
7606
7607 case FT_GUID:
7608 tmp_str = guid_to_str(NULL((void*)0), fvalue_get_guid(finfo->value));
7609 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7610 wmem_free(NULL((void*)0), tmp_str);
7611 break;
7612
7613 case FT_REL_OID:
7614 bytes = fvalue_get_bytes_data(finfo->value);
7615 tmp_str = rel_oid_resolved_from_encoded(NULL((void*)0), bytes, (int)fvalue_length2(finfo->value));
7616 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7617 wmem_free(NULL((void*)0), tmp_str);
7618 break;
7619
7620 case FT_OID:
7621 bytes = fvalue_get_bytes_data(finfo->value);
7622 tmp_str = oid_resolved_from_encoded(NULL((void*)0), bytes, (int)fvalue_length2(finfo->value));
7623 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7624 wmem_free(NULL((void*)0), tmp_str);
7625 break;
7626
7627 case FT_SYSTEM_ID:
7628 bytes = fvalue_get_bytes_data(finfo->value);
7629 tmp_str = print_system_id(NULL((void*)0), bytes, (int)fvalue_length2(finfo->value));
7630 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7631 wmem_free(NULL((void*)0), tmp_str);
7632 break;
7633
7634 case FT_FLOAT:
7635 case FT_DOUBLE:
7636 label_len = (int)fill_display_label_float(finfo, display_label_str, label_str_size);
7637 break;
7638
7639 case FT_IEEE_11073_SFLOAT:
7640 case FT_IEEE_11073_FLOAT:
7641 label_len = (int)fill_display_label_ieee_11073_float(finfo, display_label_str, label_str_size);
7642 break;
7643
7644 case FT_STRING:
7645 case FT_STRINGZ:
7646 case FT_UINT_STRING:
7647 case FT_STRINGZPAD:
7648 case FT_STRINGZTRUNC:
7649 str = fvalue_get_string(finfo->value);
7650 label_len = (int)ws_label_strcpy(display_label_str, label_str_size, 0, (const uint8_t*)str, label_strcat_flags(hfinfo));
7651 if (label_len >= label_str_size) {
7652 /* Truncation occurred. Get the real length
7653 * copied (not including '\0') */
7654 label_len = label_str_size ? label_str_size - 1 : 0;
7655 }
7656 break;
7657
7658 default:
7659 /* First try ftype string representation */
7660 tmp_str = fvalue_to_string_repr(NULL((void*)0), finfo->value, FTREPR_DISPLAY, hfinfo->display);
7661 if (!tmp_str) {
7662 /* Default to show as bytes */
7663 bytes = fvalue_get_bytes_data(finfo->value);
7664 tmp_str = bytes_to_str(NULL, bytes, fvalue_length2(finfo->value))bytes_to_str_maxlen(((void*)0), bytes, fvalue_length2(finfo->
value), 36)
;
7665 }
7666 label_len = proto_strlcpy(display_label_str, tmp_str, label_str_size);
7667 wmem_free(NULL((void*)0), tmp_str);
7668 break;
7669 }
7670 return label_len;
7671}
7672
7673const char *
7674proto_custom_set(proto_tree* tree, GSList *field_ids, int occurrence, bool_Bool display_details,
7675 char *result, char *expr, const int size)
7676{
7677 int len, prev_len, last, i, offset_r = 0, offset_e = 0;
7678 GPtrArray *finfos;
7679 field_info *finfo = NULL((void*)0);
7680 header_field_info* hfinfo;
7681 const char *abbrev = NULL((void*)0);
7682
7683 char *str;
7684 col_custom_t *field_idx;
7685 int field_id;
7686 int ii = 0;
7687
7688 ws_assert(field_ids != NULL)do { if ((1) && !(field_ids != ((void*)0))) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 7688, __func__, "assertion failed: %s"
, "field_ids != ((void*)0)"); } while (0)
;
7689 while ((field_idx = (col_custom_t *) g_slist_nth_data(field_ids, ii++))) {
7690 field_id = field_idx->field_id;
7691 if (field_id == 0) {
7692 GPtrArray *fvals = NULL((void*)0);
7693 bool_Bool passed = dfilter_apply_full(field_idx->dfilter, tree, &fvals);
7694 if (fvals != NULL((void*)0)) {
7695
7696 // XXX - Handling occurrences is unusual when more
7697 // than one field is involved, e.g. there's four
7698 // results for tcp.port + tcp.port. We may really
7699 // want to apply it to the operands, not the output.
7700 // Note that occurrences are not quite the same as
7701 // the layer operator (should the grammar support
7702 // both?)
7703 /* Calculate single index or set outer boundaries */
7704 len = g_ptr_array_len(fvals)((fvals) ? (fvals)->len : 0);
7705 if (occurrence < 0) {
7706 i = occurrence + len;
7707 last = i;
7708 } else if (occurrence > 0) {
7709 i = occurrence - 1;
7710 last = i;
7711 } else {
7712 i = 0;
7713 last = len - 1;
7714 }
7715 if (i < 0 || i >= len) {
7716 g_ptr_array_unref(fvals);
7717 continue;
7718 }
7719 for (; i <= last; i++) {
7720 /* XXX - We could have a "resolved" result
7721 * for types where the value depends only
7722 * on the type, e.g. FT_IPv4, and not on
7723 * hfinfo->strings. Supporting the latter
7724 * requires knowing which hfinfo matched
7725 * if there are multiple with the same
7726 * abbreviation. In any case, we need to
7727 * know the expected return type of the
7728 * field expression.
7729 */
7730 str = fvalue_to_string_repr(NULL((void*)0), fvals->pdata[i], FTREPR_DISPLAY, BASE_NONE);
7731 if (offset_r && (offset_r < (size - 1)))
7732 result[offset_r++] = ',';
7733 if (offset_e && (offset_e < (size - 1)))
7734 expr[offset_e++] = ',';
7735 offset_r += proto_strlcpy(result+offset_r, str, size-offset_r);
7736 // col_{add,append,set}_* calls ws_label_strcpy
7737 offset_e = (int) ws_label_strcpy(expr, size, offset_e, (const uint8_t*)str, 0);
7738
7739 g_free(str)(__builtin_object_size ((str), 0) != ((size_t) - 1)) ? g_free_sized
(str, __builtin_object_size ((str), 0)) : (g_free) (str)
;
7740 }
7741 g_ptr_array_unref(fvals);
7742 } else if (passed) {
7743 // XXX - Occurrence doesn't make sense for a test
7744 // output, it should be applied to the operands.
7745 if (offset_r && (offset_r < (size - 1)))
7746 result[offset_r++] = ',';
7747 if (offset_e && (offset_e < (size - 1)))
7748 expr[offset_e++] = ',';
7749 /* Prevent multiple check marks */
7750 if (strstr(result, UTF8_CHECK_MARK"\u2713" ",") == NULL((void*)0)) {
7751 offset_r += proto_strlcpy(result+offset_r, UTF8_CHECK_MARK"\u2713", size-offset_r);
7752 } else {
7753 result[--offset_r] = '\0'; /* Remove the added trailing ',' */
7754 }
7755 if (strstr(expr, UTF8_CHECK_MARK"\u2713" ",") == NULL((void*)0)) {
7756 offset_e += proto_strlcpy(expr+offset_e, UTF8_CHECK_MARK"\u2713", size-offset_e);
7757 } else {
7758 expr[--offset_e] = '\0'; /* Remove the added trailing ',' */
7759 }
7760 }
7761 continue;
7762 }
7763 PROTO_REGISTRAR_GET_NTH((unsigned)field_id, hfinfo)if(((unsigned)field_id == 0 || (unsigned)(unsigned)field_id >
gpa_hfinfo.len) && wireshark_abort_on_dissector_bug)
ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 7763
, __func__, "Unregistered hf! index=%d", (unsigned)field_id);
((void) (((unsigned)field_id > 0 && (unsigned)(unsigned
)field_id < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 7763,
"(unsigned)field_id > 0 && (unsigned)(unsigned)field_id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[(unsigned
)field_id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 7763,
"gpa_hfinfo.hfi[(unsigned)field_id] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[(unsigned)field_id];
;
7764
7765 /* do we need to rewind ? */
7766 if (!hfinfo)
7767 return "";
7768
7769 if (occurrence < 0) {
7770 /* Search other direction */
7771 while (hfinfo->same_name_prev_id != -1) {
7772 PROTO_REGISTRAR_GET_NTH(hfinfo->same_name_prev_id, hfinfo)if((hfinfo->same_name_prev_id == 0 || (unsigned)hfinfo->
same_name_prev_id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 7772
, __func__, "Unregistered hf! index=%d", hfinfo->same_name_prev_id
); ((void) ((hfinfo->same_name_prev_id > 0 && (
unsigned)hfinfo->same_name_prev_id < gpa_hfinfo.len) ? (
void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 7772, "hfinfo->same_name_prev_id > 0 && (unsigned)hfinfo->same_name_prev_id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
same_name_prev_id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 7772,
"gpa_hfinfo.hfi[hfinfo->same_name_prev_id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
same_name_prev_id];
;
7773 }
7774 }
7775
7776 prev_len = 0; /* Reset handled occurrences */
7777
7778 while (hfinfo) {
7779 finfos = proto_get_finfo_ptr_array(tree, hfinfo->id);
7780
7781 if (!finfos || !(len = g_ptr_array_len(finfos)((finfos) ? (finfos)->len : 0))) {
7782 if (occurrence < 0) {
7783 hfinfo = hfinfo->same_name_next;
7784 } else {
7785 hfinfo = hfinfo_same_name_get_prev(hfinfo);
7786 }
7787 continue;
7788 }
7789
7790 /* Are there enough occurrences of the field? */
7791 if (((occurrence - prev_len) > len) || ((occurrence + prev_len) < -len)) {
7792 if (occurrence < 0) {
7793 hfinfo = hfinfo->same_name_next;
7794 } else {
7795 hfinfo = hfinfo_same_name_get_prev(hfinfo);
7796 }
7797 prev_len += len;
7798 continue;
7799 }
7800
7801 /* Calculate single index or set outer boundaries */
7802 if (occurrence < 0) {
7803 i = occurrence + len + prev_len;
7804 last = i;
7805 } else if (occurrence > 0) {
7806 i = occurrence - 1 - prev_len;
7807 last = i;
7808 } else {
7809 i = 0;
7810 last = len - 1;
7811 }
7812
7813 prev_len += len; /* Count handled occurrences */
7814
7815 while (i <= last) {
7816 finfo = (field_info *)g_ptr_array_index(finfos, i)((finfos)->pdata)[i];
7817
7818 if (offset_r && (offset_r < (size - 1)))
7819 result[offset_r++] = ',';
7820
7821 if (display_details) {
7822 char representation[ITEM_LABEL_LENGTH240];
7823 size_t offset = 0;
7824
7825 if (finfo->rep && finfo->rep->value_len) {
7826 (void) g_strlcpy(representation, &finfo->rep->representation[finfo->rep->value_pos],
7827 MIN(finfo->rep->value_len + 1, ITEM_LABEL_LENGTH)(((finfo->rep->value_len + 1) < (240)) ? (finfo->
rep->value_len + 1) : (240))
);
7828 } else {
7829 proto_item_fill_label(finfo, representation, &offset);
7830 }
7831 offset_r += proto_strlcpy(result+offset_r, &representation[offset], size-offset_r);
7832 } else {
7833 switch (hfinfo->type) {
7834
7835 case FT_NONE:
7836 case FT_PROTOCOL:
7837 /* Prevent multiple check marks */
7838 if (strstr(result, UTF8_CHECK_MARK"\u2713" ",") == NULL((void*)0)) {
7839 offset_r += proto_item_fill_display_label(finfo, result+offset_r, size-offset_r);
7840 } else {
7841 result[--offset_r] = '\0'; /* Remove the added trailing ',' again */
7842 }
7843 break;
7844
7845 default:
7846 offset_r += proto_item_fill_display_label(finfo, result+offset_r, size-offset_r);
7847 break;
7848 }
7849 }
7850
7851 if (offset_e && (offset_e < (size - 1)))
7852 expr[offset_e++] = ',';
7853
7854 if (hfinfo->strings && hfinfo->type != FT_FRAMENUM && FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF) == BASE_NONE && (FT_IS_INT(hfinfo->type)(((hfinfo->type) == FT_INT8 || (hfinfo->type) == FT_INT16
|| (hfinfo->type) == FT_INT24 || (hfinfo->type) == FT_INT32
) || ((hfinfo->type) == FT_INT40 || (hfinfo->type) == FT_INT48
|| (hfinfo->type) == FT_INT56 || (hfinfo->type) == FT_INT64
))
|| FT_IS_UINT(hfinfo->type)(((hfinfo->type) == FT_CHAR || (hfinfo->type) == FT_UINT8
|| (hfinfo->type) == FT_UINT16 || (hfinfo->type) == FT_UINT24
|| (hfinfo->type) == FT_UINT32 || (hfinfo->type) == FT_FRAMENUM
) || ((hfinfo->type) == FT_UINT40 || (hfinfo->type) == FT_UINT48
|| (hfinfo->type) == FT_UINT56 || (hfinfo->type) == FT_UINT64
))
)) {
7855 const char *hf_str_val;
7856 /* Integer types with BASE_NONE never get the numeric value. */
7857 if (FT_IS_INT32(hfinfo->type)((hfinfo->type) == FT_INT8 || (hfinfo->type) == FT_INT16
|| (hfinfo->type) == FT_INT24 || (hfinfo->type) == FT_INT32
)
) {
7858 hf_str_val = hf_try_val_to_str_const(fvalue_get_sinteger(finfo->value), hfinfo, "Unknown");
7859 } else if (FT_IS_UINT32(hfinfo->type)((hfinfo->type) == FT_CHAR || (hfinfo->type) == FT_UINT8
|| (hfinfo->type) == FT_UINT16 || (hfinfo->type) == FT_UINT24
|| (hfinfo->type) == FT_UINT32 || (hfinfo->type) == FT_FRAMENUM
)
) {
7860 hf_str_val = hf_try_val_to_str_const(fvalue_get_uinteger(finfo->value), hfinfo, "Unknown");
7861 } else if (FT_IS_INT64(hfinfo->type)((hfinfo->type) == FT_INT40 || (hfinfo->type) == FT_INT48
|| (hfinfo->type) == FT_INT56 || (hfinfo->type) == FT_INT64
)
) {
7862 hf_str_val = hf_try_val64_to_str_const(fvalue_get_sinteger64(finfo->value), hfinfo, "Unknown");
7863 } else { // if (FT_IS_UINT64(hfinfo->type)) {
7864 hf_str_val = hf_try_val64_to_str_const(fvalue_get_uinteger64(finfo->value), hfinfo, "Unknown");
7865 }
7866 snprintf(expr+offset_e, size-offset_e, "\"%s\"", hf_str_val);
7867 offset_e = (int)strlen(expr);
7868 } else if (hfinfo->type == FT_NONE || hfinfo->type == FT_PROTOCOL) {
7869 /* Prevent multiple check marks */
7870 if (strstr(expr, UTF8_CHECK_MARK"\u2713" ",") == NULL((void*)0)) {
7871 offset_e += proto_item_fill_display_label(finfo, expr+offset_e, size-offset_e);
7872 } else {
7873 expr[--offset_e] = '\0'; /* Remove the added trailing ',' again */
7874 }
7875 } else {
7876 str = fvalue_to_string_repr(NULL((void*)0), finfo->value, FTREPR_RAW, finfo->hfinfo->display);
7877 // col_{add,append,set}_* calls ws_label_strcpy
7878 offset_e = (int) ws_label_strcpy(expr, size, offset_e, (const uint8_t*)str, 0);
7879 wmem_free(NULL((void*)0), str);
7880 }
7881 i++;
7882 }
7883
7884 /* XXX: Why is only the first abbreviation returned for a multifield
7885 * custom column? */
7886 if (!abbrev) {
7887 /* Store abbrev for return value */
7888 abbrev = hfinfo->abbrev;
7889 }
7890
7891 if (occurrence == 0) {
7892 /* Fetch next hfinfo with same name (abbrev) */
7893 hfinfo = hfinfo_same_name_get_prev(hfinfo);
7894 } else {
7895 hfinfo = NULL((void*)0);
7896 }
7897 }
7898 }
7899
7900 if (offset_r >= (size - 1)) {
7901 mark_truncated(result, 0, size, NULL((void*)0));
7902 }
7903 if (offset_e >= (size - 1)) {
7904 mark_truncated(expr, 0, size, NULL((void*)0));
7905 }
7906 return abbrev ? abbrev : "";
7907}
7908
7909char *
7910proto_custom_get_filter(epan_dissect_t* edt, GSList *field_ids, int occurrence)
7911{
7912 int len, prev_len, last, i;
7913 GPtrArray *finfos;
7914 field_info *finfo = NULL((void*)0);
7915 header_field_info* hfinfo;
7916
7917 char *filter = NULL((void*)0);
7918 GPtrArray *filter_array;
7919
7920 col_custom_t *col_custom;
7921 int field_id;
7922
7923 ws_assert(field_ids != NULL)do { if ((1) && !(field_ids != ((void*)0))) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 7923, __func__, "assertion failed: %s"
, "field_ids != ((void*)0)"); } while (0)
;
7924 filter_array = g_ptr_array_new_full(g_slist_length(field_ids), g_free);
7925 for (GSList *iter = field_ids; iter; iter = iter->next) {
7926 col_custom = (col_custom_t*)iter->data;
7927 field_id = col_custom->field_id;
7928 if (field_id == 0) {
7929 GPtrArray *fvals = NULL((void*)0);
7930 bool_Bool passed = dfilter_apply_full(col_custom->dfilter, edt->tree, &fvals);
7931 if (fvals != NULL((void*)0)) {
7932 // XXX - Handling occurrences is unusual when more
7933 // than one field is involved, e.g. there's four
7934 // results for tcp.port + tcp.port. We really
7935 // want to apply it to the operands, not the output.
7936 /* Calculate single index or set outer boundaries */
7937 len = g_ptr_array_len(fvals)((fvals) ? (fvals)->len : 0);
7938 if (occurrence < 0) {
7939 i = occurrence + len;
7940 last = i;
7941 } else if (occurrence > 0) {
7942 i = occurrence - 1;
7943 last = i;
7944 } else {
7945 i = 0;
7946 last = len - 1;
7947 }
7948 if (i < 0 || i >= len) {
7949 g_ptr_array_unref(fvals);
7950 continue;
7951 }
7952 for (; i <= last; i++) {
7953 /* XXX - Should multiple values for one
7954 * field use set membership to reduce
7955 * verbosity, here and below? */
7956 char *str = fvalue_to_string_repr(NULL((void*)0), fvals->pdata[i], FTREPR_DFILTER, BASE_NONE);
7957 filter = wmem_strdup_printf(NULL((void*)0), "%s == %s", col_custom->dftext, str);
7958 wmem_free(NULL((void*)0), str);
7959 if (!g_ptr_array_find_with_equal_func(filter_array, filter, g_str_equal, NULL((void*)0))) {
7960 g_ptr_array_add(filter_array, filter);
7961 }
7962 }
7963 g_ptr_array_unref(fvals);
7964 } else if (passed) {
7965 filter = wmem_strdup(NULL((void*)0), col_custom->dftext);
7966 if (!g_ptr_array_find_with_equal_func(filter_array, filter, g_str_equal, NULL((void*)0))) {
7967 g_ptr_array_add(filter_array, filter);
7968 }
7969 } else {
7970 filter = wmem_strdup_printf(NULL((void*)0), "!(%s)", col_custom->dftext);
7971 if (!g_ptr_array_find_with_equal_func(filter_array, filter, g_str_equal, NULL((void*)0))) {
7972 g_ptr_array_add(filter_array, filter);
7973 }
7974 }
7975 continue;
7976 }
7977
7978 PROTO_REGISTRAR_GET_NTH((unsigned)field_id, hfinfo)if(((unsigned)field_id == 0 || (unsigned)(unsigned)field_id >
gpa_hfinfo.len) && wireshark_abort_on_dissector_bug)
ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 7978
, __func__, "Unregistered hf! index=%d", (unsigned)field_id);
((void) (((unsigned)field_id > 0 && (unsigned)(unsigned
)field_id < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 7978,
"(unsigned)field_id > 0 && (unsigned)(unsigned)field_id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[(unsigned
)field_id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 7978,
"gpa_hfinfo.hfi[(unsigned)field_id] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[(unsigned)field_id];
;
7979
7980 /* do we need to rewind ? */
7981 if (!hfinfo)
7982 return NULL((void*)0);
7983
7984 if (occurrence < 0) {
7985 /* Search other direction */
7986 while (hfinfo->same_name_prev_id != -1) {
7987 PROTO_REGISTRAR_GET_NTH(hfinfo->same_name_prev_id, hfinfo)if((hfinfo->same_name_prev_id == 0 || (unsigned)hfinfo->
same_name_prev_id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 7987
, __func__, "Unregistered hf! index=%d", hfinfo->same_name_prev_id
); ((void) ((hfinfo->same_name_prev_id > 0 && (
unsigned)hfinfo->same_name_prev_id < gpa_hfinfo.len) ? (
void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 7987, "hfinfo->same_name_prev_id > 0 && (unsigned)hfinfo->same_name_prev_id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
same_name_prev_id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 7987,
"gpa_hfinfo.hfi[hfinfo->same_name_prev_id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfinfo->
same_name_prev_id];
;
7988 }
7989 }
7990
7991 prev_len = 0; /* Reset handled occurrences */
7992
7993 while (hfinfo) {
7994 finfos = proto_get_finfo_ptr_array(edt->tree, hfinfo->id);
7995
7996 if (!finfos || !(len = g_ptr_array_len(finfos)((finfos) ? (finfos)->len : 0))) {
7997 if (occurrence < 0) {
7998 hfinfo = hfinfo->same_name_next;
7999 } else {
8000 hfinfo = hfinfo_same_name_get_prev(hfinfo);
8001 }
8002 continue;
8003 }
8004
8005 /* Are there enough occurrences of the field? */
8006 if (((occurrence - prev_len) > len) || ((occurrence + prev_len) < -len)) {
8007 if (occurrence < 0) {
8008 hfinfo = hfinfo->same_name_next;
8009 } else {
8010 hfinfo = hfinfo_same_name_get_prev(hfinfo);
8011 }
8012 prev_len += len;
8013 continue;
8014 }
8015
8016 /* Calculate single index or set outer boundaries */
8017 if (occurrence < 0) {
8018 i = occurrence + len + prev_len;
8019 last = i;
8020 } else if (occurrence > 0) {
8021 i = occurrence - 1 - prev_len;
8022 last = i;
8023 } else {
8024 i = 0;
8025 last = len - 1;
8026 }
8027
8028 prev_len += len; /* Count handled occurrences */
8029
8030 while (i <= last) {
8031 finfo = (field_info *)g_ptr_array_index(finfos, i)((finfos)->pdata)[i];
8032
8033 filter = proto_construct_match_selected_string(finfo, edt);
8034 if (filter) {
8035 /* Only add the same expression once (especially for FT_PROTOCOL).
8036 * The ptr array doesn't have NULL entries so g_str_equal is fine.
8037 */
8038 if (!g_ptr_array_find_with_equal_func(filter_array, filter, g_str_equal, NULL((void*)0))) {
8039 g_ptr_array_add(filter_array, filter);
8040 }
8041 }
8042 i++;
8043 }
8044
8045 if (occurrence == 0) {
8046 /* Fetch next hfinfo with same name (abbrev) */
8047 hfinfo = hfinfo_same_name_get_prev(hfinfo);
8048 } else {
8049 hfinfo = NULL((void*)0);
8050 }
8051 }
8052 }
8053
8054 g_ptr_array_add(filter_array, NULL((void*)0));
8055
8056 /* XXX: Should this be || or && ? */
8057 char *output = g_strjoinv(" || ", (char **)filter_array->pdata);
8058
8059 g_ptr_array_free(filter_array, true1);
8060
8061 return output;
8062}
8063
8064/* Set text of proto_item after having already been created. */
8065void
8066proto_item_set_text(proto_item *pi, const char *format, ...)
8067{
8068 field_info *fi = NULL((void*)0);
8069 va_list ap;
8070
8071 TRY_TO_FAKE_THIS_REPR_VOID(pi)if (!pi || !((pi)->finfo)) return; if (!(((pi)->tree_data
)->visible) && proto_item_is_hidden((pi))) { return
; }
;
8072
8073 fi = PITEM_FINFO(pi)((pi)->finfo);
8074 if (fi == NULL((void*)0))
8075 return;
8076
8077 if (fi->rep) {
8078 ITEM_LABEL_FREE(PNODE_POOL(pi), fi->rep)wmem_free(((pi)->tree_data->pinfo->pool), fi->rep
);
;
8079 fi->rep = NULL((void*)0);
8080 }
8081
8082 va_start(ap, format)__builtin_va_start(ap, format);
8083 proto_tree_set_representation(pi, format, ap);
8084 va_end(ap)__builtin_va_end(ap);
8085}
8086
8087/* Append to text of proto_item after having already been created. */
8088void
8089proto_item_append_text(proto_item *pi, const char *format, ...)
8090{
8091 field_info *fi = NULL((void*)0);
8092 size_t curlen;
8093 char *str;
8094 va_list ap;
8095
8096 TRY_TO_FAKE_THIS_REPR_VOID(pi)if (!pi || !((pi)->finfo)) return; if (!(((pi)->tree_data
)->visible) && proto_item_is_hidden((pi))) { return
; }
;
8097
8098 fi = PITEM_FINFO(pi)((pi)->finfo);
8099 if (fi == NULL((void*)0)) {
8100 return;
8101 }
8102
8103 if (!proto_item_is_hidden(pi)) {
8104 /*
8105 * If we don't already have a representation,
8106 * generate the default representation.
8107 */
8108 if (fi->rep == NULL((void*)0)) {
8109 ITEM_LABEL_NEW(PNODE_POOL(pi), fi->rep)fi->rep = ((item_label_t*)wmem_alloc((((pi)->tree_data->
pinfo->pool)), sizeof(item_label_t))); fi->rep->value_pos
= 0; fi->rep->value_len = 0;
;
8110 proto_item_fill_label(fi, fi->rep->representation, &fi->rep->value_pos);
8111 /* Check for special case append value to FT_NONE or FT_PROTOCOL */
8112 if ((fi->hfinfo->type == FT_NONE || fi->hfinfo->type == FT_PROTOCOL) &&
8113 (strncmp(format, ": ", 2) == 0)) {
8114 fi->rep->value_pos += 2;
8115 }
8116 }
8117 if (fi->rep) {
8118 curlen = strlen(fi->rep->representation);
8119 /* curlen doesn't include the \0 byte.
8120 * XXX: If curlen + 4 > ITEM_LABEL_LENGTH, we can't tell if
8121 * the representation has already been truncated (of an up
8122 * to 4 byte UTF-8 character) or is just at the maximum length
8123 * unless we search for " [truncated]" (which may not be
8124 * at the start.)
8125 * It's safer to do nothing.
8126 */
8127 if (ITEM_LABEL_LENGTH240 > (curlen + 4)) {
8128 va_start(ap, format)__builtin_va_start(ap, format);
8129 str = wmem_strdup_vprintf(PNODE_POOL(pi)((pi)->tree_data->pinfo->pool), format, ap);
8130 va_end(ap)__builtin_va_end(ap);
8131 WS_UTF_8_CHECK(str, -1)do { const char *__uni_endptr; if (1 && (str) != ((void
*)0) && !g_utf8_validate(str, -1, &__uni_endptr))
{ do { if (1) { ws_log_utf8_full("UTF-8", LOG_LEVEL_DEBUG, "epan/proto.c"
, 8131, __func__, str, -1, __uni_endptr); } } while (0); } } while
(0)
;
8132 /* Keep fi->rep->value_pos */
8133 curlen = ws_label_strcpy(fi->rep->representation, ITEM_LABEL_LENGTH240, curlen, (const uint8_t*)str, 0);
8134 if (curlen >= ITEM_LABEL_LENGTH240) {
8135 /* Uh oh, we don't have enough room. Tell the user that the field is truncated. */
8136 size_t name_pos = label_find_name_pos(fi->rep);
8137 label_mark_truncated(fi->rep->representation, name_pos, &fi->rep->value_pos);
8138 }
8139 fi->rep->value_len = strlen(fi->rep->representation) - fi->rep->value_pos;
8140 }
8141 }
8142 }
8143}
8144
8145/* Prepend to text of proto_item after having already been created. */
8146void
8147proto_item_prepend_text(proto_item *pi, const char *format, ...)
8148{
8149 field_info *fi = NULL((void*)0);
8150 size_t pos;
8151 char representation[ITEM_LABEL_LENGTH240];
8152 char *str;
8153 va_list ap;
8154
8155 TRY_TO_FAKE_THIS_REPR_VOID(pi)if (!pi || !((pi)->finfo)) return; if (!(((pi)->tree_data
)->visible) && proto_item_is_hidden((pi))) { return
; }
;
8156
8157 fi = PITEM_FINFO(pi)((pi)->finfo);
8158 if (fi == NULL((void*)0)) {
8159 return;
8160 }
8161
8162 if (!proto_item_is_hidden(pi)) {
8163 /*
8164 * If we don't already have a representation,
8165 * generate the default representation.
8166 */
8167 if (fi->rep == NULL((void*)0)) {
8168 ITEM_LABEL_NEW(PNODE_POOL(pi), fi->rep)fi->rep = ((item_label_t*)wmem_alloc((((pi)->tree_data->
pinfo->pool)), sizeof(item_label_t))); fi->rep->value_pos
= 0; fi->rep->value_len = 0;
;
8169 proto_item_fill_label(fi, representation, &fi->rep->value_pos);
8170 } else
8171 (void) g_strlcpy(representation, fi->rep->representation, ITEM_LABEL_LENGTH240);
8172
8173 va_start(ap, format)__builtin_va_start(ap, format);
8174 str = wmem_strdup_vprintf(PNODE_POOL(pi)((pi)->tree_data->pinfo->pool), format, ap);
8175 va_end(ap)__builtin_va_end(ap);
8176 WS_UTF_8_CHECK(str, -1)do { const char *__uni_endptr; if (1 && (str) != ((void
*)0) && !g_utf8_validate(str, -1, &__uni_endptr))
{ do { if (1) { ws_log_utf8_full("UTF-8", LOG_LEVEL_DEBUG, "epan/proto.c"
, 8176, __func__, str, -1, __uni_endptr); } } while (0); } } while
(0)
;
8177 fi->rep->value_pos += strlen(str);
8178 pos = ws_label_strcpy(fi->rep->representation, ITEM_LABEL_LENGTH240, 0, (const uint8_t*)str, 0);
8179 pos = ws_label_strcpy(fi->rep->representation, ITEM_LABEL_LENGTH240, pos, (const uint8_t*)representation, 0);
8180 /* XXX: As above, if the old representation is close to the label
8181 * length, it might already be marked as truncated. */
8182 if (pos >= ITEM_LABEL_LENGTH240 && (strlen(representation) + 4) <= ITEM_LABEL_LENGTH240) {
8183 /* Uh oh, we don't have enough room. Tell the user that the field is truncated. */
8184 size_t name_pos = label_find_name_pos(fi->rep);
8185 label_mark_truncated(fi->rep->representation, name_pos, &fi->rep->value_pos);
8186 }
8187 fi->rep->value_len = strlen(fi->rep->representation) - fi->rep->value_pos;
8188 }
8189}
8190
8191static void
8192finfo_set_len(field_info *fi, const unsigned length)
8193{
8194 unsigned length_remaining;
8195
8196 length_remaining = G_LIKELY(fi->ds_tvb)(fi->ds_tvb) ? tvb_captured_length_remaining(fi->ds_tvb, fi->start) : 0;
8197 if (length > length_remaining)
8198 fi->length = length_remaining;
8199 else
8200 fi->length = length;
8201
8202 /* If we have an FT_PROTOCOL we need to set the length of the fvalue tvbuff as well. */
8203 if (fvalue_type_ftenum(fi->value) == FT_PROTOCOL) {
8204 fvalue_set_protocol_length(fi->value, fi->length);
8205 }
8206
8207 /*
8208 * You cannot just make the "len" field of a GByteArray
8209 * larger, if there's no data to back that length;
8210 * you can only make it smaller.
8211 */
8212 if (fvalue_type_ftenum(fi->value) == FT_BYTES && fi->length > 0) {
8213 GBytes *bytes = fvalue_get_bytes(fi->value);
8214 size_t size;
8215 const void *data = g_bytes_get_data(bytes, &size);
8216 if ((size_t)fi->length <= size) {
8217 fvalue_set_bytes_data(fi->value, data, fi->length);
8218 }
8219 g_bytes_unref(bytes);
8220 }
8221}
8222
8223void
8224proto_item_set_len(proto_item *pi, const unsigned length)
8225{
8226 field_info *fi;
8227
8228 if (pi == NULL((void*)0))
8229 return;
8230
8231 fi = PITEM_FINFO(pi)((pi)->finfo);
8232 if (fi == NULL((void*)0))
8233 return;
8234
8235 finfo_set_len(fi, length);
8236}
8237
8238/*
8239 * Sets the length of the item based on its start and on the specified
8240 * offset, which is the offset past the end of the item; as the start
8241 * in the item is relative to the beginning of the data source tvbuff,
8242 * we need to pass in a tvbuff - the end offset is relative to the beginning
8243 * of that tvbuff.
8244 */
8245void
8246proto_item_set_end(proto_item *pi, tvbuff_t *tvb, unsigned end)
8247{
8248 field_info *fi;
8249 unsigned length;
8250
8251 if (pi == NULL((void*)0))
8252 return;
8253
8254 fi = PITEM_FINFO(pi)((pi)->finfo);
8255 if (fi == NULL((void*)0))
8256 return;
8257
8258 if (G_LIKELY(tvb)(tvb)) {
8259 DISSECTOR_ASSERT(tvb_get_ds_tvb(tvb) == fi->ds_tvb)((void) ((tvb_get_ds_tvb(tvb) == fi->ds_tvb) ? (void)0 : (
proto_report_dissector_bug("%s:%u: failed assertion \"%s\"", "epan/proto.c"
, 8259, "tvb_get_ds_tvb(tvb) == fi->ds_tvb"))))
;
8260 end += tvb_raw_offset(tvb);
8261 } else {
8262 DISSECTOR_ASSERT(NULL == fi->ds_tvb)((void) ((((void*)0) == fi->ds_tvb) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 8262, "((void*)0) == fi->ds_tvb"
))))
;
8263 }
8264 DISSECTOR_ASSERT(end >= fi->start)((void) ((end >= fi->start) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 8264, "end >= fi->start"
))))
;
8265 length = end - fi->start;
8266
8267 finfo_set_len(fi, length);
8268}
8269
8270unsigned
8271proto_item_get_len(const proto_item *pi)
8272{
8273 /* XXX - The only use case where this is really guaranteed to work is
8274 * increasing the length of an item (which has no effect if the item
8275 * is faked, so it doesn't matter that this returns 0 in that case), e.g.
8276 *
8277 * proto_item_set_len(pi, proto_item_get_len(pi) + delta);
8278 *
8279 * Should there be a macro or function to do that, and possibly this
8280 * be deprecated? As a bonus, we could handle overflow.
8281 */
8282 field_info *fi;
8283
8284 if (!pi)
8285 return 0;
8286 fi = PITEM_FINFO(pi)((pi)->finfo);
8287 if (fi) {
8288 return fi->length;
8289 }
8290 return 0;
8291}
8292
8293void
8294proto_item_set_bits_offset_len(proto_item *ti, int bits_offset, int bits_len) {
8295 if (!ti) {
8296 return;
8297 }
8298 FI_SET_FLAG(PNODE_FINFO(ti), FI_BITS_OFFSET(bits_offset))do { if (((ti)->finfo)) (((ti)->finfo))->flags = (((
ti)->finfo))->flags | ((((bits_offset) & 63) <<
5)); } while(0)
;
8299 FI_SET_FLAG(PNODE_FINFO(ti), FI_BITS_SIZE(bits_len))do { if (((ti)->finfo)) (((ti)->finfo))->flags = (((
ti)->finfo))->flags | ((((bits_len) & 63) << 12
)); } while(0)
;
8300}
8301
8302char *
8303proto_item_get_display_repr(wmem_allocator_t *scope, proto_item *pi)
8304{
8305 field_info *fi;
8306
8307 if (!pi)
8308 return wmem_strdup(scope, "");
8309 fi = PITEM_FINFO(pi)((pi)->finfo);
8310 if (!fi)
8311 return wmem_strdup(scope, "");
8312 DISSECTOR_ASSERT(fi->hfinfo != NULL)((void) ((fi->hfinfo != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 8312, "fi->hfinfo != ((void*)0)"
))))
;
8313 return fvalue_to_string_repr(scope, fi->value, FTREPR_DISPLAY, fi->hfinfo->display);
8314}
8315
8316proto_tree *
8317proto_tree_create_root(packet_info *pinfo)
8318{
8319 proto_node *pnode;
8320
8321 /* Initialize the proto_node */
8322 pnode = g_slice_new(proto_tree)((proto_tree*) g_slice_alloc ((sizeof (proto_tree) > 0 ? sizeof
(proto_tree) : 1)))
;
8323 PROTO_NODE_INIT(pnode)pnode->first_child = ((void*)0); pnode->last_child = ((
void*)0); pnode->next = ((void*)0);
;
8324 pnode->parent = NULL((void*)0);
8325 PNODE_FINFO(pnode)((pnode)->finfo) = NULL((void*)0);
8326 pnode->tree_data = g_slice_new(tree_data_t)((tree_data_t*) g_slice_alloc ((sizeof (tree_data_t) > 0 ?
sizeof (tree_data_t) : 1)))
;
8327
8328 /* Make sure we can access pinfo everywhere */
8329 pnode->tree_data->pinfo = pinfo;
8330
8331 /* Don't initialize the tree_data_t. Wait until we know we need it */
8332 pnode->tree_data->interesting_hfids = NULL((void*)0);
8333
8334 /* Set the default to false so it's easier to
8335 * find errors; if we expect to see the protocol tree
8336 * but for some reason the default 'visible' is not
8337 * changed, then we'll find out very quickly. */
8338 pnode->tree_data->visible = false0;
8339
8340 /* Make sure that we fake protocols (if possible) */
8341 pnode->tree_data->fake_protocols = true1;
8342
8343 /* Keep track of the number of children */
8344 pnode->tree_data->count = 0;
8345
8346 /* Initialize our loop checks */
8347 pnode->tree_data->idle_count_ds_tvb = NULL((void*)0);
8348 pnode->tree_data->max_start = 0;
8349 pnode->tree_data->start_idle_count = 0;
8350
8351 return (proto_tree *)pnode;
8352}
8353
8354
8355/* "prime" a proto_tree with a single hfid that a dfilter
8356 * is interested in. */
8357void
8358proto_tree_prime_with_hfid(proto_tree *tree _U___attribute__((unused)), const int hfid)
8359{
8360 header_field_info *hfinfo;
8361
8362 PROTO_REGISTRAR_GET_NTH(hfid, hfinfo)if((hfid == 0 || (unsigned)hfid > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 8362, __func__, "Unregistered hf! index=%d"
, hfid); ((void) ((hfid > 0 && (unsigned)hfid <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 8362, "hfid > 0 && (unsigned)hfid < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfid] != (
(void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 8362, "gpa_hfinfo.hfi[hfid] != ((void*)0)",
"Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfid];
;
8363 /* this field is referenced by a filter so increase the refcount.
8364 also increase the refcount for the parent, i.e the protocol.
8365 Don't increase the refcount if we're already printing the
8366 type, as that is a superset of direct reference.
8367 */
8368 if (hfinfo->ref_type != HF_REF_TYPE_PRINT) {
8369 hfinfo->ref_type = HF_REF_TYPE_DIRECT;
8370 }
8371 /* only increase the refcount if there is a parent.
8372 if this is a protocol and not a field then parent will be -1
8373 and there is no parent to add any refcounting for.
8374 */
8375 if (hfinfo->parent != -1) {
8376 header_field_info *parent_hfinfo;
8377 PROTO_REGISTRAR_GET_NTH(hfinfo->parent, parent_hfinfo)if((hfinfo->parent == 0 || (unsigned)hfinfo->parent >
gpa_hfinfo.len) && wireshark_abort_on_dissector_bug)
ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 8377
, __func__, "Unregistered hf! index=%d", hfinfo->parent); (
(void) ((hfinfo->parent > 0 && (unsigned)hfinfo
->parent < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 8377,
"hfinfo->parent > 0 && (unsigned)hfinfo->parent < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
parent] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 8377,
"gpa_hfinfo.hfi[hfinfo->parent] != ((void*)0)", "Unregistered hf."
)))) ; parent_hfinfo = gpa_hfinfo.hfi[hfinfo->parent];
;
8378
8379 /* Mark parent as indirectly referenced unless it is already directly
8380 * referenced, i.e. the user has specified the parent in a filter.
8381 */
8382 if (parent_hfinfo->ref_type == HF_REF_TYPE_NONE)
8383 parent_hfinfo->ref_type = HF_REF_TYPE_INDIRECT;
8384 }
8385}
8386
8387/* "prime" a proto_tree with a single hfid that a dfilter
8388 * is interested in. */
8389void
8390proto_tree_prime_with_hfid_print(proto_tree *tree _U___attribute__((unused)), const int hfid)
8391{
8392 header_field_info *hfinfo;
8393
8394 PROTO_REGISTRAR_GET_NTH(hfid, hfinfo)if((hfid == 0 || (unsigned)hfid > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 8394, __func__, "Unregistered hf! index=%d"
, hfid); ((void) ((hfid > 0 && (unsigned)hfid <
gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 8394, "hfid > 0 && (unsigned)hfid < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfid] != (
(void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 8394, "gpa_hfinfo.hfi[hfid] != ((void*)0)",
"Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfid];
;
8395 /* this field is referenced by an (output) filter so increase the refcount.
8396 also increase the refcount for the parent, i.e the protocol.
8397 */
8398 hfinfo->ref_type = HF_REF_TYPE_PRINT;
8399 /* only increase the refcount if there is a parent.
8400 if this is a protocol and not a field then parent will be -1
8401 and there is no parent to add any refcounting for.
8402 */
8403 if (hfinfo->parent != -1) {
8404 header_field_info *parent_hfinfo;
8405 PROTO_REGISTRAR_GET_NTH(hfinfo->parent, parent_hfinfo)if((hfinfo->parent == 0 || (unsigned)hfinfo->parent >
gpa_hfinfo.len) && wireshark_abort_on_dissector_bug)
ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 8405
, __func__, "Unregistered hf! index=%d", hfinfo->parent); (
(void) ((hfinfo->parent > 0 && (unsigned)hfinfo
->parent < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 8405,
"hfinfo->parent > 0 && (unsigned)hfinfo->parent < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
parent] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 8405,
"gpa_hfinfo.hfi[hfinfo->parent] != ((void*)0)", "Unregistered hf."
)))) ; parent_hfinfo = gpa_hfinfo.hfi[hfinfo->parent];
;
8406
8407 /* Mark parent as indirectly referenced unless it is already directly
8408 * referenced, i.e. the user has specified the parent in a filter.
8409 */
8410 if (parent_hfinfo->ref_type == HF_REF_TYPE_NONE)
8411 parent_hfinfo->ref_type = HF_REF_TYPE_INDIRECT;
8412 }
8413}
8414
8415proto_tree *
8416proto_item_add_subtree(proto_item *pi, const int idx) {
8417 field_info *fi;
8418
8419 if (!pi)
8420 return NULL((void*)0);
8421
8422 DISSECTOR_ASSERT(idx >= 0 && idx < num_tree_types)((void) ((idx >= 0 && idx < num_tree_types) ? (
void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 8422, "idx >= 0 && idx < num_tree_types"
))))
;
8423
8424 fi = PITEM_FINFO(pi)((pi)->finfo);
8425 if (!fi)
8426 return (proto_tree *)pi;
8427
8428 fi->tree_type = idx;
8429
8430 return (proto_tree *)pi;
8431}
8432
8433proto_tree *
8434proto_item_get_subtree(proto_item *pi) {
8435 field_info *fi;
8436
8437 if (!pi)
8438 return NULL((void*)0);
8439 fi = PITEM_FINFO(pi)((pi)->finfo);
8440 if ( (fi) && (fi->tree_type == -1) )
8441 return NULL((void*)0);
8442 return (proto_tree *)pi;
8443}
8444
8445proto_item *
8446proto_item_get_parent(const proto_item *ti) {
8447 if (!ti)
8448 return NULL((void*)0);
8449 return ti->parent;
8450}
8451
8452proto_item *
8453proto_item_get_parent_nth(proto_item *ti, int gen) {
8454 if (!ti)
8455 return NULL((void*)0);
8456 while (gen--) {
8457 ti = ti->parent;
8458 if (!ti)
8459 return NULL((void*)0);
8460 }
8461 return ti;
8462}
8463
8464
8465proto_item *
8466proto_tree_get_parent(proto_tree *tree) {
8467 if (!tree)
8468 return NULL((void*)0);
8469 return (proto_item *)tree;
8470}
8471
8472proto_tree *
8473proto_tree_get_parent_tree(proto_tree *tree) {
8474 if (!tree)
8475 return NULL((void*)0);
8476
8477 /* we're the root tree, there's no parent
8478 return ourselves so the caller has at least a tree to attach to */
8479 if (!tree->parent)
8480 return tree;
8481
8482 return (proto_tree *)tree->parent;
8483}
8484
8485proto_tree *
8486proto_tree_get_root(proto_tree *tree) {
8487 if (!tree)
8488 return NULL((void*)0);
8489 while (tree->parent) {
8490 tree = tree->parent;
8491 }
8492 return tree;
8493}
8494
8495void
8496proto_tree_move_item(proto_tree *tree, proto_item *fixed_item,
8497 proto_item *item_to_move)
8498{
8499 /* This function doesn't generate any values. It only reorganizes the protocol tree
8500 * so we can bail out immediately if it isn't visible. */
8501 if (!tree || !PTREE_DATA(tree)((tree)->tree_data)->visible)
8502 return;
8503
8504 DISSECTOR_ASSERT(item_to_move->parent == tree)((void) ((item_to_move->parent == tree) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 8504, "item_to_move->parent == tree"
))))
;
8505 DISSECTOR_ASSERT(fixed_item->parent == tree)((void) ((fixed_item->parent == tree) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 8505, "fixed_item->parent == tree"
))))
;
8506
8507 /*** cut item_to_move out ***/
8508
8509 /* is item_to_move the first? */
8510 if (tree->first_child == item_to_move) {
8511 /* simply change first child to next */
8512 tree->first_child = item_to_move->next;
8513
8514 DISSECTOR_ASSERT(tree->last_child != item_to_move)((void) ((tree->last_child != item_to_move) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 8514, "tree->last_child != item_to_move"
))))
;
8515 } else {
8516 proto_item *curr_item;
8517 /* find previous and change it's next */
8518 for (curr_item = tree->first_child; curr_item != NULL((void*)0); curr_item = curr_item->next) {
8519 if (curr_item->next == item_to_move) {
8520 break;
8521 }
8522 }
8523
8524 DISSECTOR_ASSERT(curr_item)((void) ((curr_item) ? (void)0 : (proto_report_dissector_bug(
"%s:%u: failed assertion \"%s\"", "epan/proto.c", 8524, "curr_item"
))))
;
8525
8526 curr_item->next = item_to_move->next;
8527
8528 /* fix last_child if required */
8529 if (tree->last_child == item_to_move) {
8530 tree->last_child = curr_item;
8531 }
8532 }
8533
8534 /*** insert to_move after fixed ***/
8535 item_to_move->next = fixed_item->next;
8536 fixed_item->next = item_to_move;
8537 if (tree->last_child == fixed_item) {
8538 tree->last_child = item_to_move;
8539 }
8540}
8541
8542void
8543proto_tree_set_appendix(proto_tree *tree, tvbuff_t *tvb, unsigned start,
8544 const unsigned length)
8545{
8546 field_info *fi;
8547
8548 if (tree == NULL((void*)0))
8549 return;
8550
8551 fi = PTREE_FINFO(tree)((tree)->finfo);
8552 if (fi == NULL((void*)0))
8553 return;
8554
8555 /* We don't store a separate data source tvb for the appendix, so
8556 * it must be from the same data source. (XXX - Are there any
8557 * situations where it makes sense to have an appendix from a
8558 * different data source?) */
8559 if (G_LIKELY(tvb)(tvb)) {
8560 DISSECTOR_ASSERT(tvb_get_ds_tvb(tvb) == fi->ds_tvb)((void) ((tvb_get_ds_tvb(tvb) == fi->ds_tvb) ? (void)0 : (
proto_report_dissector_bug("%s:%u: failed assertion \"%s\"", "epan/proto.c"
, 8560, "tvb_get_ds_tvb(tvb) == fi->ds_tvb"))))
;
8561 start += tvb_raw_offset(tvb);
8562 } else {
8563 DISSECTOR_ASSERT(NULL == fi->ds_tvb)((void) ((((void*)0) == fi->ds_tvb) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 8563, "((void*)0) == fi->ds_tvb"
))))
;
8564 }
8565
8566 /* XXX - DISSECTOR_ASSERT that the appendix doesn't overlap the
8567 * main body? */
8568
8569 fi->appendix_start = start;
8570 fi->appendix_length = length;
8571}
8572
8573static void
8574check_protocol_filter_name_or_fail(const char *filter_name)
8575{
8576 /* Require at least two characters. */
8577 if (filter_name[0] == '\0' || filter_name[1] == '\0') {
8578 REPORT_DISSECTOR_BUG("Protocol filter name \"%s\" cannot have length less than two.", filter_name)proto_report_dissector_bug("Protocol filter name \"%s\" cannot have length less than two."
, filter_name)
;
8579 }
8580
8581 if (proto_check_field_name(filter_name) != '\0') {
8582 REPORT_DISSECTOR_BUG("Protocol filter name \"%s\" has one or more invalid characters."proto_report_dissector_bug("Protocol filter name \"%s\" has one or more invalid characters."
" Allowed are letters, digits, '-', '_' and non-repeating '.'."
" This might be caused by an inappropriate plugin or a development error."
, filter_name)
8583 " Allowed are letters, digits, '-', '_' and non-repeating '.'."proto_report_dissector_bug("Protocol filter name \"%s\" has one or more invalid characters."
" Allowed are letters, digits, '-', '_' and non-repeating '.'."
" This might be caused by an inappropriate plugin or a development error."
, filter_name)
8584 " This might be caused by an inappropriate plugin or a development error.", filter_name)proto_report_dissector_bug("Protocol filter name \"%s\" has one or more invalid characters."
" Allowed are letters, digits, '-', '_' and non-repeating '.'."
" This might be caused by an inappropriate plugin or a development error."
, filter_name)
;
8585 }
8586
8587 /* Check that it doesn't match some very common numeric forms. */
8588 if (filter_name[0] == '0' &&
8589 (filter_name[1] == 'x' || filter_name[1] == 'X' ||
8590 filter_name[1] == 'b' || filter_name[1] == 'B')) {
8591 REPORT_DISSECTOR_BUG("Protocol filter name \"%s\" cannot start with \"%c%c\".",proto_report_dissector_bug("Protocol filter name \"%s\" cannot start with \"%c%c\"."
, filter_name, filter_name[0], filter_name[1])
8592 filter_name, filter_name[0], filter_name[1])proto_report_dissector_bug("Protocol filter name \"%s\" cannot start with \"%c%c\"."
, filter_name, filter_name[0], filter_name[1])
;
8593 }
8594
8595 /* Names starting with a digit must not contain a minus sign (currently not checked at runtime). */
8596
8597 /* Check that it contains at least one letter. */
8598 bool_Bool have_letter = false0;
8599 for (const char *s = filter_name; *s != '\0'; s++) {
8600 if (g_ascii_isalpha(*s)((g_ascii_table[(guchar) (*s)] & G_ASCII_ALPHA) != 0)) {
8601 have_letter = true1;
8602 break;
8603 }
8604 }
8605 if (!have_letter) {
8606 REPORT_DISSECTOR_BUG("Protocol filter name \"%s\" must contain at least one letter a-z.",proto_report_dissector_bug("Protocol filter name \"%s\" must contain at least one letter a-z."
, filter_name)
8607 filter_name)proto_report_dissector_bug("Protocol filter name \"%s\" must contain at least one letter a-z."
, filter_name)
;
8608 }
8609
8610 /* Check for reserved keywords. */
8611 if (g_hash_table_contains(proto_reserved_filter_names, filter_name)) {
8612 REPORT_DISSECTOR_BUG("Protocol filter name \"%s\" is invalid because it is a reserved keyword."proto_report_dissector_bug("Protocol filter name \"%s\" is invalid because it is a reserved keyword."
" This might be caused by an inappropriate plugin or a development error."
, filter_name)
8613 " This might be caused by an inappropriate plugin or a development error.", filter_name)proto_report_dissector_bug("Protocol filter name \"%s\" is invalid because it is a reserved keyword."
" This might be caused by an inappropriate plugin or a development error."
, filter_name)
;
8614 }
8615}
8616
8617int
8618proto_register_protocol(const char *name, const char *short_name, const char *filter_name)
8619{
8620 protocol_t *protocol;
8621 header_field_info *hfinfo;
8622
8623 check_protocol_filter_name_or_fail(filter_name);
8624
8625 /*
8626 * Add this protocol to the list of known protocols;
8627 * the list is sorted by protocol short name.
8628 */
8629 protocol = g_new(protocol_t, 1)((protocol_t *) g_malloc_n ((1), sizeof (protocol_t)));
8630 protocol->name = name;
8631 protocol->short_name = short_name;
8632 protocol->filter_name = filter_name;
8633 protocol->fields = NULL((void*)0); /* Delegate until actually needed */
8634 protocol->is_enabled = true1; /* protocol is enabled by default */
8635 protocol->enabled_by_default = true1; /* see previous comment */
8636 protocol->can_toggle = true1;
8637 protocol->parent_proto_id = -1;
8638 protocol->heur_list = NULL((void*)0);
8639
8640 /* List will be sorted later by name, when all protocols completed registering */
8641 protocols = g_list_prepend(protocols, protocol);
8642 /*
8643 * Make sure there's not already a protocol with any of those
8644 * names. Crash if there is, as that's an error in the code
8645 * or an inappropriate plugin.
8646 * This situation has to be fixed to not register more than one
8647 * protocol with the same name.
8648 */
8649 if (!g_hash_table_insert(proto_names, (void *)name, protocol)) {
8650 /* ws_error will terminate the program */
8651 REPORT_DISSECTOR_BUG("Duplicate protocol name \"%s\"."proto_report_dissector_bug("Duplicate protocol name \"%s\"." " This might be caused by an inappropriate plugin or a development error."
, name)
8652 " This might be caused by an inappropriate plugin or a development error.", name)proto_report_dissector_bug("Duplicate protocol name \"%s\"." " This might be caused by an inappropriate plugin or a development error."
, name)
;
8653 }
8654 if (!g_hash_table_insert(proto_filter_names, (void *)filter_name, protocol)) {
8655 REPORT_DISSECTOR_BUG("Duplicate protocol filter_name \"%s\"."proto_report_dissector_bug("Duplicate protocol filter_name \"%s\"."
" This might be caused by an inappropriate plugin or a development error."
, filter_name)
8656 " This might be caused by an inappropriate plugin or a development error.", filter_name)proto_report_dissector_bug("Duplicate protocol filter_name \"%s\"."
" This might be caused by an inappropriate plugin or a development error."
, filter_name)
;
8657 }
8658 if (!g_hash_table_insert(proto_short_names, (void *)short_name, protocol)) {
8659 REPORT_DISSECTOR_BUG("Duplicate protocol short_name \"%s\"."proto_report_dissector_bug("Duplicate protocol short_name \"%s\"."
" This might be caused by an inappropriate plugin or a development error."
, short_name)
8660 " This might be caused by an inappropriate plugin or a development error.", short_name)proto_report_dissector_bug("Duplicate protocol short_name \"%s\"."
" This might be caused by an inappropriate plugin or a development error."
, short_name)
;
8661 }
8662
8663 /* Here we allocate a new header_field_info struct */
8664 hfinfo = g_slice_new(header_field_info)((header_field_info*) g_slice_alloc ((sizeof (header_field_info
) > 0 ? sizeof (header_field_info) : 1)))
;
8665 hfinfo->name = name;
8666 hfinfo->abbrev = filter_name;
8667 hfinfo->type = FT_PROTOCOL;
8668 hfinfo->display = BASE_NONE;
8669 hfinfo->strings = protocol;
8670 hfinfo->bitmask = 0;
8671 hfinfo->ref_type = HF_REF_TYPE_NONE;
8672 hfinfo->blurb = NULL((void*)0);
8673 hfinfo->parent = -1; /* This field differentiates protos and fields */
8674
8675 protocol->proto_id = proto_register_field_init(hfinfo, hfinfo->parent);
8676 return protocol->proto_id;
8677}
8678
8679int
8680proto_register_protocol_in_name_only(const char *name, const char *short_name, const char *filter_name, int parent_proto, enum ftenum field_type)
8681{
8682 protocol_t *protocol;
8683 header_field_info *hfinfo;
8684
8685 /*
8686 * Helper protocols don't need the strict rules as a "regular" protocol
8687 * Just register it in a list and make a hf_ field from it
8688 */
8689 if ((field_type != FT_PROTOCOL) && (field_type != FT_BYTES)) {
8690 REPORT_DISSECTOR_BUG("Pino \"%s\" must be of type FT_PROTOCOL or FT_BYTES.", name)proto_report_dissector_bug("Pino \"%s\" must be of type FT_PROTOCOL or FT_BYTES."
, name)
;
8691 }
8692
8693 if (parent_proto <= 0) {
8694 REPORT_DISSECTOR_BUG("Must have a valid parent protocol for helper protocol \"%s\"."proto_report_dissector_bug("Must have a valid parent protocol for helper protocol \"%s\"."
" This might be caused by an inappropriate plugin or a development error."
, name)
8695 " This might be caused by an inappropriate plugin or a development error.", name)proto_report_dissector_bug("Must have a valid parent protocol for helper protocol \"%s\"."
" This might be caused by an inappropriate plugin or a development error."
, name)
;
8696 }
8697
8698 check_protocol_filter_name_or_fail(filter_name);
8699
8700 /* Add this protocol to the list of helper protocols (just so it can be properly freed) */
8701 protocol = g_new(protocol_t, 1)((protocol_t *) g_malloc_n ((1), sizeof (protocol_t)));
8702 protocol->name = name;
8703 protocol->short_name = short_name;
8704 protocol->filter_name = filter_name;
8705 protocol->fields = NULL((void*)0); /* Delegate until actually needed */
8706
8707 /* Enabling and toggling is really determined by parent protocol,
8708 but provide default values here */
8709 protocol->is_enabled = true1;
8710 protocol->enabled_by_default = true1;
8711 protocol->can_toggle = true1;
8712
8713 protocol->parent_proto_id = parent_proto;
8714 protocol->heur_list = NULL((void*)0);
8715
8716 /* List will be sorted later by name, when all protocols completed registering */
8717 protocols = g_list_prepend(protocols, protocol);
8718
8719 /* Here we allocate a new header_field_info struct */
8720 hfinfo = g_slice_new(header_field_info)((header_field_info*) g_slice_alloc ((sizeof (header_field_info
) > 0 ? sizeof (header_field_info) : 1)))
;
8721 hfinfo->name = name;
8722 hfinfo->abbrev = filter_name;
8723 hfinfo->type = field_type;
8724 hfinfo->display = BASE_NONE;
8725 if (field_type == FT_BYTES) {
8726 hfinfo->display |= (BASE_NO_DISPLAY_VALUE0x00002000|BASE_PROTOCOL_INFO0x00004000);
8727 }
8728 hfinfo->strings = protocol;
8729 hfinfo->bitmask = 0;
8730 hfinfo->ref_type = HF_REF_TYPE_NONE;
8731 hfinfo->blurb = NULL((void*)0);
8732 hfinfo->parent = -1; /* This field differentiates protos and fields */
8733
8734 protocol->proto_id = proto_register_field_init(hfinfo, hfinfo->parent);
8735 return protocol->proto_id;
8736}
8737
8738bool_Bool
8739proto_deregister_protocol(const char *short_name)
8740{
8741 protocol_t *protocol;
8742 header_field_info *hfinfo;
8743 int proto_id;
8744 unsigned i;
8745
8746 proto_id = proto_get_id_by_short_name(short_name);
8747 protocol = find_protocol_by_id(proto_id);
8748 if (protocol == NULL((void*)0))
8749 return false0;
8750
8751 g_hash_table_remove(proto_names, protocol->name);
8752 g_hash_table_remove(proto_short_names, (void *)short_name);
8753 g_hash_table_remove(proto_filter_names, (void *)protocol->filter_name);
8754
8755 if (protocol->fields) {
8756 for (i = 0; i < protocol->fields->len; i++) {
8757 hfinfo = (header_field_info *)g_ptr_array_index(protocol->fields, i)((protocol->fields)->pdata)[i];
8758 hfinfo_remove_from_gpa_name_map(hfinfo);
8759 expert_deregister_expertinfo(hfinfo->abbrev);
8760 g_ptr_array_add(deregistered_fields, gpa_hfinfo.hfi[hfinfo->id]);
8761 }
8762 g_ptr_array_free(protocol->fields, true1);
8763 protocol->fields = NULL((void*)0);
8764 }
8765
8766 g_list_free(protocol->heur_list);
8767
8768 /* Remove this protocol from the list of known protocols */
8769 protocols = g_list_remove(protocols, protocol);
8770
8771 g_ptr_array_add(deregistered_fields, gpa_hfinfo.hfi[proto_id]);
8772 wmem_map_remove(gpa_name_map, protocol->filter_name);
8773
8774 g_free(last_field_name)(__builtin_object_size ((last_field_name), 0) != ((size_t) - 1
)) ? g_free_sized (last_field_name, __builtin_object_size ((last_field_name
), 0)) : (g_free) (last_field_name)
;
8775 last_field_name = NULL((void*)0);
8776
8777 return true1;
8778}
8779
8780void
8781proto_register_alias(const int proto_id, const char *alias_name)
8782{
8783 protocol_t *protocol;
8784
8785 protocol = find_protocol_by_id(proto_id);
8786 if (alias_name && protocol) {
8787 g_hash_table_insert(gpa_protocol_aliases, (void *) alias_name, (void *)protocol->filter_name);
8788 }
8789}
8790
8791/*
8792 * Routines to use to iterate over the protocols.
8793 * The argument passed to the iterator routines is an opaque cookie to
8794 * their callers; it's the GList pointer for the current element in
8795 * the list.
8796 * The ID of the protocol is returned, or -1 if there is no protocol.
8797 */
8798int
8799proto_get_first_protocol(void **cookie)
8800{
8801 protocol_t *protocol;
8802
8803 if (protocols == NULL((void*)0))
8804 return -1;
8805 *cookie = protocols;
8806 protocol = (protocol_t *)protocols->data;
8807 return protocol->proto_id;
8808}
8809
8810int
8811proto_get_data_protocol(void *cookie)
8812{
8813 GList *list_item = (GList *)cookie;
8814
8815 protocol_t *protocol = (protocol_t *)list_item->data;
8816 return protocol->proto_id;
8817}
8818
8819int
8820proto_get_next_protocol(void **cookie)
8821{
8822 GList *list_item = (GList *)*cookie;
8823 protocol_t *protocol;
8824
8825 list_item = g_list_next(list_item)((list_item) ? (((GList *)(list_item))->next) : ((void*)0)
)
;
8826 if (list_item == NULL((void*)0))
8827 return -1;
8828 *cookie = list_item;
8829 protocol = (protocol_t *)list_item->data;
8830 return protocol->proto_id;
8831}
8832
8833header_field_info *
8834proto_get_first_protocol_field(const int proto_id, void **cookie)
8835{
8836 protocol_t *protocol = find_protocol_by_id(proto_id);
8837
8838 if ((protocol == NULL((void*)0)) || (protocol->fields == NULL((void*)0)) || (protocol->fields->len == 0))
8839 return NULL((void*)0);
8840
8841 *cookie = GUINT_TO_POINTER(0)((gpointer) (gulong) (0));
8842 return (header_field_info *)g_ptr_array_index(protocol->fields, 0)((protocol->fields)->pdata)[0];
8843}
8844
8845header_field_info *
8846proto_get_next_protocol_field(const int proto_id, void **cookie)
8847{
8848 protocol_t *protocol = find_protocol_by_id(proto_id);
8849 unsigned i = GPOINTER_TO_UINT(*cookie)((guint) (gulong) (*cookie));
8850
8851 i++;
8852
8853 if ((protocol->fields == NULL((void*)0)) || (i >= protocol->fields->len))
8854 return NULL((void*)0);
8855
8856 *cookie = GUINT_TO_POINTER(i)((gpointer) (gulong) (i));
8857 return (header_field_info *)g_ptr_array_index(protocol->fields, i)((protocol->fields)->pdata)[i];
8858}
8859
8860protocol_t *
8861find_protocol_by_id(const int proto_id)
8862{
8863 header_field_info *hfinfo;
8864
8865 if (proto_id <= 0)
8866 return NULL((void*)0);
8867
8868 PROTO_REGISTRAR_GET_NTH(proto_id, hfinfo)if((proto_id == 0 || (unsigned)proto_id > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 8868, __func__, "Unregistered hf! index=%d"
, proto_id); ((void) ((proto_id > 0 && (unsigned)proto_id
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 8868,
"proto_id > 0 && (unsigned)proto_id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[proto_id]
!= ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 8868, "gpa_hfinfo.hfi[proto_id] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[proto_id];
;
8869 if (hfinfo->type != FT_PROTOCOL) {
8870 DISSECTOR_ASSERT(hfinfo->display & BASE_PROTOCOL_INFO)((void) ((hfinfo->display & 0x00004000) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 8870, "hfinfo->display & 0x00004000"
))))
;
8871 }
8872 return (protocol_t *)hfinfo->strings;
8873}
8874
8875int
8876proto_get_id(const protocol_t *protocol)
8877{
8878 return protocol->proto_id;
8879}
8880
8881bool_Bool
8882proto_name_already_registered(const char *name)
8883{
8884 DISSECTOR_ASSERT_HINT(name, "No name present")((void) ((name) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 8884, "name", "No name present"))))
;
8885
8886 if (g_hash_table_lookup(proto_names, name) != NULL((void*)0))
8887 return true1;
8888 return false0;
8889}
8890
8891int
8892proto_get_id_by_filter_name(const char *filter_name)
8893{
8894 const protocol_t *protocol = NULL((void*)0);
8895
8896 DISSECTOR_ASSERT_HINT(filter_name, "No filter name present")((void) ((filter_name) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 8896,
"filter_name", "No filter name present"))))
;
8897
8898 protocol = (const protocol_t *)g_hash_table_lookup(proto_filter_names, filter_name);
8899
8900 if (protocol == NULL((void*)0))
8901 return -1;
8902 return protocol->proto_id;
8903}
8904
8905int
8906proto_get_id_by_short_name(const char *short_name)
8907{
8908 const protocol_t *protocol = NULL((void*)0);
8909
8910 DISSECTOR_ASSERT_HINT(short_name, "No short name present")((void) ((short_name) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 8910,
"short_name", "No short name present"))))
;
8911
8912 protocol = (const protocol_t *)g_hash_table_lookup(proto_short_names, short_name);
8913
8914 if (protocol == NULL((void*)0))
8915 return -1;
8916 return protocol->proto_id;
8917}
8918
8919const char *
8920proto_get_protocol_name(const int proto_id)
8921{
8922 protocol_t *protocol;
8923
8924 protocol = find_protocol_by_id(proto_id);
8925
8926 if (protocol == NULL((void*)0))
8927 return NULL((void*)0);
8928 return protocol->name;
8929}
8930
8931const char *
8932proto_get_protocol_short_name(const protocol_t *protocol)
8933{
8934 if (protocol == NULL((void*)0))
8935 return "(none)";
8936 return protocol->short_name;
8937}
8938
8939const char *
8940proto_get_protocol_long_name(const protocol_t *protocol)
8941{
8942 if (protocol == NULL((void*)0))
8943 return "(none)";
8944 return protocol->name;
8945}
8946
8947const char *
8948proto_get_protocol_filter_name(const int proto_id)
8949{
8950 protocol_t *protocol;
8951
8952 protocol = find_protocol_by_id(proto_id);
8953 if (protocol == NULL((void*)0))
8954 return "(none)";
8955 return protocol->filter_name;
8956}
8957
8958void proto_add_heuristic_dissector(protocol_t *protocol, const char *short_name)
8959{
8960 heur_dtbl_entry_t* heuristic_dissector;
8961
8962 if (protocol == NULL((void*)0))
8963 return;
8964
8965 heuristic_dissector = find_heur_dissector_by_unique_short_name(short_name);
8966 if (heuristic_dissector != NULL((void*)0))
8967 {
8968 protocol->heur_list = g_list_prepend (protocol->heur_list, heuristic_dissector);
8969 }
8970}
8971
8972void proto_heuristic_dissector_foreach(const protocol_t *protocol, GFunc func, void *user_data)
8973{
8974 if (protocol == NULL((void*)0))
8975 return;
8976
8977 g_list_foreach(protocol->heur_list, func, user_data);
8978}
8979
8980void
8981proto_get_frame_protocols(const wmem_list_t *layers, bool_Bool *is_ip,
8982 bool_Bool *is_tcp, bool_Bool *is_udp,
8983 bool_Bool *is_sctp, bool_Bool *is_tls,
8984 bool_Bool *is_rtp,
8985 bool_Bool *is_lte_rlc)
8986{
8987 wmem_list_frame_t *protos = wmem_list_head(layers);
8988 int proto_id;
8989 const char *proto_name;
8990
8991 /* Walk the list of a available protocols in the packet and
8992 attempt to find "major" ones. */
8993 /* It might make more sense to assemble and return a bitfield. */
8994 while (protos != NULL((void*)0))
8995 {
8996 proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos))((gint) (glong) (wmem_list_frame_data(protos)));
8997 proto_name = proto_get_protocol_filter_name(proto_id);
8998
8999 if (is_ip && ((!strcmp(proto_name, "ip")) ||
9000 (!strcmp(proto_name, "ipv6")))) {
9001 *is_ip = true1;
9002 } else if (is_tcp && !strcmp(proto_name, "tcp")) {
9003 *is_tcp = true1;
9004 } else if (is_udp && !strcmp(proto_name, "udp")) {
9005 *is_udp = true1;
9006 } else if (is_sctp && !strcmp(proto_name, "sctp")) {
9007 *is_sctp = true1;
9008 } else if (is_tls && !strcmp(proto_name, "tls")) {
9009 *is_tls = true1;
9010 } else if (is_rtp && !strcmp(proto_name, "rtp")) {
9011 *is_rtp = true1;
9012 } else if (is_lte_rlc && (!strcmp(proto_name, "rlc-lte") || !strcmp(proto_name, "rlc-nr"))) {
9013 *is_lte_rlc = true1;
9014 }
9015
9016 protos = wmem_list_frame_next(protos);
9017 }
9018}
9019
9020bool_Bool
9021proto_is_frame_protocol(const wmem_list_t *layers, const char* proto_name)
9022{
9023 wmem_list_frame_t *protos = wmem_list_head(layers);
9024 int proto_id;
9025 const char *name;
9026
9027 /* Walk the list of a available protocols in the packet and
9028 attempt to find the specified protocol. */
9029 while (protos != NULL((void*)0))
9030 {
9031 proto_id = GPOINTER_TO_INT(wmem_list_frame_data(protos))((gint) (glong) (wmem_list_frame_data(protos)));
9032 name = proto_get_protocol_filter_name(proto_id);
9033
9034 if (!strcmp(name, proto_name))
9035 {
9036 return true1;
9037 }
9038
9039 protos = wmem_list_frame_next(protos);
9040 }
9041
9042 return false0;
9043}
9044
9045char *
9046proto_list_layers(const packet_info *pinfo)
9047{
9048 wmem_strbuf_t *buf;
9049 wmem_list_frame_t *layers = wmem_list_head(pinfo->layers);
9050
9051 buf = wmem_strbuf_new_sized(pinfo->pool, 128);
9052
9053 /* Walk the list of layers in the packet and
9054 return a string of all entries. */
9055 while (layers != NULL((void*)0))
9056 {
9057 wmem_strbuf_append(buf, proto_get_protocol_filter_name(GPOINTER_TO_UINT(wmem_list_frame_data(layers))((guint) (gulong) (wmem_list_frame_data(layers)))));
9058
9059 layers = wmem_list_frame_next(layers);
9060 if (layers != NULL((void*)0)) {
9061 wmem_strbuf_append_c(buf, ':');
9062 }
9063 }
9064
9065 return wmem_strbuf_finalize(buf);
9066}
9067
9068uint8_t
9069proto_get_layer_num(const packet_info *pinfo, const int proto_id)
9070{
9071 int *proto_layer_num_ptr;
9072
9073 proto_layer_num_ptr = wmem_map_lookup(pinfo->proto_layers, GINT_TO_POINTER(proto_id)((gpointer) (glong) (proto_id)));
9074 if (proto_layer_num_ptr == NULL((void*)0)) {
9075 return 0;
9076 }
9077
9078 return (uint8_t)*proto_layer_num_ptr;
9079}
9080
9081bool_Bool
9082proto_is_pino(const protocol_t *protocol)
9083{
9084 return (protocol->parent_proto_id != -1);
9085}
9086
9087const char*
9088proto_get_group_name(const protocol_t* protocol)
9089{
9090 if (protocol == NULL((void*)0))
9091 return 0;
9092 int group = register_get_group_from_filter_name(protocol->filter_name);
9093 return val_to_str_const(group, prot_group_vals, "Unknown");
9094}
9095
9096bool_Bool
9097proto_is_bytes_pino(const protocol_t *protocol)
9098{
9099 header_field_info *hfinfo;
9100
9101 if (!proto_is_pino(protocol))
9102 return false0;
9103
9104 PROTO_REGISTRAR_GET_NTH(protocol->proto_id, hfinfo)if((protocol->proto_id == 0 || (unsigned)protocol->proto_id
> gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 9104
, __func__, "Unregistered hf! index=%d", protocol->proto_id
); ((void) ((protocol->proto_id > 0 && (unsigned
)protocol->proto_id < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 9104,
"protocol->proto_id > 0 && (unsigned)protocol->proto_id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[protocol->
proto_id] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 9104,
"gpa_hfinfo.hfi[protocol->proto_id] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[protocol->proto_id];
;
9105 return hfinfo->type != FT_PROTOCOL;
9106}
9107
9108bool_Bool
9109// NOLINTNEXTLINE(misc-no-recursion)
9110proto_is_protocol_enabled(const protocol_t *protocol)
9111{
9112 if (protocol == NULL((void*)0))
9113 return false0;
9114
9115 //parent protocol determines enable/disable for helper dissectors
9116 if (proto_is_pino(protocol))
9117 return proto_is_protocol_enabled(find_protocol_by_id(protocol->parent_proto_id));
9118
9119 return protocol->is_enabled;
9120}
9121
9122bool_Bool
9123// NOLINTNEXTLINE(misc-no-recursion)
9124proto_is_protocol_enabled_by_default(const protocol_t *protocol)
9125{
9126 //parent protocol determines enable/disable for helper dissectors
9127 if (proto_is_pino(protocol))
9128 return proto_is_protocol_enabled_by_default(find_protocol_by_id(protocol->parent_proto_id));
9129
9130 return protocol->enabled_by_default;
9131}
9132
9133bool_Bool
9134// NOLINTNEXTLINE(misc-no-recursion)
9135proto_can_toggle_protocol(const int proto_id)
9136{
9137 protocol_t *protocol;
9138
9139 protocol = find_protocol_by_id(proto_id);
9140 //parent protocol determines toggling for helper dissectors
9141 if (proto_is_pino(protocol))
9142 return proto_can_toggle_protocol(protocol->parent_proto_id);
9143
9144 return protocol->can_toggle;
9145}
9146
9147void
9148proto_disable_by_default(const int proto_id)
9149{
9150 protocol_t *protocol;
9151
9152 protocol = find_protocol_by_id(proto_id);
9153 DISSECTOR_ASSERT(protocol->can_toggle)((void) ((protocol->can_toggle) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 9153, "protocol->can_toggle"
))))
;
9154 DISSECTOR_ASSERT(proto_is_pino(protocol) == false)((void) ((proto_is_pino(protocol) == 0) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 9154, "proto_is_pino(protocol) == 0"
))))
;
9155 protocol->is_enabled = false0;
9156 protocol->enabled_by_default = false0;
9157}
9158
9159void
9160proto_set_decoding(const int proto_id, const bool_Bool enabled)
9161{
9162 protocol_t *protocol;
9163
9164 protocol = find_protocol_by_id(proto_id);
9165 DISSECTOR_ASSERT(protocol->can_toggle)((void) ((protocol->can_toggle) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 9165, "protocol->can_toggle"
))))
;
9166 DISSECTOR_ASSERT(proto_is_pino(protocol) == false)((void) ((proto_is_pino(protocol) == 0) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 9166, "proto_is_pino(protocol) == 0"
))))
;
9167 protocol->is_enabled = enabled;
9168}
9169
9170void
9171proto_disable_all(void)
9172{
9173 /* This doesn't explicitly disable heuristic protocols,
9174 * but the heuristic doesn't get called if the parent
9175 * protocol isn't enabled.
9176 */
9177 protocol_t *protocol;
9178 GList *list_item = protocols;
9179
9180 if (protocols == NULL((void*)0))
9181 return;
9182
9183 while (list_item) {
9184 protocol = (protocol_t *)list_item->data;
9185 if (protocol->can_toggle) {
9186 protocol->is_enabled = false0;
9187 }
9188 list_item = g_list_next(list_item)((list_item) ? (((GList *)(list_item))->next) : ((void*)0)
)
;
9189 }
9190}
9191
9192static void
9193heur_reenable_cb(void *data, void *user_data _U___attribute__((unused)))
9194{
9195 heur_dtbl_entry_t *heur = (heur_dtbl_entry_t*)data;
9196
9197 heur->enabled = heur->enabled_by_default;
9198}
9199
9200void
9201proto_reenable_all(void)
9202{
9203 protocol_t *protocol;
9204 GList *list_item = protocols;
9205
9206 if (protocols == NULL((void*)0))
9207 return;
9208
9209 while (list_item) {
9210 protocol = (protocol_t *)list_item->data;
9211 if (protocol->can_toggle)
9212 protocol->is_enabled = protocol->enabled_by_default;
9213 proto_heuristic_dissector_foreach(protocol, heur_reenable_cb, NULL((void*)0));
9214 list_item = g_list_next(list_item)((list_item) ? (((GList *)(list_item))->next) : ((void*)0)
)
;
9215 }
9216}
9217
9218void
9219proto_set_cant_toggle(const int proto_id)
9220{
9221 protocol_t *protocol;
9222
9223 protocol = find_protocol_by_id(proto_id);
9224 protocol->can_toggle = false0;
9225}
9226
9227static int
9228proto_register_field_common(protocol_t *proto, header_field_info *hfi, const int parent)
9229{
9230 g_ptr_array_add(proto->fields, hfi);
9231
9232 return proto_register_field_init(hfi, parent);
9233}
9234
9235/* for use with static arrays only, since we don't allocate our own copies
9236of the header_field_info struct contained within the hf_register_info struct */
9237void
9238proto_register_field_array(const int parent, hf_register_info *hf, const int num_records)
9239{
9240 hf_register_info *ptr = hf;
9241 protocol_t *proto;
9242 int i;
9243
9244 proto = find_protocol_by_id(parent);
9245
9246 /* if (proto == NULL) - error or return? */
9247
9248 if (proto->fields == NULL((void*)0)) {
9249 /* Ironically, the NEW_PROTO_TREE_API was removed shortly before
9250 * GLib introduced g_ptr_array_new_from_array, which might have
9251 * given a reason to actually use it. (#17774)
9252 */
9253 proto->fields = g_ptr_array_sized_new(num_records);
9254 }
9255
9256 for (i = 0; i < num_records; i++, ptr++) {
9257 /*
9258 * Make sure we haven't registered this yet.
9259 * Most fields have variables associated with them that
9260 * are initialized to 0; some are initialized to -1 (which
9261 * was the standard before 4.4).
9262 *
9263 * XXX - Since this is called almost 300000 times at startup,
9264 * it might be nice to compare to only 0 and require
9265 * dissectors to pass in zero for unregistered fields.
9266 */
9267 if (*ptr->p_id != -1 && *ptr->p_id != 0) {
9268 REPORT_DISSECTOR_BUG(proto_report_dissector_bug("Duplicate field detected in call to proto_register_field_array: %s is already registered"
, ptr->hfinfo.abbrev)
9269 "Duplicate field detected in call to proto_register_field_array: %s is already registered",proto_report_dissector_bug("Duplicate field detected in call to proto_register_field_array: %s is already registered"
, ptr->hfinfo.abbrev)
9270 ptr->hfinfo.abbrev)proto_report_dissector_bug("Duplicate field detected in call to proto_register_field_array: %s is already registered"
, ptr->hfinfo.abbrev)
;
9271 return;
9272 }
9273
9274 *ptr->p_id = proto_register_field_common(proto, &ptr->hfinfo, parent);
9275 }
9276}
9277
9278/* deregister already registered fields */
9279void
9280proto_deregister_field (const int parent, int hf_id)
9281{
9282 header_field_info *hfi;
9283 protocol_t *proto;
9284 unsigned i;
9285
9286 g_free(last_field_name)(__builtin_object_size ((last_field_name), 0) != ((size_t) - 1
)) ? g_free_sized (last_field_name, __builtin_object_size ((last_field_name
), 0)) : (g_free) (last_field_name)
;
9287 last_field_name = NULL((void*)0);
9288
9289 if (hf_id == -1 || hf_id == 0)
9290 return;
9291
9292 proto = find_protocol_by_id (parent);
9293 if (!proto || proto->fields == NULL((void*)0)) {
9294 return;
9295 }
9296
9297 for (i = 0; i < proto->fields->len; i++) {
9298 hfi = (header_field_info *)g_ptr_array_index(proto->fields, i)((proto->fields)->pdata)[i];
9299 if (hfi->id == hf_id) {
9300 /* Found the hf_id in this protocol */
9301 wmem_map_remove(gpa_name_map, hfi->abbrev);
9302 g_ptr_array_remove_index_fast(proto->fields, i);
9303 g_ptr_array_add(deregistered_fields, gpa_hfinfo.hfi[hf_id]);
9304 return;
9305 }
9306 }
9307}
9308
9309/* Deregister all registered fields starting with a prefix. Use for dynamic registered fields only! */
9310void
9311proto_deregister_all_fields_with_prefix(const int parent, const char *prefix)
9312{
9313 header_field_info *hfinfo;
9314 protocol_t *proto;
9315
9316 g_free(last_field_name)(__builtin_object_size ((last_field_name), 0) != ((size_t) - 1
)) ? g_free_sized (last_field_name, __builtin_object_size ((last_field_name
), 0)) : (g_free) (last_field_name)
;
9317 last_field_name = NULL((void*)0);
9318
9319 proto = find_protocol_by_id(parent);
9320 if (proto && proto->fields && proto->fields->len > 0) {
9321 unsigned i = proto->fields->len;
9322 do {
9323 i--;
9324
9325 hfinfo = (header_field_info *)g_ptr_array_index(proto->fields, i)((proto->fields)->pdata)[i];
9326 if (g_str_has_prefix(hfinfo->abbrev, prefix)(__builtin_constant_p (prefix)? __extension__ ({ const char *
const __str = (hfinfo->abbrev); const char * const __prefix
= (prefix); gboolean __result = (0); if (__str == ((void*)0)
|| __prefix == ((void*)0)) __result = (g_str_has_prefix) (__str
, __prefix); else { const size_t __str_len = strlen (((__str)
+ !(__str))); const size_t __prefix_len = strlen (((__prefix
) + !(__prefix))); if (__str_len >= __prefix_len) __result
= memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len
) == 0; } __result; }) : (g_str_has_prefix) (hfinfo->abbrev
, prefix) )
) {
9327 hfinfo_remove_from_gpa_name_map(hfinfo);
9328 expert_deregister_expertinfo(hfinfo->abbrev);
9329 g_ptr_array_add(deregistered_fields, gpa_hfinfo.hfi[hfinfo->id]);
9330 g_ptr_array_remove_index_fast(proto->fields, i);
9331 }
9332 } while (i > 0);
9333 }
9334}
9335
9336void
9337proto_add_deregistered_data (void *data)
9338{
9339 g_ptr_array_add(deregistered_data, data);
9340}
9341
9342void
9343proto_add_deregistered_slice (size_t block_size, void *mem_block)
9344{
9345 struct g_slice_data *slice_data = g_slice_new(struct g_slice_data)((struct g_slice_data*) g_slice_alloc ((sizeof (struct g_slice_data
) > 0 ? sizeof (struct g_slice_data) : 1)))
;
9346
9347 slice_data->block_size = block_size;
9348 slice_data->mem_block = mem_block;
9349
9350 g_ptr_array_add(deregistered_slice, slice_data);
9351}
9352
9353void proto_free_field_strings (ftenum_t field_type, unsigned int field_display, const void *field_strings)
9354{
9355 if (field_strings == NULL((void*)0)) {
9356 return;
9357 }
9358
9359 switch (field_type) {
9360 case FT_FRAMENUM:
9361 /* This is just an integer represented as a pointer */
9362 break;
9363 case FT_PROTOCOL: {
9364 protocol_t *protocol = (protocol_t *)field_strings;
9365 g_free((char *)protocol->short_name)(__builtin_object_size (((char *)protocol->short_name), 0)
!= ((size_t) - 1)) ? g_free_sized ((char *)protocol->short_name
, __builtin_object_size (((char *)protocol->short_name), 0
)) : (g_free) ((char *)protocol->short_name)
;
9366 break;
9367 }
9368 case FT_BOOLEAN: {
9369 true_false_string *tf = (true_false_string *)field_strings;
9370 g_free((char *)tf->true_string)(__builtin_object_size (((char *)tf->true_string), 0) != (
(size_t) - 1)) ? g_free_sized ((char *)tf->true_string, __builtin_object_size
(((char *)tf->true_string), 0)) : (g_free) ((char *)tf->
true_string)
;
9371 g_free((char *)tf->false_string)(__builtin_object_size (((char *)tf->false_string), 0) != (
(size_t) - 1)) ? g_free_sized ((char *)tf->false_string, __builtin_object_size
(((char *)tf->false_string), 0)) : (g_free) ((char *)tf->
false_string)
;
9372 break;
9373 }
9374 case FT_UINT40:
9375 case FT_INT40:
9376 case FT_UINT48:
9377 case FT_INT48:
9378 case FT_UINT56:
9379 case FT_INT56:
9380 case FT_UINT64:
9381 case FT_INT64: {
9382 if (field_display & BASE_UNIT_STRING0x00001000) {
9383 unit_name_string *unit = (unit_name_string *)field_strings;
9384 g_free((char *)unit->singular)(__builtin_object_size (((char *)unit->singular), 0) != ((
size_t) - 1)) ? g_free_sized ((char *)unit->singular, __builtin_object_size
(((char *)unit->singular), 0)) : (g_free) ((char *)unit->
singular)
;
9385 g_free((char *)unit->plural)(__builtin_object_size (((char *)unit->plural), 0) != ((size_t
) - 1)) ? g_free_sized ((char *)unit->plural, __builtin_object_size
(((char *)unit->plural), 0)) : (g_free) ((char *)unit->
plural)
;
9386 } else if (field_display & BASE_RANGE_STRING0x00000100) {
9387 range_string *rs = (range_string *)field_strings;
9388 while (rs->strptr) {
9389 g_free((char *)rs->strptr)(__builtin_object_size (((char *)rs->strptr), 0) != ((size_t
) - 1)) ? g_free_sized ((char *)rs->strptr, __builtin_object_size
(((char *)rs->strptr), 0)) : (g_free) ((char *)rs->strptr
)
;
9390 rs++;
9391 }
9392 } else if (field_display & BASE_EXT_STRING0x00000200) {
9393 val64_string_ext *vse = (val64_string_ext *)field_strings;
9394 val64_string *vs = (val64_string *)vse->_vs_p;
9395 while (vs->strptr) {
9396 g_free((char *)vs->strptr)(__builtin_object_size (((char *)vs->strptr), 0) != ((size_t
) - 1)) ? g_free_sized ((char *)vs->strptr, __builtin_object_size
(((char *)vs->strptr), 0)) : (g_free) ((char *)vs->strptr
)
;
9397 vs++;
9398 }
9399 val64_string_ext_free(vse);
9400 field_strings = NULL((void*)0);
9401 } else if (field_display == BASE_CUSTOM) {
9402 /* this will be a pointer to a function, don't free that */
9403 field_strings = NULL((void*)0);
9404 } else {
9405 val64_string *vs64 = (val64_string *)field_strings;
9406 while (vs64->strptr) {
9407 g_free((char *)vs64->strptr)(__builtin_object_size (((char *)vs64->strptr), 0) != ((size_t
) - 1)) ? g_free_sized ((char *)vs64->strptr, __builtin_object_size
(((char *)vs64->strptr), 0)) : (g_free) ((char *)vs64->
strptr)
;
9408 vs64++;
9409 }
9410 }
9411 break;
9412 }
9413 case FT_CHAR:
9414 case FT_UINT8:
9415 case FT_INT8:
9416 case FT_UINT16:
9417 case FT_INT16:
9418 case FT_UINT24:
9419 case FT_INT24:
9420 case FT_UINT32:
9421 case FT_INT32:
9422 case FT_FLOAT:
9423 case FT_DOUBLE: {
9424 if (field_display & BASE_UNIT_STRING0x00001000) {
9425 unit_name_string *unit = (unit_name_string *)field_strings;
9426 g_free((char *)unit->singular)(__builtin_object_size (((char *)unit->singular), 0) != ((
size_t) - 1)) ? g_free_sized ((char *)unit->singular, __builtin_object_size
(((char *)unit->singular), 0)) : (g_free) ((char *)unit->
singular)
;
9427 g_free((char *)unit->plural)(__builtin_object_size (((char *)unit->plural), 0) != ((size_t
) - 1)) ? g_free_sized ((char *)unit->plural, __builtin_object_size
(((char *)unit->plural), 0)) : (g_free) ((char *)unit->
plural)
;
9428 } else if (field_display & BASE_RANGE_STRING0x00000100) {
9429 range_string *rs = (range_string *)field_strings;
9430 while (rs->strptr) {
9431 g_free((char *)rs->strptr)(__builtin_object_size (((char *)rs->strptr), 0) != ((size_t
) - 1)) ? g_free_sized ((char *)rs->strptr, __builtin_object_size
(((char *)rs->strptr), 0)) : (g_free) ((char *)rs->strptr
)
;
9432 rs++;
9433 }
9434 } else if (field_display & BASE_EXT_STRING0x00000200) {
9435 value_string_ext *vse = (value_string_ext *)field_strings;
9436 value_string *vs = (value_string *)vse->_vs_p;
9437 while (vs->strptr) {
9438 g_free((char *)vs->strptr)(__builtin_object_size (((char *)vs->strptr), 0) != ((size_t
) - 1)) ? g_free_sized ((char *)vs->strptr, __builtin_object_size
(((char *)vs->strptr), 0)) : (g_free) ((char *)vs->strptr
)
;
9439 vs++;
9440 }
9441 value_string_ext_free(vse);
9442 field_strings = NULL((void*)0);
9443 } else if (field_display == BASE_CUSTOM) {
9444 /* this will be a pointer to a function, don't free that */
9445 field_strings = NULL((void*)0);
9446 } else {
9447 value_string *vs = (value_string *)field_strings;
9448 while (vs->strptr) {
9449 g_free((char *)vs->strptr)(__builtin_object_size (((char *)vs->strptr), 0) != ((size_t
) - 1)) ? g_free_sized ((char *)vs->strptr, __builtin_object_size
(((char *)vs->strptr), 0)) : (g_free) ((char *)vs->strptr
)
;
9450 vs++;
9451 }
9452 }
9453 break;
9454 default:
9455 break;
9456 }
9457 }
9458
9459 if (field_type != FT_FRAMENUM) {
9460 g_free((void *)field_strings)(__builtin_object_size (((void *)field_strings), 0) != ((size_t
) - 1)) ? g_free_sized ((void *)field_strings, __builtin_object_size
(((void *)field_strings), 0)) : (g_free) ((void *)field_strings
)
;
9461 }
9462}
9463
9464static void
9465free_deregistered_field (void *data, void *user_data _U___attribute__((unused)))
9466{
9467 header_field_info *hfi = (header_field_info *) data;
9468 int hf_id = hfi->id;
9469
9470 g_free((char *)hfi->name)(__builtin_object_size (((char *)hfi->name), 0) != ((size_t
) - 1)) ? g_free_sized ((char *)hfi->name, __builtin_object_size
(((char *)hfi->name), 0)) : (g_free) ((char *)hfi->name
)
;
9471 g_free((char *)hfi->abbrev)(__builtin_object_size (((char *)hfi->abbrev), 0) != ((size_t
) - 1)) ? g_free_sized ((char *)hfi->abbrev, __builtin_object_size
(((char *)hfi->abbrev), 0)) : (g_free) ((char *)hfi->abbrev
)
;
9472 g_free((char *)hfi->blurb)(__builtin_object_size (((char *)hfi->blurb), 0) != ((size_t
) - 1)) ? g_free_sized ((char *)hfi->blurb, __builtin_object_size
(((char *)hfi->blurb), 0)) : (g_free) ((char *)hfi->blurb
)
;
9473
9474 proto_free_field_strings(hfi->type, hfi->display, hfi->strings);
9475
9476 if (hfi->parent == -1)
9477 g_slice_free(header_field_info, hfi)do { if (1) g_slice_free1 (sizeof (header_field_info), (hfi))
; else (void) ((header_field_info*) 0 == (hfi)); } while (0)
;
9478
9479 gpa_hfinfo.hfi[hf_id] = NULL((void*)0); /* Invalidate this hf_id / proto_id */
9480}
9481
9482static void
9483free_deregistered_data (void *data, void *user_data _U___attribute__((unused)))
9484{
9485 g_free (data)(__builtin_object_size ((data), 0) != ((size_t) - 1)) ? g_free_sized
(data, __builtin_object_size ((data), 0)) : (g_free) (data)
;
9486}
9487
9488static void
9489free_deregistered_slice (void *data, void *user_data _U___attribute__((unused)))
9490{
9491 struct g_slice_data *slice_data = (struct g_slice_data *)data;
9492
9493 g_slice_free1(slice_data->block_size, slice_data->mem_block);
9494 g_slice_free(struct g_slice_data, slice_data)do { if (1) g_slice_free1 (sizeof (struct g_slice_data), (slice_data
)); else (void) ((struct g_slice_data*) 0 == (slice_data)); }
while (0)
;
9495}
9496
9497/* free deregistered fields and data */
9498void
9499proto_free_deregistered_fields (void)
9500{
9501 expert_free_deregistered_expertinfos();
9502
9503 g_ptr_array_foreach(deregistered_fields, free_deregistered_field, NULL((void*)0));
9504 g_ptr_array_free(deregistered_fields, true1);
9505 deregistered_fields = g_ptr_array_new();
9506
9507 g_ptr_array_foreach(deregistered_data, free_deregistered_data, NULL((void*)0));
9508 g_ptr_array_free(deregistered_data, true1);
9509 deregistered_data = g_ptr_array_new();
9510
9511 g_ptr_array_foreach(deregistered_slice, free_deregistered_slice, NULL((void*)0));
9512 g_ptr_array_free(deregistered_slice, true1);
9513 deregistered_slice = g_ptr_array_new();
9514}
9515
9516static const value_string hf_display[] = {
9517 { BASE_NONE, "BASE_NONE" },
9518 { BASE_DEC, "BASE_DEC" },
9519 { BASE_HEX, "BASE_HEX" },
9520 { BASE_OCT, "BASE_OCT" },
9521 { BASE_DEC_HEX, "BASE_DEC_HEX" },
9522 { BASE_HEX_DEC, "BASE_HEX_DEC" },
9523 { BASE_CUSTOM, "BASE_CUSTOM" },
9524 { BASE_NONE|BASE_RANGE_STRING0x00000100, "BASE_NONE|BASE_RANGE_STRING" },
9525 { BASE_DEC|BASE_RANGE_STRING0x00000100, "BASE_DEC|BASE_RANGE_STRING" },
9526 { BASE_HEX|BASE_RANGE_STRING0x00000100, "BASE_HEX|BASE_RANGE_STRING" },
9527 { BASE_OCT|BASE_RANGE_STRING0x00000100, "BASE_OCT|BASE_RANGE_STRING" },
9528 { BASE_DEC_HEX|BASE_RANGE_STRING0x00000100, "BASE_DEC_HEX|BASE_RANGE_STRING" },
9529 { BASE_HEX_DEC|BASE_RANGE_STRING0x00000100, "BASE_HEX_DEC|BASE_RANGE_STRING" },
9530 { BASE_CUSTOM|BASE_RANGE_STRING0x00000100, "BASE_CUSTOM|BASE_RANGE_STRING" },
9531 { BASE_NONE|BASE_VAL64_STRING0x00000400, "BASE_NONE|BASE_VAL64_STRING" },
9532 { BASE_DEC|BASE_VAL64_STRING0x00000400, "BASE_DEC|BASE_VAL64_STRING" },
9533 { BASE_HEX|BASE_VAL64_STRING0x00000400, "BASE_HEX|BASE_VAL64_STRING" },
9534 { BASE_OCT|BASE_VAL64_STRING0x00000400, "BASE_OCT|BASE_VAL64_STRING" },
9535 { BASE_DEC_HEX|BASE_VAL64_STRING0x00000400, "BASE_DEC_HEX|BASE_VAL64_STRING" },
9536 { BASE_HEX_DEC|BASE_VAL64_STRING0x00000400, "BASE_HEX_DEC|BASE_VAL64_STRING" },
9537 { BASE_CUSTOM|BASE_VAL64_STRING0x00000400, "BASE_CUSTOM|BASE_VAL64_STRING" },
9538 { ABSOLUTE_TIME_LOCAL, "ABSOLUTE_TIME_LOCAL" },
9539 { ABSOLUTE_TIME_UTC, "ABSOLUTE_TIME_UTC" },
9540 { ABSOLUTE_TIME_DOY_UTC, "ABSOLUTE_TIME_DOY_UTC" },
9541 { BASE_PT_UDP, "BASE_PT_UDP" },
9542 { BASE_PT_TCP, "BASE_PT_TCP" },
9543 { BASE_PT_DCCP, "BASE_PT_DCCP" },
9544 { BASE_PT_SCTP, "BASE_PT_SCTP" },
9545 { BASE_OUI, "BASE_OUI" },
9546 { 0, NULL((void*)0) } };
9547
9548const char* proto_field_display_to_string(int field_display)
9549{
9550 return val_to_str_const(field_display, hf_display, "Unknown");
9551}
9552
9553static inline port_type
9554display_to_port_type(field_display_e e)
9555{
9556 switch (e) {
9557 case BASE_PT_UDP:
9558 return PT_UDP;
9559 case BASE_PT_TCP:
9560 return PT_TCP;
9561 case BASE_PT_DCCP:
9562 return PT_DCCP;
9563 case BASE_PT_SCTP:
9564 return PT_SCTP;
9565 default:
9566 break;
9567 }
9568 return PT_NONE;
9569}
9570
9571/* temporary function containing assert part for easier profiling */
9572static void
9573tmp_fld_check_assert(header_field_info *hfinfo)
9574{
9575 char* tmp_str;
9576
9577 /* The field must have a name (with length > 0) */
9578 if (!hfinfo->name || !hfinfo->name[0]) {
9579 if (hfinfo->abbrev)
9580 /* Try to identify the field */
9581 REPORT_DISSECTOR_BUG("Field (abbrev='%s') does not have a name",proto_report_dissector_bug("Field (abbrev='%s') does not have a name"
, hfinfo->abbrev)
9582 hfinfo->abbrev)proto_report_dissector_bug("Field (abbrev='%s') does not have a name"
, hfinfo->abbrev)
;
9583 else
9584 /* Hum, no luck */
9585 REPORT_DISSECTOR_BUG("Field does not have a name (nor an abbreviation)")proto_report_dissector_bug("Field does not have a name (nor an abbreviation)"
)
;
9586 }
9587
9588 /* fields with an empty string for an abbreviation aren't filterable */
9589 if (!hfinfo->abbrev || !hfinfo->abbrev[0])
9590 REPORT_DISSECTOR_BUG("Field '%s' does not have an abbreviation", hfinfo->name)proto_report_dissector_bug("Field '%s' does not have an abbreviation"
, hfinfo->name)
;
9591
9592 /* TODO: This check is a significant percentage of startup time (~10%),
9593 although not nearly as slow as what's enabled by ENABLE_CHECK_FILTER.
9594 It might be nice to have a way to disable this check when, e.g.,
9595 running TShark many times with the same configuration. */
9596 /* Check that the filter name (abbreviation) is legal;
9597 * it must contain only alphanumerics, '-', "_", and ".". */
9598 unsigned char c;
9599 c = module_check_valid_name(hfinfo->abbrev, false0);
9600 if (c) {
9601 if (c == '.') {
9602 REPORT_DISSECTOR_BUG("Invalid leading, duplicated or trailing '.' found in filter name '%s'", hfinfo->abbrev)proto_report_dissector_bug("Invalid leading, duplicated or trailing '.' found in filter name '%s'"
, hfinfo->abbrev)
;
9603 } else if (g_ascii_isprint(c)((g_ascii_table[(guchar) (c)] & G_ASCII_PRINT) != 0)) {
9604 REPORT_DISSECTOR_BUG("Invalid character '%c' in filter name '%s'", c, hfinfo->abbrev)proto_report_dissector_bug("Invalid character '%c' in filter name '%s'"
, c, hfinfo->abbrev)
;
9605 } else {
9606 REPORT_DISSECTOR_BUG("Invalid byte \\%03o in filter name '%s'", c, hfinfo->abbrev)proto_report_dissector_bug("Invalid byte \\%03o in filter name '%s'"
, c, hfinfo->abbrev)
;
9607 }
9608 }
9609
9610 /* These types of fields are allowed to have value_strings,
9611 * true_false_strings or a protocol_t struct
9612 */
9613 if (hfinfo->strings != NULL((void*)0) && FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF) != BASE_CUSTOM) {
9614 switch (hfinfo->type) {
9615
9616 /*
9617 * These types are allowed to support display value_strings,
9618 * value64_strings, the extended versions of the previous
9619 * two, range strings, or unit strings.
9620 */
9621 case FT_CHAR:
9622 case FT_UINT8:
9623 case FT_UINT16:
9624 case FT_UINT24:
9625 case FT_UINT32:
9626 case FT_UINT40:
9627 case FT_UINT48:
9628 case FT_UINT56:
9629 case FT_UINT64:
9630 case FT_INT8:
9631 case FT_INT16:
9632 case FT_INT24:
9633 case FT_INT32:
9634 case FT_INT40:
9635 case FT_INT48:
9636 case FT_INT56:
9637 case FT_INT64:
9638 case FT_BOOLEAN:
9639 case FT_PROTOCOL:
9640 break;
9641
9642 /*
9643 * This is allowed to have a value of type
9644 * enum ft_framenum_type to indicate what relationship
9645 * the frame in question has to the frame in which
9646 * the field is put.
9647 */
9648 case FT_FRAMENUM:
9649 break;
9650
9651 /*
9652 * These types are allowed to support only unit strings.
9653 */
9654 case FT_FLOAT:
9655 case FT_DOUBLE:
9656 case FT_IEEE_11073_SFLOAT:
9657 case FT_IEEE_11073_FLOAT:
9658 if (!(hfinfo->display & BASE_UNIT_STRING0x00001000)) {
9659 REPORT_DISSECTOR_BUG("Field '%s' (%s) has a non-unit-strings 'strings' value but is of type %s"proto_report_dissector_bug("Field '%s' (%s) has a non-unit-strings 'strings' value but is of type %s"
" (which is only allowed to have unit strings)", hfinfo->
name, hfinfo->abbrev, ftype_name(hfinfo->type))
9660 " (which is only allowed to have unit strings)",proto_report_dissector_bug("Field '%s' (%s) has a non-unit-strings 'strings' value but is of type %s"
" (which is only allowed to have unit strings)", hfinfo->
name, hfinfo->abbrev, ftype_name(hfinfo->type))
9661 hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) has a non-unit-strings 'strings' value but is of type %s"
" (which is only allowed to have unit strings)", hfinfo->
name, hfinfo->abbrev, ftype_name(hfinfo->type))
;
9662 }
9663 break;
9664
9665 /*
9666 * These types are allowed to support display
9667 * time_value_strings.
9668 */
9669 case FT_ABSOLUTE_TIME:
9670 if (hfinfo->display & BASE_RANGE_STRING0x00000100 ||
9671 hfinfo->display & BASE_EXT_STRING0x00000200 ||
9672 hfinfo->display & BASE_VAL64_STRING0x00000400 ||
9673 hfinfo->display & BASE_UNIT_STRING0x00001000) {
9674 REPORT_DISSECTOR_BUG("Field '%s' (%s) has a non-time-value-strings 'strings' value but is of type %s"proto_report_dissector_bug("Field '%s' (%s) has a non-time-value-strings 'strings' value but is of type %s"
" (which is only allowed to have time-value strings)", hfinfo
->name, hfinfo->abbrev, ftype_name(hfinfo->type))
9675 " (which is only allowed to have time-value strings)",proto_report_dissector_bug("Field '%s' (%s) has a non-time-value-strings 'strings' value but is of type %s"
" (which is only allowed to have time-value strings)", hfinfo
->name, hfinfo->abbrev, ftype_name(hfinfo->type))
9676 hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) has a non-time-value-strings 'strings' value but is of type %s"
" (which is only allowed to have time-value strings)", hfinfo
->name, hfinfo->abbrev, ftype_name(hfinfo->type))
;
9677 }
9678 break;
9679
9680 /*
9681 * This type is only allowed to support a string if it's
9682 * a protocol (for pinos).
9683 */
9684 case FT_BYTES:
9685 if (!(hfinfo->display & BASE_PROTOCOL_INFO0x00004000)) {
9686 REPORT_DISSECTOR_BUG("Field '%s' (%s) has a non-protocol-info 'strings' value but is of type %s"proto_report_dissector_bug("Field '%s' (%s) has a non-protocol-info 'strings' value but is of type %s"
" (which is only allowed to have protocol-info strings)", hfinfo
->name, hfinfo->abbrev, ftype_name(hfinfo->type))
9687 " (which is only allowed to have protocol-info strings)",proto_report_dissector_bug("Field '%s' (%s) has a non-protocol-info 'strings' value but is of type %s"
" (which is only allowed to have protocol-info strings)", hfinfo
->name, hfinfo->abbrev, ftype_name(hfinfo->type))
9688 hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) has a non-protocol-info 'strings' value but is of type %s"
" (which is only allowed to have protocol-info strings)", hfinfo
->name, hfinfo->abbrev, ftype_name(hfinfo->type))
;
9689 }
9690 break;
9691
9692 default:
9693 REPORT_DISSECTOR_BUG("Field '%s' (%s) has a 'strings' value but is of type %s"proto_report_dissector_bug("Field '%s' (%s) has a 'strings' value but is of type %s"
" (which is not allowed to have strings)", hfinfo->name, hfinfo
->abbrev, ftype_name(hfinfo->type))
9694 " (which is not allowed to have strings)",proto_report_dissector_bug("Field '%s' (%s) has a 'strings' value but is of type %s"
" (which is not allowed to have strings)", hfinfo->name, hfinfo
->abbrev, ftype_name(hfinfo->type))
9695 hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) has a 'strings' value but is of type %s"
" (which is not allowed to have strings)", hfinfo->name, hfinfo
->abbrev, ftype_name(hfinfo->type))
;
9696 }
9697 }
9698
9699 /* TODO: This check may slow down startup, and output quite a few warnings.
9700 It would be good to be able to enable this (and possibly other checks?)
9701 in non-release builds. */
9702#ifdef ENABLE_CHECK_FILTER
9703 /* Check for duplicate value_string values.
9704 There are lots that have the same value *and* string, so for now only
9705 report those that have same value but different string. */
9706 if ((hfinfo->strings != NULL((void*)0)) &&
9707 !(hfinfo->display & BASE_RANGE_STRING0x00000100) &&
9708 !(hfinfo->display & BASE_UNIT_STRING0x00001000) &&
9709 !((hfinfo->display & FIELD_DISPLAY_E_MASK0xFF) == BASE_CUSTOM) &&
9710 (
9711 (hfinfo->type == FT_CHAR) ||
9712 (hfinfo->type == FT_UINT8) ||
9713 (hfinfo->type == FT_UINT16) ||
9714 (hfinfo->type == FT_UINT24) ||
9715 (hfinfo->type == FT_UINT32) ||
9716 (hfinfo->type == FT_INT8) ||
9717 (hfinfo->type == FT_INT16) ||
9718 (hfinfo->type == FT_INT24) ||
9719 (hfinfo->type == FT_INT32) )) {
9720
9721 if (hfinfo->display & BASE_EXT_STRING0x00000200) {
9722 if (hfinfo->display & BASE_VAL64_STRING0x00000400) {
9723 const val64_string *start_values = VAL64_STRING_EXT_VS_P((const val64_string_ext*)hfinfo->strings)((const val64_string_ext*)hfinfo->strings)->_vs_p;
9724 CHECK_HF_VALUE(val64_string, PRIu64"l" "u", start_values);
9725 } else {
9726 const value_string *start_values = VALUE_STRING_EXT_VS_P((const value_string_ext*)hfinfo->strings)((const value_string_ext*)hfinfo->strings)->_vs_p;
9727 CHECK_HF_VALUE(value_string, "u", start_values);
9728 }
9729 } else {
9730 const value_string *start_values = (const value_string*)hfinfo->strings;
9731 CHECK_HF_VALUE(value_string, "u", start_values);
9732 }
9733 }
9734
9735 if (hfinfo->type == FT_BOOLEAN) {
9736 const true_false_string *tfs = (const true_false_string*)hfinfo->strings;
9737 if (tfs) {
9738 if (strcmp(tfs->false_string, tfs->true_string) == 0) {
9739 ws_error("Field '%s' (%s) has identical true and false strings (\"%s\", \"%s\")",ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 9741
, __func__, "Field '%s' (%s) has identical true and false strings (\"%s\", \"%s\")"
, hfinfo->name, hfinfo->abbrev, tfs->false_string, tfs
->true_string)
9740 hfinfo->name, hfinfo->abbrev,ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 9741
, __func__, "Field '%s' (%s) has identical true and false strings (\"%s\", \"%s\")"
, hfinfo->name, hfinfo->abbrev, tfs->false_string, tfs
->true_string)
9741 tfs->false_string, tfs->true_string)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 9741
, __func__, "Field '%s' (%s) has identical true and false strings (\"%s\", \"%s\")"
, hfinfo->name, hfinfo->abbrev, tfs->false_string, tfs
->true_string)
;
9742 }
9743 }
9744 }
9745
9746 if (hfinfo->display & BASE_RANGE_STRING0x00000100) {
9747 const range_string *rs = (const range_string*)(hfinfo->strings);
9748 if (rs) {
9749 const range_string *this_it = rs;
9750
9751 do {
9752 if (this_it->value_max < this_it->value_min) {
9753 ws_warning("value_range_string error: %s (%s) entry for \"%s\" - max(%"PRIu64" 0x%"PRIx64") is less than min(%"PRIu64" 0x%"PRIx64")",do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 9757, __func__, "value_range_string error: %s (%s) entry for \"%s\" - max(%"
"l" "u"" 0x%""l" "x"") is less than min(%""l" "u"" 0x%""l" "x"
")", hfinfo->name, hfinfo->abbrev, this_it->strptr, this_it
->value_max, this_it->value_max, this_it->value_min,
this_it->value_min); } } while (0)
9754 hfinfo->name, hfinfo->abbrev,do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 9757, __func__, "value_range_string error: %s (%s) entry for \"%s\" - max(%"
"l" "u"" 0x%""l" "x"") is less than min(%""l" "u"" 0x%""l" "x"
")", hfinfo->name, hfinfo->abbrev, this_it->strptr, this_it
->value_max, this_it->value_max, this_it->value_min,
this_it->value_min); } } while (0)
9755 this_it->strptr,do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 9757, __func__, "value_range_string error: %s (%s) entry for \"%s\" - max(%"
"l" "u"" 0x%""l" "x"") is less than min(%""l" "u"" 0x%""l" "x"
")", hfinfo->name, hfinfo->abbrev, this_it->strptr, this_it
->value_max, this_it->value_max, this_it->value_min,
this_it->value_min); } } while (0)
9756 this_it->value_max, this_it->value_max,do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 9757, __func__, "value_range_string error: %s (%s) entry for \"%s\" - max(%"
"l" "u"" 0x%""l" "x"") is less than min(%""l" "u"" 0x%""l" "x"
")", hfinfo->name, hfinfo->abbrev, this_it->strptr, this_it
->value_max, this_it->value_max, this_it->value_min,
this_it->value_min); } } while (0)
9757 this_it->value_min, this_it->value_min)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 9757, __func__, "value_range_string error: %s (%s) entry for \"%s\" - max(%"
"l" "u"" 0x%""l" "x"") is less than min(%""l" "u"" 0x%""l" "x"
")", hfinfo->name, hfinfo->abbrev, this_it->strptr, this_it
->value_max, this_it->value_max, this_it->value_min,
this_it->value_min); } } while (0)
;
9758 ++this_it;
9759 continue;
9760 }
9761
9762 for (const range_string *prev_it=rs; prev_it < this_it; ++prev_it) {
9763 /* Not OK if this one is completely hidden by an earlier one! */
9764 if ((prev_it->value_min <= this_it->value_min) && (prev_it->value_max >= this_it->value_max)) {
9765 ws_warning("value_range_string error: %s (%s) hidden by earlier entry "do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 9771, __func__, "value_range_string error: %s (%s) hidden by earlier entry "
"(prev=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l" "u"" 0x%"
"l" "x"") (this=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l"
"u"" 0x%""l" "x"")", hfinfo->name, hfinfo->abbrev, prev_it
->strptr, prev_it->value_min, prev_it->value_min, prev_it
->value_max, prev_it->value_max, this_it->strptr, this_it
->value_min, this_it->value_min, this_it->value_max,
this_it->value_max); } } while (0)
9766 "(prev=\"%s\": %"PRIu64" 0x%"PRIx64" -> %"PRIu64" 0x%"PRIx64") (this=\"%s\": %"PRIu64" 0x%"PRIx64" -> %"PRIu64" 0x%"PRIx64")",do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 9771, __func__, "value_range_string error: %s (%s) hidden by earlier entry "
"(prev=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l" "u"" 0x%"
"l" "x"") (this=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l"
"u"" 0x%""l" "x"")", hfinfo->name, hfinfo->abbrev, prev_it
->strptr, prev_it->value_min, prev_it->value_min, prev_it
->value_max, prev_it->value_max, this_it->strptr, this_it
->value_min, this_it->value_min, this_it->value_max,
this_it->value_max); } } while (0)
9767 hfinfo->name, hfinfo->abbrev,do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 9771, __func__, "value_range_string error: %s (%s) hidden by earlier entry "
"(prev=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l" "u"" 0x%"
"l" "x"") (this=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l"
"u"" 0x%""l" "x"")", hfinfo->name, hfinfo->abbrev, prev_it
->strptr, prev_it->value_min, prev_it->value_min, prev_it
->value_max, prev_it->value_max, this_it->strptr, this_it
->value_min, this_it->value_min, this_it->value_max,
this_it->value_max); } } while (0)
9768 prev_it->strptr, prev_it->value_min, prev_it->value_min,do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 9771, __func__, "value_range_string error: %s (%s) hidden by earlier entry "
"(prev=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l" "u"" 0x%"
"l" "x"") (this=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l"
"u"" 0x%""l" "x"")", hfinfo->name, hfinfo->abbrev, prev_it
->strptr, prev_it->value_min, prev_it->value_min, prev_it
->value_max, prev_it->value_max, this_it->strptr, this_it
->value_min, this_it->value_min, this_it->value_max,
this_it->value_max); } } while (0)
9769 prev_it->value_max, prev_it->value_max,do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 9771, __func__, "value_range_string error: %s (%s) hidden by earlier entry "
"(prev=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l" "u"" 0x%"
"l" "x"") (this=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l"
"u"" 0x%""l" "x"")", hfinfo->name, hfinfo->abbrev, prev_it
->strptr, prev_it->value_min, prev_it->value_min, prev_it
->value_max, prev_it->value_max, this_it->strptr, this_it
->value_min, this_it->value_min, this_it->value_max,
this_it->value_max); } } while (0)
9770 this_it->strptr, this_it->value_min, this_it->value_min,do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 9771, __func__, "value_range_string error: %s (%s) hidden by earlier entry "
"(prev=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l" "u"" 0x%"
"l" "x"") (this=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l"
"u"" 0x%""l" "x"")", hfinfo->name, hfinfo->abbrev, prev_it
->strptr, prev_it->value_min, prev_it->value_min, prev_it
->value_max, prev_it->value_max, this_it->strptr, this_it
->value_min, this_it->value_min, this_it->value_max,
this_it->value_max); } } while (0)
9771 this_it->value_max, this_it->value_max)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 9771, __func__, "value_range_string error: %s (%s) hidden by earlier entry "
"(prev=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l" "u"" 0x%"
"l" "x"") (this=\"%s\": %""l" "u"" 0x%""l" "x"" -> %""l"
"u"" 0x%""l" "x"")", hfinfo->name, hfinfo->abbrev, prev_it
->strptr, prev_it->value_min, prev_it->value_min, prev_it
->value_max, prev_it->value_max, this_it->strptr, this_it
->value_min, this_it->value_min, this_it->value_max,
this_it->value_max); } } while (0)
;
9772 }
9773 }
9774 ++this_it;
9775 } while (this_it->strptr);
9776 }
9777 }
9778#endif
9779
9780 switch (hfinfo->type) {
9781
9782 case FT_CHAR:
9783 /* Require the char type to have BASE_HEX, BASE_OCT,
9784 * BASE_CUSTOM, or BASE_NONE as its base.
9785 *
9786 * If the display value is BASE_NONE and there is a
9787 * strings conversion then the dissector writer is
9788 * telling us that the field's numerical value is
9789 * meaningless; we'll avoid showing the value to the
9790 * user.
9791 */
9792 switch (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF)) {
9793 case BASE_HEX:
9794 case BASE_OCT:
9795 case BASE_CUSTOM: /* hfinfo_numeric_value_format() treats this as decimal */
9796 break;
9797 case BASE_NONE:
9798 if (hfinfo->strings == NULL((void*)0))
9799 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an integral value (%s)"proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as BASE_NONE but" " without a strings conversion"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9800 " but is being displayed as BASE_NONE but"proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as BASE_NONE but" " without a strings conversion"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9801 " without a strings conversion",proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as BASE_NONE but" " without a strings conversion"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9802 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as BASE_NONE but" " without a strings conversion"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9803 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as BASE_NONE but" " without a strings conversion"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
9804 break;
9805 default:
9806 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Unknown: 0x%x)");
9807 REPORT_DISSECTOR_BUG("Field '%s' (%s) is a character value (%s)"proto_report_dissector_bug("Field '%s' (%s) is a character value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
9808 " but is being displayed as %s",proto_report_dissector_bug("Field '%s' (%s) is a character value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
9809 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is a character value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
9810 ftype_name(hfinfo->type), tmp_str)proto_report_dissector_bug("Field '%s' (%s) is a character value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
;
9811 //wmem_free(NULL, tmp_str);
9812 }
9813 if (hfinfo->display & BASE_UNIT_STRING0x00001000) {
9814 REPORT_DISSECTOR_BUG("Field '%s' (%s) is a character value (%s) but has a unit string",proto_report_dissector_bug("Field '%s' (%s) is a character value (%s) but has a unit string"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9815 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is a character value (%s) but has a unit string"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9816 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is a character value (%s) but has a unit string"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
9817 }
9818 break;
9819 case FT_INT8:
9820 case FT_INT16:
9821 case FT_INT24:
9822 case FT_INT32:
9823 case FT_INT40:
9824 case FT_INT48:
9825 case FT_INT56:
9826 case FT_INT64:
9827 /* Hexadecimal and octal are, in printf() and everywhere
9828 * else, unsigned so don't allow dissectors to register a
9829 * signed field to be displayed unsigned. (Else how would
9830 * we display negative values?)
9831 */
9832 switch (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF)) {
9833 case BASE_HEX:
9834 case BASE_OCT:
9835 case BASE_DEC_HEX:
9836 case BASE_HEX_DEC:
9837 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Bit count: %d)");
9838 REPORT_DISSECTOR_BUG("Field '%s' (%s) is signed (%s) but is being displayed unsigned (%s)",proto_report_dissector_bug("Field '%s' (%s) is signed (%s) but is being displayed unsigned (%s)"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9839 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is signed (%s) but is being displayed unsigned (%s)"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9840 ftype_name(hfinfo->type), tmp_str)proto_report_dissector_bug("Field '%s' (%s) is signed (%s) but is being displayed unsigned (%s)"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
;
9841 //wmem_free(NULL, tmp_str);
9842 }
9843 /* FALL THROUGH */
9844 case FT_UINT8:
9845 case FT_UINT16:
9846 case FT_UINT24:
9847 case FT_UINT32:
9848 case FT_UINT40:
9849 case FT_UINT48:
9850 case FT_UINT56:
9851 case FT_UINT64:
9852 if (IS_BASE_PORT(hfinfo->display)(((hfinfo->display)==BASE_PT_UDP||(hfinfo->display)==BASE_PT_TCP
||(hfinfo->display)==BASE_PT_DCCP||(hfinfo->display)==BASE_PT_SCTP
))
) {
9853 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Unknown: 0x%x)");
9854 if (hfinfo->type != FT_UINT16) {
9855 REPORT_DISSECTOR_BUG("Field '%s' (%s) has 'display' value %s but it can only be used with FT_UINT16, not %s",proto_report_dissector_bug("Field '%s' (%s) has 'display' value %s but it can only be used with FT_UINT16, not %s"
, hfinfo->name, hfinfo->abbrev, tmp_str, ftype_name(hfinfo
->type))
9856 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) has 'display' value %s but it can only be used with FT_UINT16, not %s"
, hfinfo->name, hfinfo->abbrev, tmp_str, ftype_name(hfinfo
->type))
9857 tmp_str, ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) has 'display' value %s but it can only be used with FT_UINT16, not %s"
, hfinfo->name, hfinfo->abbrev, tmp_str, ftype_name(hfinfo
->type))
;
9858 }
9859 if (hfinfo->strings != NULL((void*)0)) {
9860 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s (%s) but has a strings value",proto_report_dissector_bug("Field '%s' (%s) is an %s (%s) but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9861 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s (%s) but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9862 ftype_name(hfinfo->type), tmp_str)proto_report_dissector_bug("Field '%s' (%s) is an %s (%s) but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
;
9863 }
9864 if (hfinfo->bitmask != 0) {
9865 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s (%s) but has a bitmask",proto_report_dissector_bug("Field '%s' (%s) is an %s (%s) but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9866 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s (%s) but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9867 ftype_name(hfinfo->type), tmp_str)proto_report_dissector_bug("Field '%s' (%s) is an %s (%s) but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
;
9868 }
9869 wmem_free(NULL((void*)0), tmp_str);
9870 break;
9871 }
9872
9873 if (hfinfo->display == BASE_OUI) {
9874 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Unknown: 0x%x)");
9875 if (!FT_IS_UINT(hfinfo->type)(((hfinfo->type) == FT_CHAR || (hfinfo->type) == FT_UINT8
|| (hfinfo->type) == FT_UINT16 || (hfinfo->type) == FT_UINT24
|| (hfinfo->type) == FT_UINT32 || (hfinfo->type) == FT_FRAMENUM
) || ((hfinfo->type) == FT_UINT40 || (hfinfo->type) == FT_UINT48
|| (hfinfo->type) == FT_UINT56 || (hfinfo->type) == FT_UINT64
))
|| ftype_wire_size(hfinfo->type) < 3) {
9876 REPORT_DISSECTOR_BUG("Field '%s' (%s) has 'display' value %s but it can only be used with FT_UINT24, not %s",proto_report_dissector_bug("Field '%s' (%s) has 'display' value %s but it can only be used with FT_UINT24, not %s"
, hfinfo->name, hfinfo->abbrev, tmp_str, ftype_name(hfinfo
->type))
9877 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) has 'display' value %s but it can only be used with FT_UINT24, not %s"
, hfinfo->name, hfinfo->abbrev, tmp_str, ftype_name(hfinfo
->type))
9878 tmp_str, ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) has 'display' value %s but it can only be used with FT_UINT24, not %s"
, hfinfo->name, hfinfo->abbrev, tmp_str, ftype_name(hfinfo
->type))
;
9879 }
9880 if (hfinfo->strings != NULL((void*)0)) {
9881 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s (%s) but has a strings value",proto_report_dissector_bug("Field '%s' (%s) is an %s (%s) but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9882 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s (%s) but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9883 ftype_name(hfinfo->type), tmp_str)proto_report_dissector_bug("Field '%s' (%s) is an %s (%s) but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
;
9884 }
9885 /* It can be a FT_UINT24 with a 0 bitmask, or
9886 * larger with a bitmask with 24 bits set. */
9887 if ((hfinfo->type != FT_UINT24 || hfinfo->bitmask != 0) && ws_count_ones(hfinfo->bitmask) != 24) {
9888 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s (%s) but has a bitmask",proto_report_dissector_bug("Field '%s' (%s) is an %s (%s) but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9889 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s (%s) but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9890 ftype_name(hfinfo->type), tmp_str)proto_report_dissector_bug("Field '%s' (%s) is an %s (%s) but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
;
9891 }
9892 wmem_free(NULL((void*)0), tmp_str);
9893 break;
9894 }
9895
9896 /* Require integral types (other than frame number,
9897 * which is always displayed in decimal) to have a
9898 * number base.
9899 *
9900 * If the display value is BASE_NONE and there is a
9901 * strings conversion then the dissector writer is
9902 * telling us that the field's numerical value is
9903 * meaningless; we'll avoid showing the value to the
9904 * user.
9905 */
9906 switch (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF)) {
9907 case BASE_DEC:
9908 case BASE_HEX:
9909 case BASE_OCT:
9910 case BASE_DEC_HEX:
9911 case BASE_HEX_DEC:
9912 case BASE_CUSTOM: /* hfinfo_numeric_value_format() treats this as decimal */
9913 break;
9914 case BASE_NONE:
9915 if (hfinfo->strings == NULL((void*)0)) {
9916 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an integral value (%s)"proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as BASE_NONE but" " without a strings conversion"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9917 " but is being displayed as BASE_NONE but"proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as BASE_NONE but" " without a strings conversion"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9918 " without a strings conversion",proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as BASE_NONE but" " without a strings conversion"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9919 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as BASE_NONE but" " without a strings conversion"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9920 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as BASE_NONE but" " without a strings conversion"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
9921 }
9922 if (hfinfo->display & BASE_SPECIAL_VALS0x00008000) {
9923 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an integral value (%s)"proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" that is being displayed as BASE_NONE but" " with BASE_SPECIAL_VALS"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9924 " that is being displayed as BASE_NONE but"proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" that is being displayed as BASE_NONE but" " with BASE_SPECIAL_VALS"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9925 " with BASE_SPECIAL_VALS",proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" that is being displayed as BASE_NONE but" " with BASE_SPECIAL_VALS"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9926 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" that is being displayed as BASE_NONE but" " with BASE_SPECIAL_VALS"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9927 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" that is being displayed as BASE_NONE but" " with BASE_SPECIAL_VALS"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
9928 }
9929 break;
9930
9931 default:
9932 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Unknown: 0x%x)");
9933 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an integral value (%s)"proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
9934 " but is being displayed as %s",proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
9935 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
9936 ftype_name(hfinfo->type), tmp_str)proto_report_dissector_bug("Field '%s' (%s) is an integral value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
;
9937 //wmem_free(NULL, tmp_str);
9938 }
9939 break;
9940 case FT_BYTES:
9941 case FT_UINT_BYTES:
9942 /* Require bytes to have a "display type" that could
9943 * add a character between displayed bytes.
9944 */
9945 switch (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF)) {
9946 case BASE_NONE:
9947 case SEP_DOT:
9948 case SEP_DASH:
9949 case SEP_COLON:
9950 case SEP_SPACE:
9951 break;
9952 default:
9953 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Bit count: %d)");
9954 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an byte array but is being displayed as %s instead of BASE_NONE, SEP_DOT, SEP_DASH, SEP_COLON, or SEP_SPACE",proto_report_dissector_bug("Field '%s' (%s) is an byte array but is being displayed as %s instead of BASE_NONE, SEP_DOT, SEP_DASH, SEP_COLON, or SEP_SPACE"
, hfinfo->name, hfinfo->abbrev, tmp_str)
9955 hfinfo->name, hfinfo->abbrev, tmp_str)proto_report_dissector_bug("Field '%s' (%s) is an byte array but is being displayed as %s instead of BASE_NONE, SEP_DOT, SEP_DASH, SEP_COLON, or SEP_SPACE"
, hfinfo->name, hfinfo->abbrev, tmp_str)
;
9956 //wmem_free(NULL, tmp_str);
9957 }
9958 if (hfinfo->bitmask != 0)
9959 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask",proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9960 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9961 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
9962 //allowed to support string if its a protocol (for pinos)
9963 if ((hfinfo->strings != NULL((void*)0)) && (!(hfinfo->display & BASE_PROTOCOL_INFO0x00004000)))
9964 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a strings value",proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9965 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9966 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
9967 break;
9968
9969 case FT_PROTOCOL:
9970 case FT_FRAMENUM:
9971 if (hfinfo->display != BASE_NONE) {
9972 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Bit count: %d)");
9973 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE",proto_report_dissector_bug("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9974 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9975 ftype_name(hfinfo->type), tmp_str)proto_report_dissector_bug("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
;
9976 //wmem_free(NULL, tmp_str);
9977 }
9978 if (hfinfo->bitmask != 0)
9979 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask",proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9980 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9981 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
9982 break;
9983
9984 case FT_BOOLEAN:
9985 break;
9986
9987 case FT_ABSOLUTE_TIME:
9988 if (!FIELD_DISPLAY_IS_ABSOLUTE_TIME(hfinfo->display)(((hfinfo->display) & 0xFF) >= ABSOLUTE_TIME_LOCAL &&
((hfinfo->display) & 0xFF) <= ABSOLUTE_TIME_UNIX)
) {
9989 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Bit count: %d)");
9990 REPORT_DISSECTOR_BUG("Field '%s' (%s) is a %s but is being displayed as %s instead of as a time",proto_report_dissector_bug("Field '%s' (%s) is a %s but is being displayed as %s instead of as a time"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
9991 hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type), tmp_str)proto_report_dissector_bug("Field '%s' (%s) is a %s but is being displayed as %s instead of as a time"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
;
9992 //wmem_free(NULL, tmp_str);
9993 }
9994 if (hfinfo->bitmask != 0)
9995 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask",proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9996 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
9997 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
9998 break;
9999
10000 case FT_STRING:
10001 case FT_STRINGZ:
10002 case FT_UINT_STRING:
10003 case FT_STRINGZPAD:
10004 case FT_STRINGZTRUNC:
10005 switch (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF)) {
10006 case BASE_NONE:
10007 case BASE_STR_WSP:
10008 break;
10009
10010 default:
10011 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Unknown: 0x%x)");
10012 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an string value (%s)"proto_report_dissector_bug("Field '%s' (%s) is an string value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
10013 " but is being displayed as %s",proto_report_dissector_bug("Field '%s' (%s) is an string value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
10014 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an string value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
10015 ftype_name(hfinfo->type), tmp_str)proto_report_dissector_bug("Field '%s' (%s) is an string value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
;
10016 //wmem_free(NULL, tmp_str);
10017 }
10018
10019 if (hfinfo->bitmask != 0)
10020 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask",proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10021 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10022 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
10023 if (hfinfo->strings != NULL((void*)0))
10024 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a strings value",proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10025 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10026 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
10027 break;
10028
10029 case FT_IPv4:
10030 switch (hfinfo->display) {
10031 case BASE_NONE:
10032 case BASE_NETMASK:
10033 break;
10034
10035 default:
10036 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Unknown: 0x%x)");
10037 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an IPv4 value (%s)"proto_report_dissector_bug("Field '%s' (%s) is an IPv4 value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
10038 " but is being displayed as %s",proto_report_dissector_bug("Field '%s' (%s) is an IPv4 value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
10039 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an IPv4 value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
10040 ftype_name(hfinfo->type), tmp_str)proto_report_dissector_bug("Field '%s' (%s) is an IPv4 value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
;
10041 //wmem_free(NULL, tmp_str);
10042 break;
10043 }
10044 break;
10045 case FT_FLOAT:
10046 case FT_DOUBLE:
10047 switch (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF)) {
10048 case BASE_NONE:
10049 case BASE_DEC:
10050 case BASE_HEX:
10051 case BASE_EXP:
10052 case BASE_CUSTOM:
10053 break;
10054 default:
10055 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Unknown: 0x%x)");
10056 REPORT_DISSECTOR_BUG("Field '%s' (%s) is a float value (%s)"proto_report_dissector_bug("Field '%s' (%s) is a float value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
10057 " but is being displayed as %s",proto_report_dissector_bug("Field '%s' (%s) is a float value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
10058 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is a float value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
10059 ftype_name(hfinfo->type), tmp_str)proto_report_dissector_bug("Field '%s' (%s) is a float value (%s)"
" but is being displayed as %s", hfinfo->name, hfinfo->
abbrev, ftype_name(hfinfo->type), tmp_str)
;
10060 //wmem_free(NULL, tmp_str);
10061 }
10062 if (hfinfo->bitmask != 0)
10063 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask",proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10064 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10065 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
10066 if (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF) != BASE_CUSTOM && (hfinfo->strings != NULL((void*)0)) && !(hfinfo->display & BASE_UNIT_STRING0x00001000))
10067 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a strings value",proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10068 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10069 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
10070 break;
10071 case FT_IEEE_11073_SFLOAT:
10072 case FT_IEEE_11073_FLOAT:
10073 if (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF) != BASE_NONE) {
10074 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Bit count: %d)");
10075 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE",proto_report_dissector_bug("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
10076 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
10077 ftype_name(hfinfo->type),proto_report_dissector_bug("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
10078 tmp_str)proto_report_dissector_bug("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
;
10079 //wmem_free(NULL, tmp_str);
10080 }
10081 if (hfinfo->bitmask != 0)
10082 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask",proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10083 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10084 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
10085 if ((hfinfo->strings != NULL((void*)0)) && !(hfinfo->display & BASE_UNIT_STRING0x00001000))
10086 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a strings value",proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10087 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10088 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
10089 break;
10090 default:
10091 if (hfinfo->display != BASE_NONE) {
10092 tmp_str = val_to_str(NULL((void*)0), hfinfo->display, hf_display, "(Bit count: %d)");
10093 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE",proto_report_dissector_bug("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
10094 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
10095 ftype_name(hfinfo->type),proto_report_dissector_bug("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
10096 tmp_str)proto_report_dissector_bug("Field '%s' (%s) is an %s but is being displayed as %s instead of BASE_NONE"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
), tmp_str)
;
10097 //wmem_free(NULL, tmp_str);
10098 }
10099 if (hfinfo->bitmask != 0)
10100 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a bitmask",proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10101 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10102 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an %s but has a bitmask"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
10103 if (hfinfo->strings != NULL((void*)0))
10104 REPORT_DISSECTOR_BUG("Field '%s' (%s) is an %s but has a strings value",proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10105 hfinfo->name, hfinfo->abbrev,proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
10106 ftype_name(hfinfo->type))proto_report_dissector_bug("Field '%s' (%s) is an %s but has a strings value"
, hfinfo->name, hfinfo->abbrev, ftype_name(hfinfo->type
))
;
10107 break;
10108 }
10109}
10110
10111static void
10112register_type_length_mismatch(void)
10113{
10114 static ei_register_info ei[] = {
10115 { &ei_type_length_mismatch_error, { "_ws.type_length.mismatch", PI_MALFORMED0x07000000, PI_ERROR0x00800000, "Trying to fetch X with length Y", 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)}}
}},
10116 { &ei_type_length_mismatch_warn, { "_ws.type_length.mismatch_warn", PI_MALFORMED0x07000000, PI_WARN0x00600000, "Trying to fetch X with length Y", 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)}}
}},
10117 };
10118
10119 expert_module_t* expert_type_length_mismatch;
10120
10121 proto_type_length_mismatch = proto_register_protocol("Type Length Mismatch", "Type length mismatch", "_ws.type_length");
10122
10123 expert_type_length_mismatch = expert_register_protocol(proto_type_length_mismatch);
10124 expert_register_field_array(expert_type_length_mismatch, ei, array_length(ei)(sizeof (ei) / sizeof (ei)[0]));
10125
10126 /* "Type Length Mismatch" isn't really a protocol, it's an error indication;
10127 disabling them makes no sense. */
10128 proto_set_cant_toggle(proto_type_length_mismatch);
10129}
10130
10131static void
10132register_byte_array_string_decodinws_error(void)
10133{
10134 static ei_register_info ei[] = {
10135 { &ei_byte_array_string_decoding_failed_error,
10136 { "_ws.byte_array_string.decoding_error.failed", PI_MALFORMED0x07000000, PI_ERROR0x00800000,
10137 "Failed to decode byte array from string", 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)}}
10138 }
10139 },
10140 };
10141
10142 expert_module_t* expert_byte_array_string_decoding_error;
10143
10144 proto_byte_array_string_decoding_error =
10145 proto_register_protocol("Byte Array-String Decoding Error",
10146 "Byte Array-string decoding error",
10147 "_ws.byte_array_string.decoding_error");
10148
10149 expert_byte_array_string_decoding_error =
10150 expert_register_protocol(proto_byte_array_string_decoding_error);
10151 expert_register_field_array(expert_byte_array_string_decoding_error, ei, array_length(ei)(sizeof (ei) / sizeof (ei)[0]));
10152
10153 /* "Byte Array-String Decoding Error" isn't really a protocol, it's an error indication;
10154 disabling them makes no sense. */
10155 proto_set_cant_toggle(proto_byte_array_string_decoding_error);
10156}
10157
10158static void
10159register_date_time_string_decodinws_error(void)
10160{
10161 static ei_register_info ei[] = {
10162 { &ei_date_time_string_decoding_failed_error,
10163 { "_ws.date_time_string.decoding_error.failed", PI_MALFORMED0x07000000, PI_ERROR0x00800000,
10164 "Failed to decode date and time from string", 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)}}
10165 }
10166 },
10167 };
10168
10169 expert_module_t* expert_date_time_string_decoding_error;
10170
10171 proto_date_time_string_decoding_error =
10172 proto_register_protocol("Date and Time-String Decoding Error",
10173 "Date and Time-string decoding error",
10174 "_ws.date_time_string.decoding_error");
10175
10176 expert_date_time_string_decoding_error =
10177 expert_register_protocol(proto_date_time_string_decoding_error);
10178 expert_register_field_array(expert_date_time_string_decoding_error, ei, array_length(ei)(sizeof (ei) / sizeof (ei)[0]));
10179
10180 /* "Date and Time-String Decoding Error" isn't really a protocol, it's an error indication;
10181 disabling them makes no sense. */
10182 proto_set_cant_toggle(proto_date_time_string_decoding_error);
10183}
10184
10185static void
10186register_string_errors(void)
10187{
10188 static ei_register_info ei[] = {
10189 { &ei_string_trailing_characters,
10190 { "_ws.string.trailing_stray_characters", PI_UNDECODED0x05000000, PI_WARN0x00600000, "Trailing stray characters", 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)}}
}
10191 },
10192 };
10193
10194 expert_module_t* expert_string_errors;
10195
10196 proto_string_errors = proto_register_protocol("String Errors", "String errors", "_ws.string");
10197
10198 expert_string_errors = expert_register_protocol(proto_string_errors);
10199 expert_register_field_array(expert_string_errors, ei, array_length(ei)(sizeof (ei) / sizeof (ei)[0]));
10200
10201 /* "String Errors" isn't really a protocol, it's an error indication;
10202 disabling them makes no sense. */
10203 proto_set_cant_toggle(proto_string_errors);
10204}
10205
10206static void
10207register_varint_errors(void)
10208{
10209 static ei_register_info ei[] = {
10210 { &ei_varint_decoding_failed_error,
10211 { "_ws.varint.decoding_failed", PI_MALFORMED0x07000000, PI_ERROR0x00800000, "Varint decoding failed", 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)}}
}
10212 },
10213 };
10214
10215 expert_module_t* expert_varint_errors;
10216
10217 proto_varint_errors = proto_register_protocol("Varint Errors", "Varint errors", "_ws.varint");
10218
10219 expert_varint_errors = expert_register_protocol(proto_varint_errors);
10220 expert_register_field_array(expert_varint_errors, ei, array_length(ei)(sizeof (ei) / sizeof (ei)[0]));
10221
10222 /* "Varint Errors" isn't really a protocol, it's an error indication;
10223 disabling them makes no sense. */
10224 proto_set_cant_toggle(proto_varint_errors);
10225}
10226
10227static int
10228proto_register_field_init(header_field_info *hfinfo, const int parent)
10229{
10230
10231 tmp_fld_check_assert(hfinfo);
10232
10233 hfinfo->parent = parent;
10234 hfinfo->same_name_next = NULL((void*)0);
10235 hfinfo->same_name_prev_id = -1;
10236
10237 /* if we always add and never delete, then id == len - 1 is correct */
10238 if (gpa_hfinfo.len >= gpa_hfinfo.allocated_len) {
10239 if (!gpa_hfinfo.hfi) {
10240 gpa_hfinfo.allocated_len = PROTO_PRE_ALLOC_HF_FIELDS_MEM(300000+5000);
10241 gpa_hfinfo.hfi = (header_field_info **)g_malloc(sizeof(header_field_info *)*PROTO_PRE_ALLOC_HF_FIELDS_MEM(300000+5000));
10242 /* The entry with index 0 is not used. */
10243 gpa_hfinfo.hfi[0] = NULL((void*)0);
10244 gpa_hfinfo.len = 1;
10245 } else {
10246 gpa_hfinfo.allocated_len += 1000;
10247 gpa_hfinfo.hfi = (header_field_info **)g_realloc(gpa_hfinfo.hfi,
10248 sizeof(header_field_info *)*gpa_hfinfo.allocated_len);
10249 /*ws_warning("gpa_hfinfo.allocated_len %u", gpa_hfinfo.allocated_len);*/
10250 }
10251 }
10252 gpa_hfinfo.hfi[gpa_hfinfo.len] = hfinfo;
10253 gpa_hfinfo.len++;
10254 hfinfo->id = gpa_hfinfo.len - 1;
10255
10256 /* if we have real names, enter this field in the name tree */
10257 /* Already checked in tmp_fld_check_assert */
10258 /*if ((hfinfo->name[0] != 0) && (hfinfo->abbrev[0] != 0 )) */
10259 {
10260
10261 header_field_info *same_name_next_hfinfo;
10262
10263 /* We allow multiple hfinfo's to be registered under the same
10264 * abbreviation. This was done for X.25, as, depending
10265 * on whether it's modulo-8 or modulo-128 operation,
10266 * some bitfield fields may be in different bits of
10267 * a byte, and we want to be able to refer to that field
10268 * with one name regardless of whether the packets
10269 * are modulo-8 or modulo-128 packets. */
10270
10271 /* wmem_map_insert - if key is already present the previous
10272 * hfinfo with the same key/name is returned, otherwise NULL */
10273 same_name_hfinfo = wmem_map_insert(gpa_name_map, (void *) (hfinfo->abbrev), hfinfo);
10274 if (same_name_hfinfo) {
10275 /* There's already a field with this name.
10276 * Put the current field *before* that field
10277 * in the list of fields with this name, Thus,
10278 * we end up with an effectively
10279 * doubly-linked-list of same-named hfinfo's,
10280 * with the head of the list (stored in the
10281 * hash) being the last seen hfinfo.
10282 */
10283 same_name_next_hfinfo =
10284 same_name_hfinfo->same_name_next;
10285
10286 hfinfo->same_name_next = same_name_next_hfinfo;
10287 if (same_name_next_hfinfo)
10288 same_name_next_hfinfo->same_name_prev_id = hfinfo->id;
10289
10290 same_name_hfinfo->same_name_next = hfinfo;
10291 hfinfo->same_name_prev_id = same_name_hfinfo->id;
10292#ifdef ENABLE_CHECK_FILTER
10293 while (same_name_hfinfo) {
10294 if (!ftype_similar_types(hfinfo->type, same_name_hfinfo->type))
10295 ws_error("'%s' exists multiple times with incompatible types: %s and %s", hfinfo->abbrev, ftype_name(hfinfo->type), ftype_name(same_name_hfinfo->type))ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 10295
, __func__, "'%s' exists multiple times with incompatible types: %s and %s"
, hfinfo->abbrev, ftype_name(hfinfo->type), ftype_name(
same_name_hfinfo->type))
;
10296 same_name_hfinfo = same_name_hfinfo->same_name_next;
10297 }
10298#endif
10299 }
10300 }
10301
10302 return hfinfo->id;
10303}
10304
10305void
10306proto_register_subtree_array(int * const *indices, const int num_indices)
10307{
10308 int i;
10309 int *const *ptr = indices;
10310
10311 /*
10312 * If we've already allocated the array of tree types, expand
10313 * it; this lets plugins such as mate add tree types after
10314 * the initial startup. (If we haven't already allocated it,
10315 * we don't allocate it; on the first pass, we just assign
10316 * ett values and keep track of how many we've assigned, and
10317 * when we're finished registering all dissectors we allocate
10318 * the array, so that we do only one allocation rather than
10319 * wasting CPU time and memory by growing the array for each
10320 * dissector that registers ett values.)
10321 */
10322 if (tree_is_expanded != NULL((void*)0)) {
10323 tree_is_expanded = (uint32_t *)g_realloc(tree_is_expanded, (1+((num_tree_types + num_indices)/32)) * sizeof(uint32_t));
10324
10325 /* set new items to 0 */
10326 /* XXX, slow!!! optimize when needed (align 'i' to 32, and set rest of uint32_t to 0) */
10327 for (i = num_tree_types; i < num_tree_types + num_indices; i++)
10328 tree_is_expanded[i >> 5] &= ~(1U << (i & 31));
10329 }
10330
10331 /*
10332 * Assign "num_indices" subtree numbers starting at "num_tree_types",
10333 * returning the indices through the pointers in the array whose
10334 * first element is pointed to by "indices", and update
10335 * "num_tree_types" appropriately.
10336 */
10337 for (i = 0; i < num_indices; i++, ptr++, num_tree_types++) {
10338 if (**ptr != -1 && **ptr != 0) {
10339 REPORT_DISSECTOR_BUG("register_subtree_array: subtree item type (ett_...) not -1 or 0 ."proto_report_dissector_bug("register_subtree_array: subtree item type (ett_...) not -1 or 0 ."
" This is a development error:" " Either the subtree item type has already been assigned or"
" was not initialized to -1 or 0.")
10340 " This is a development error:"proto_report_dissector_bug("register_subtree_array: subtree item type (ett_...) not -1 or 0 ."
" This is a development error:" " Either the subtree item type has already been assigned or"
" was not initialized to -1 or 0.")
10341 " Either the subtree item type has already been assigned or"proto_report_dissector_bug("register_subtree_array: subtree item type (ett_...) not -1 or 0 ."
" This is a development error:" " Either the subtree item type has already been assigned or"
" was not initialized to -1 or 0.")
10342 " was not initialized to -1 or 0.")proto_report_dissector_bug("register_subtree_array: subtree item type (ett_...) not -1 or 0 ."
" This is a development error:" " Either the subtree item type has already been assigned or"
" was not initialized to -1 or 0.")
;
10343 }
10344 **ptr = num_tree_types;
10345 }
10346}
10347
10348static void
10349mark_truncated(char *label_str, size_t name_pos, const size_t size, size_t *value_pos)
10350{
10351 static const char trunc_str[] = " [" UTF8_HORIZONTAL_ELLIPSIS"\u2026" "] ";
10352 const size_t trunc_len = sizeof(trunc_str)-2; /* Default do not include the trailing space. */
10353 char *last_char;
10354
10355 /* ..... field_name: dataaaaaaaaaaaaa
10356 * |
10357 * ^^^^^ name_pos
10358 *
10359 * ..... field_name […]: dataaaaaaaaaaaaa
10360 *
10361 * name_pos==0 means that we have only data or only a field_name
10362 */
10363
10364 ws_abort_if_fail(size > trunc_len)do { if ((1) && !(size > trunc_len)) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 10364, __func__, "assertion failed: %s"
, "size > trunc_len"); } while (0)
;
10365
10366 if (name_pos >= size - trunc_len) {
10367 /* No room for trunc_str after the field_name, put it first. */
10368 name_pos = 0;
10369 }
10370
10371 memmove(label_str + name_pos + trunc_len, label_str + name_pos, size - name_pos - trunc_len);
10372 if (name_pos == 0) {
10373 /* Copy the trunc_str after the first byte, so that we don't have a leading space in the label. */
10374 memcpy(label_str, trunc_str + 1, trunc_len);
10375 } else {
10376 memcpy(label_str + name_pos, trunc_str, trunc_len);
10377 }
10378 /* in general, label_str is UTF-8
10379 we can truncate it only at the beginning of a new character
10380 we go backwards from the byte right after our buffer and
10381 find the next starting byte of a UTF-8 character, this is
10382 where we cut
10383 there's no need to use g_utf8_find_prev_char(), the search
10384 will always succeed since we copied trunc_str into the
10385 buffer */
10386 /* g_utf8_prev_char does not deference the memory address
10387 * passed in (until after decrementing it, so it is perfectly
10388 * legal to pass in a pointer one past the last element.
10389 */
10390 last_char = g_utf8_prev_char(label_str + size);
10391 *last_char = '\0';
10392 /* This is unnecessary (above always terminates), but try to
10393 * convince Coverity to avoid dozens of false positives. */
10394 label_str[size - 1] = '\0';
10395
10396 if (value_pos && *value_pos > 0) {
10397 if (name_pos == 0) {
10398 *value_pos += trunc_len;
10399 } else {
10400 /* Move one back to include trunc_str in the value. */
10401 *value_pos -= 1;
10402 }
10403 }
10404
10405 /* Check if value_pos is past label_str. */
10406 if (value_pos && *value_pos >= size) {
10407 *value_pos = size - 1;
10408 }
10409}
10410
10411static void
10412label_mark_truncated(char *label_str, size_t name_pos, size_t *value_pos)
10413{
10414 mark_truncated(label_str, name_pos, ITEM_LABEL_LENGTH240, value_pos);
10415}
10416
10417static size_t
10418label_fill(char *label_str, size_t pos, const header_field_info *hfinfo, const char *text, size_t *value_pos)
10419{
10420 size_t name_pos;
10421
10422 /* "%s: %s", hfinfo->name, text */
10423 name_pos = pos = label_concat(label_str, pos, (const uint8_t*)hfinfo->name)ws_label_strcpy(label_str, 240, pos, (const uint8_t*)hfinfo->
name, 0)
;
10424 if (!(hfinfo->display & BASE_NO_DISPLAY_VALUE0x00002000)) {
10425 pos = label_concat(label_str, pos, (const uint8_t*)": ")ws_label_strcpy(label_str, 240, pos, (const uint8_t*)": ", 0);
10426 if (value_pos) {
10427 *value_pos = pos;
10428 }
10429 pos = ws_label_strcpy(label_str, ITEM_LABEL_LENGTH240, pos, (const uint8_t*)(text ? text : "(null)"), label_strcat_flags(hfinfo));
10430 }
10431
10432 if (pos >= ITEM_LABEL_LENGTH240) {
10433 /* Uh oh, we don't have enough room. Tell the user that the field is truncated. */
10434 label_mark_truncated(label_str, name_pos, value_pos);
10435 }
10436
10437 return pos;
10438}
10439
10440static size_t
10441label_fill_descr(char *label_str, size_t pos, const header_field_info *hfinfo, const char *text, const char *descr, size_t *value_pos)
10442{
10443 size_t name_pos;
10444
10445 /* "%s: %s (%s)", hfinfo->name, text, descr */
10446 name_pos = pos = label_concat(label_str, pos, (const uint8_t*)hfinfo->name)ws_label_strcpy(label_str, 240, pos, (const uint8_t*)hfinfo->
name, 0)
;
10447 if (!(hfinfo->display & BASE_NO_DISPLAY_VALUE0x00002000)) {
10448 pos = label_concat(label_str, pos, (const uint8_t*)": ")ws_label_strcpy(label_str, 240, pos, (const uint8_t*)": ", 0);
10449 if (value_pos) {
10450 *value_pos = pos;
10451 }
10452 if (hfinfo->display & BASE_UNIT_STRING0x00001000) {
10453 pos = label_concat(label_str, pos, (const uint8_t*)(descr ? descr : "(null)"))ws_label_strcpy(label_str, 240, pos, (const uint8_t*)(descr ?
descr : "(null)"), 0)
;
10454 pos = label_concat(label_str, pos, (const uint8_t*)(text ? text : "(null)"))ws_label_strcpy(label_str, 240, pos, (const uint8_t*)(text ? text
: "(null)"), 0)
;
10455 } else {
10456 pos = label_concat(label_str, pos, (const uint8_t*)(text ? text : "(null)"))ws_label_strcpy(label_str, 240, pos, (const uint8_t*)(text ? text
: "(null)"), 0)
;
10457 pos = label_concat(label_str, pos, (const uint8_t*)" (")ws_label_strcpy(label_str, 240, pos, (const uint8_t*)" (", 0);
10458 pos = label_concat(label_str, pos, (const uint8_t*)(descr ? descr : "(null)"))ws_label_strcpy(label_str, 240, pos, (const uint8_t*)(descr ?
descr : "(null)"), 0)
;
10459 pos = label_concat(label_str, pos, (const uint8_t*)")")ws_label_strcpy(label_str, 240, pos, (const uint8_t*)")", 0);
10460 }
10461 }
10462
10463 if (pos >= ITEM_LABEL_LENGTH240) {
10464 /* Uh oh, we don't have enough room. Tell the user that the field is truncated. */
10465 label_mark_truncated(label_str, name_pos, value_pos);
10466 }
10467
10468 return pos;
10469}
10470
10471void
10472proto_item_fill_label(const field_info *fi, char *label_str, size_t *value_pos)
10473{
10474 const header_field_info *hfinfo;
10475 const char *str;
10476 const uint8_t *bytes;
10477 uint32_t integer;
10478 const ipv4_addr_and_mask *ipv4;
10479 const ipv6_addr_and_prefix *ipv6;
10480 const e_guid_t *guid;
10481 char *name;
10482 address addr;
10483 char *addr_str;
10484 char *tmp;
10485
10486 if (!label_str) {
10487 ws_warning("NULL label_str passed to proto_item_fill_label.")do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 10487, __func__, "NULL label_str passed to proto_item_fill_label."
); } } while (0)
;
10488 return;
10489 }
10490
10491 label_str[0]= '\0';
10492
10493 if (!fi) {
10494 return;
10495 }
10496
10497 hfinfo = fi->hfinfo;
10498
10499 switch (hfinfo->type) {
10500 case FT_NONE:
10501 case FT_PROTOCOL:
10502 (void) g_strlcpy(label_str, hfinfo->name, ITEM_LABEL_LENGTH240);
10503 if (value_pos) {
10504 *value_pos = strlen(hfinfo->name);
10505 }
10506 break;
10507
10508 case FT_BOOLEAN:
10509 fill_label_boolean(fi, label_str, value_pos);
10510 break;
10511
10512 case FT_BYTES:
10513 case FT_UINT_BYTES:
10514 tmp = format_bytes_hfinfo(NULL((void*)0), hfinfo,
10515 fvalue_get_bytes_data(fi->value),
10516 (unsigned)fvalue_length2(fi->value));
10517 label_fill(label_str, 0, hfinfo, tmp, value_pos);
10518 wmem_free(NULL((void*)0), tmp);
10519 break;
10520
10521 case FT_CHAR:
10522 if (hfinfo->bitmask) {
10523 fill_label_bitfield_char(fi, label_str, value_pos);
10524 } else {
10525 fill_label_char(fi, label_str, value_pos);
10526 }
10527 break;
10528
10529 /* Four types of integers to take care of:
10530 * Bitfield, with val_string
10531 * Bitfield, w/o val_string
10532 * Non-bitfield, with val_string
10533 * Non-bitfield, w/o val_string
10534 */
10535 case FT_UINT8:
10536 case FT_UINT16:
10537 case FT_UINT24:
10538 case FT_UINT32:
10539 if (hfinfo->bitmask) {
10540 fill_label_bitfield(fi, label_str, value_pos, false0);
10541 } else {
10542 fill_label_number(fi, label_str, value_pos, false0);
10543 }
10544 break;
10545
10546 case FT_FRAMENUM:
10547 fill_label_number(fi, label_str, value_pos, false0);
10548 break;
10549
10550 case FT_UINT40:
10551 case FT_UINT48:
10552 case FT_UINT56:
10553 case FT_UINT64:
10554 if (hfinfo->bitmask) {
10555 fill_label_bitfield64(fi, label_str, value_pos, false0);
10556 } else {
10557 fill_label_number64(fi, label_str, value_pos, false0);
10558 }
10559 break;
10560
10561 case FT_INT8:
10562 case FT_INT16:
10563 case FT_INT24:
10564 case FT_INT32:
10565 if (hfinfo->bitmask) {
10566 fill_label_bitfield(fi, label_str, value_pos, true1);
10567 } else {
10568 fill_label_number(fi, label_str, value_pos, true1);
10569 }
10570 break;
10571
10572 case FT_INT40:
10573 case FT_INT48:
10574 case FT_INT56:
10575 case FT_INT64:
10576 if (hfinfo->bitmask) {
10577 fill_label_bitfield64(fi, label_str, value_pos, true1);
10578 } else {
10579 fill_label_number64(fi, label_str, value_pos, true1);
10580 }
10581 break;
10582
10583 case FT_FLOAT:
10584 case FT_DOUBLE:
10585 fill_label_float(fi, label_str, value_pos);
10586 break;
10587
10588 case FT_ABSOLUTE_TIME:
10589 {
10590 const nstime_t *value = fvalue_get_time(fi->value);
10591 int flags = ABS_TIME_TO_STR_SHOW_ZONE(1U << 0);
10592 if (prefs.display_abs_time_ascii < ABS_TIME_ASCII_TREE) {
10593 flags |= ABS_TIME_TO_STR_ISO8601(1U << 3);
10594 }
10595 if (hfinfo->strings) {
10596 /*
10597 * Table of time values to be displayed
10598 * specially.
10599 *
10600 * XXX - Initializing these time_value_strings can be a pain
10601 * because the special times usually have special values in
10602 * the original encoding, not when converted to a nstime_t
10603 * relative to the UN*X epoch.
10604 */
10605 const char *time_string = try_time_val_to_str(value, (const time_value_string *)hfinfo->strings);
10606 if (time_string != NULL((void*)0)) {
10607 label_fill(label_str, 0, hfinfo, time_string, value_pos);
10608 break;
10609 }
10610 }
10611 tmp = abs_time_to_str_ex(NULL((void*)0), value, hfinfo->display, flags);
10612 label_fill(label_str, 0, hfinfo, tmp, value_pos);
10613 wmem_free(NULL((void*)0), tmp);
10614 break;
10615 }
10616 case FT_RELATIVE_TIME:
10617 tmp = rel_time_to_str(NULL((void*)0), fvalue_get_time(fi->value));
10618 label_fill(label_str, 0, hfinfo, tmp, value_pos);
10619 wmem_free(NULL((void*)0), tmp);
10620 break;
10621
10622 case FT_IPXNET:
10623 integer = fvalue_get_uinteger(fi->value);
10624 tmp = get_ipxnet_name(NULL((void*)0), integer);
10625 addr_str = wmem_strdup_printf(NULL((void*)0), "0x%08X", integer);
10626 label_fill_descr(label_str, 0, hfinfo, tmp, addr_str, value_pos);
10627 wmem_free(NULL((void*)0), tmp);
10628 wmem_free(NULL((void*)0), addr_str);
10629 break;
10630
10631 case FT_VINES:
10632 addr.type = AT_VINES;
10633 addr.len = VINES_ADDR_LEN6;
10634 addr.data = fvalue_get_bytes_data(fi->value);
10635
10636 addr_str = (char*)address_to_str(NULL((void*)0), &addr);
10637 label_fill(label_str, 0, hfinfo, addr_str, value_pos);
10638 wmem_free(NULL((void*)0), addr_str);
10639 break;
10640
10641 case FT_ETHER:
10642 bytes = fvalue_get_bytes_data(fi->value);
10643
10644 addr.type = AT_ETHER;
10645 addr.len = 6;
10646 addr.data = bytes;
10647
10648 addr_str = (char*)address_with_resolution_to_str(NULL((void*)0), &addr);
10649 label_fill(label_str, 0, hfinfo, addr_str, value_pos);
10650 wmem_free(NULL((void*)0), addr_str);
10651 break;
10652
10653 case FT_IPv4:
10654 ipv4 = fvalue_get_ipv4(fi->value);
10655 set_address_ipv4(&addr, ipv4);
10656
10657 if (hfinfo->display == BASE_NETMASK) {
10658 addr_str = (char*)address_to_str(NULL((void*)0), &addr);
10659 } else {
10660 addr_str = (char*)address_with_resolution_to_str(NULL((void*)0), &addr);
10661 }
10662 label_fill(label_str, 0, hfinfo, addr_str, value_pos);
10663 wmem_free(NULL((void*)0), addr_str);
10664 free_address(&addr);
10665 break;
10666
10667 case FT_IPv6:
10668 ipv6 = fvalue_get_ipv6(fi->value);
10669 set_address_ipv6(&addr, ipv6);
10670
10671 addr_str = (char*)address_with_resolution_to_str(NULL((void*)0), &addr);
10672 label_fill(label_str, 0, hfinfo, addr_str, value_pos);
10673 wmem_free(NULL((void*)0), addr_str);
10674 free_address(&addr);
10675 break;
10676
10677 case FT_FCWWN:
10678 bytes = fvalue_get_bytes_data(fi->value);
10679 addr.type = AT_FCWWN;
10680 addr.len = FCWWN_ADDR_LEN8;
10681 addr.data = bytes;
10682
10683 addr_str = (char*)address_with_resolution_to_str(NULL((void*)0), &addr);
10684 label_fill(label_str, 0, hfinfo, addr_str, value_pos);
10685 wmem_free(NULL((void*)0), addr_str);
10686 break;
10687
10688 case FT_GUID:
10689 guid = fvalue_get_guid(fi->value);
10690 tmp = guid_to_str(NULL((void*)0), guid);
10691 label_fill(label_str, 0, hfinfo, tmp, value_pos);
10692 wmem_free(NULL((void*)0), tmp);
10693 break;
10694
10695 case FT_OID:
10696 bytes = fvalue_get_bytes_data(fi->value);
10697 name = oid_resolved_from_encoded(NULL((void*)0), bytes, (int)fvalue_length2(fi->value));
10698 tmp = oid_encoded2string(NULL((void*)0), bytes, (unsigned)fvalue_length2(fi->value));
10699 if (name) {
10700 label_fill_descr(label_str, 0, hfinfo, tmp, name, value_pos);
10701 wmem_free(NULL((void*)0), name);
10702 } else {
10703 label_fill(label_str, 0, hfinfo, tmp, value_pos);
10704 }
10705 wmem_free(NULL((void*)0), tmp);
10706 break;
10707
10708 case FT_REL_OID:
10709 bytes = fvalue_get_bytes_data(fi->value);
10710 name = rel_oid_resolved_from_encoded(NULL((void*)0), bytes, (int)fvalue_length2(fi->value));
10711 tmp = rel_oid_encoded2string(NULL((void*)0), bytes, (unsigned)fvalue_length2(fi->value));
10712 if (name) {
10713 label_fill_descr(label_str, 0, hfinfo, tmp, name, value_pos);
10714 wmem_free(NULL((void*)0), name);
10715 } else {
10716 label_fill(label_str, 0, hfinfo, tmp, value_pos);
10717 }
10718 wmem_free(NULL((void*)0), tmp);
10719 break;
10720
10721 case FT_SYSTEM_ID:
10722 bytes = fvalue_get_bytes_data(fi->value);
10723 tmp = print_system_id(NULL((void*)0), bytes, (int)fvalue_length2(fi->value));
10724 label_fill(label_str, 0, hfinfo, tmp, value_pos);
10725 wmem_free(NULL((void*)0), tmp);
10726 break;
10727
10728 case FT_EUI64:
10729 bytes = fvalue_get_bytes_data(fi->value);
10730 addr.type = AT_EUI64;
10731 addr.len = EUI64_ADDR_LEN8;
10732 addr.data = bytes;
10733
10734 addr_str = (char*)address_with_resolution_to_str(NULL((void*)0), &addr);
10735 label_fill(label_str, 0, hfinfo, addr_str, value_pos);
10736 wmem_free(NULL((void*)0), addr_str);
10737 break;
10738 case FT_STRING:
10739 case FT_STRINGZ:
10740 case FT_UINT_STRING:
10741 case FT_STRINGZPAD:
10742 case FT_STRINGZTRUNC:
10743 case FT_AX25:
10744 str = fvalue_get_string(fi->value);
10745 label_fill(label_str, 0, hfinfo, str, value_pos);
10746 break;
10747
10748 case FT_IEEE_11073_SFLOAT:
10749 case FT_IEEE_11073_FLOAT:
10750 fill_label_ieee_11073_float(fi, label_str, value_pos);
10751 break;
10752
10753 default:
10754 REPORT_DISSECTOR_BUG("field %s has type %d (%s) not handled in proto_item_fill_label()",proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_item_fill_label()"
, hfinfo->abbrev, hfinfo->type, ftype_name(hfinfo->type
))
10755 hfinfo->abbrev,proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_item_fill_label()"
, hfinfo->abbrev, hfinfo->type, ftype_name(hfinfo->type
))
10756 hfinfo->type,proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_item_fill_label()"
, hfinfo->abbrev, hfinfo->type, ftype_name(hfinfo->type
))
10757 ftype_name(hfinfo->type))proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_item_fill_label()"
, hfinfo->abbrev, hfinfo->type, ftype_name(hfinfo->type
))
;
10758 break;
10759 }
10760}
10761
10762static void
10763fill_label_boolean(const field_info *fi, char *label_str, size_t *value_pos)
10764{
10765 char *p;
10766 unsigned bitfield_byte_length = 0;
10767 int bitwidth;
10768 uint64_t unshifted_value;
10769 uint64_t value;
10770
10771 const header_field_info *hfinfo = fi->hfinfo;
10772
10773 value = fvalue_get_uinteger64(fi->value);
10774 if (hfinfo->bitmask) {
10775 /* Figure out the bit width */
10776 bitwidth = hfinfo_container_bitwidth(hfinfo);
10777
10778 /* Un-shift bits */
10779 unshifted_value = value;
10780 unshifted_value <<= hfinfo_bitshift(hfinfo);
10781
10782 /* Create the bitfield first */
10783 p = decode_bitfield_value(label_str, unshifted_value, hfinfo->bitmask, bitwidth);
10784 bitfield_byte_length = (unsigned) (p - label_str);
10785 }
10786
10787 /* Fill in the textual info */
10788 label_fill(label_str, bitfield_byte_length, hfinfo, tfs_get_string(!!value, hfinfo->strings), value_pos);
10789}
10790
10791static const char *
10792hf_try_val_to_str(uint32_t value, const header_field_info *hfinfo)
10793{
10794 if (hfinfo->display & BASE_RANGE_STRING0x00000100)
10795 return try_rval_to_str(value, (const range_string *) hfinfo->strings);
10796
10797 if (hfinfo->display & BASE_EXT_STRING0x00000200) {
10798 if (hfinfo->display & BASE_VAL64_STRING0x00000400)
10799 return try_val64_to_str_ext(value, (val64_string_ext *) hfinfo->strings);
10800 else
10801 return try_val_to_str_ext(value, (value_string_ext *) hfinfo->strings);
10802 }
10803
10804 if (hfinfo->display & BASE_VAL64_STRING0x00000400)
10805 return try_val64_to_str(value, (const val64_string *) hfinfo->strings);
10806
10807 if (hfinfo->display & BASE_UNIT_STRING0x00001000)
10808 return unit_name_string_get_value(value, (const struct unit_name_string*) hfinfo->strings);
10809
10810 return try_val_to_str(value, (const value_string *) hfinfo->strings);
10811}
10812
10813static const char *
10814hf_try_val64_to_str(uint64_t value, const header_field_info *hfinfo)
10815{
10816 if (hfinfo->display & BASE_VAL64_STRING0x00000400) {
10817 if (hfinfo->display & BASE_EXT_STRING0x00000200)
10818 return try_val64_to_str_ext(value, (val64_string_ext *) hfinfo->strings);
10819 else
10820 return try_val64_to_str(value, (const val64_string *) hfinfo->strings);
10821 }
10822
10823 if (hfinfo->display & BASE_RANGE_STRING0x00000100)
10824 return try_rval64_to_str(value, (const range_string *) hfinfo->strings);
10825
10826 if (hfinfo->display & BASE_UNIT_STRING0x00001000)
10827 return unit_name_string_get_value64(value, (const struct unit_name_string*) hfinfo->strings);
10828
10829 /* If this is reached somebody registered a 64-bit field with a 32-bit
10830 * value-string, which isn't right. */
10831 REPORT_DISSECTOR_BUG("field %s is a 64-bit field with a 32-bit value_string",proto_report_dissector_bug("field %s is a 64-bit field with a 32-bit value_string"
, hfinfo->abbrev)
10832 hfinfo->abbrev)proto_report_dissector_bug("field %s is a 64-bit field with a 32-bit value_string"
, hfinfo->abbrev)
;
10833
10834 /* This is necessary to squelch MSVC errors; is there
10835 any way to tell it that DISSECTOR_ASSERT_NOT_REACHED()
10836 never returns? */
10837 return NULL((void*)0);
10838}
10839
10840static const char *
10841hf_try_double_val_to_str(double value, const header_field_info *hfinfo)
10842{
10843 if (hfinfo->display & BASE_UNIT_STRING0x00001000)
10844 return unit_name_string_get_double(value, (const struct unit_name_string*)hfinfo->strings);
10845
10846 REPORT_DISSECTOR_BUG("field %s (FT_DOUBLE) has no base_unit_string", hfinfo->abbrev)proto_report_dissector_bug("field %s (FT_DOUBLE) has no base_unit_string"
, hfinfo->abbrev)
;
10847
10848 /* This is necessary to squelch MSVC errors; is there
10849 any way to tell it that DISSECTOR_ASSERT_NOT_REACHED()
10850 never returns? */
10851 return NULL((void*)0);
10852}
10853
10854static const char *
10855hf_try_val_to_str_const(uint32_t value, const header_field_info *hfinfo, const char *unknown_str)
10856{
10857 const char *str = hf_try_val_to_str(value, hfinfo);
10858
10859 return (str) ? str : unknown_str;
10860}
10861
10862static const char *
10863hf_try_val64_to_str_const(uint64_t value, const header_field_info *hfinfo, const char *unknown_str)
10864{
10865 const char *str = hf_try_val64_to_str(value, hfinfo);
10866
10867 return (str) ? str : unknown_str;
10868}
10869
10870/* Fills data for bitfield chars with val_strings */
10871static void
10872fill_label_bitfield_char(const field_info *fi, char *label_str, size_t *value_pos)
10873{
10874 char *p;
10875 unsigned bitfield_byte_length;
10876 int bitwidth;
10877 uint32_t unshifted_value;
10878 uint32_t value;
10879
10880 char buf[32];
10881 const char *out;
10882
10883 const header_field_info *hfinfo = fi->hfinfo;
10884
10885 /* Figure out the bit width */
10886 bitwidth = hfinfo_container_bitwidth(hfinfo);
10887
10888 /* Un-shift bits */
10889 value = fvalue_get_uinteger(fi->value);
10890
10891 unshifted_value = value;
10892 if (hfinfo->bitmask) {
10893 unshifted_value <<= hfinfo_bitshift(hfinfo);
10894 }
10895
10896 /* Create the bitfield first */
10897 p = decode_bitfield_value(label_str, unshifted_value, hfinfo->bitmask, bitwidth);
10898 bitfield_byte_length = (unsigned) (p - label_str);
10899
10900 /* Fill in the textual info using stored (shifted) value */
10901 if (hfinfo->display == BASE_CUSTOM) {
10902 char tmp[ITEM_LABEL_LENGTH240];
10903 const custom_fmt_func_t fmtfunc = (const custom_fmt_func_t)hfinfo->strings;
10904
10905 DISSECTOR_ASSERT(fmtfunc)((void) ((fmtfunc) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 10905, "fmtfunc"))))
;
10906 fmtfunc(tmp, value);
10907 label_fill(label_str, bitfield_byte_length, hfinfo, tmp, value_pos);
10908 }
10909 else if (hfinfo->strings) {
10910 const char *val_str = hf_try_val_to_str_const(value, hfinfo, "Unknown");
10911
10912 out = hfinfo_char_vals_format(hfinfo, buf, value);
10913 if (out == NULL((void*)0)) /* BASE_NONE so don't put integer in descr */
10914 label_fill(label_str, bitfield_byte_length, hfinfo, val_str, value_pos);
10915 else
10916 label_fill_descr(label_str, bitfield_byte_length, hfinfo, val_str, out, value_pos);
10917 }
10918 else {
10919 out = hfinfo_char_value_format(hfinfo, buf, value);
10920
10921 label_fill(label_str, bitfield_byte_length, hfinfo, out, value_pos);
10922 }
10923}
10924
10925/* Fills data for bitfield ints with val_strings */
10926static void
10927fill_label_bitfield(const field_info *fi, char *label_str, size_t *value_pos, bool_Bool is_signed)
10928{
10929 char *p;
10930 unsigned bitfield_byte_length;
10931 int bitwidth;
10932 uint32_t value, unshifted_value;
10933 char buf[NUMBER_LABEL_LENGTH80];
10934 const char *out;
10935
10936 const header_field_info *hfinfo = fi->hfinfo;
10937
10938 /* Figure out the bit width */
10939 if (fi->flags & FI_VARINT0x00040000)
10940 bitwidth = fi->length*8;
10941 else
10942 bitwidth = hfinfo_container_bitwidth(hfinfo);
10943
10944 /* Un-shift bits */
10945 if (is_signed)
10946 value = fvalue_get_sinteger(fi->value);
10947 else
10948 value = fvalue_get_uinteger(fi->value);
10949
10950 unshifted_value = value;
10951 if (hfinfo->bitmask) {
10952 unshifted_value <<= hfinfo_bitshift(hfinfo);
10953 }
10954
10955 /* Create the bitfield first */
10956 if (fi->flags & FI_VARINT0x00040000)
10957 p = decode_bitfield_varint_value(label_str, unshifted_value, hfinfo->bitmask, bitwidth);
10958 else
10959 p = decode_bitfield_value(label_str, unshifted_value, hfinfo->bitmask, bitwidth);
10960 bitfield_byte_length = (unsigned) (p - label_str);
10961
10962 /* Fill in the textual info using stored (shifted) value */
10963 if (hfinfo->display == BASE_CUSTOM) {
10964 char tmp[ITEM_LABEL_LENGTH240];
10965 const custom_fmt_func_t fmtfunc = (const custom_fmt_func_t)hfinfo->strings;
10966
10967 DISSECTOR_ASSERT(fmtfunc)((void) ((fmtfunc) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 10967, "fmtfunc"))))
;
10968 fmtfunc(tmp, value);
10969 label_fill(label_str, bitfield_byte_length, hfinfo, tmp, value_pos);
10970 }
10971 else if (hfinfo->strings) {
10972 const char *val_str = hf_try_val_to_str(value, hfinfo);
10973
10974 out = hfinfo_number_vals_format(hfinfo, buf, value);
10975 if (hfinfo->display & BASE_SPECIAL_VALS0x00008000) {
10976 /*
10977 * Unique values only display value_string string
10978 * if there is a match. Otherwise it's just a number
10979 */
10980 if (val_str) {
10981 label_fill_descr(label_str, bitfield_byte_length, hfinfo, val_str, out, value_pos);
10982 } else {
10983 label_fill(label_str, bitfield_byte_length, hfinfo, out, value_pos);
10984 }
10985 } else {
10986 if (val_str == NULL((void*)0))
10987 val_str = "Unknown";
10988
10989 if (out == NULL((void*)0)) /* BASE_NONE so don't put integer in descr */
10990 label_fill(label_str, bitfield_byte_length, hfinfo, val_str, value_pos);
10991 else
10992 label_fill_descr(label_str, bitfield_byte_length, hfinfo, val_str, out, value_pos);
10993 }
10994 }
10995 else {
10996 out = hfinfo_number_value_format(hfinfo, buf, value);
10997
10998 label_fill(label_str, bitfield_byte_length, hfinfo, out, value_pos);
10999 }
11000}
11001
11002static void
11003fill_label_bitfield64(const field_info *fi, char *label_str, size_t *value_pos, bool_Bool is_signed)
11004{
11005 char *p;
11006 unsigned bitfield_byte_length;
11007 int bitwidth;
11008 uint64_t value, unshifted_value;
11009 char buf[NUMBER_LABEL_LENGTH80];
11010 const char *out;
11011
11012 const header_field_info *hfinfo = fi->hfinfo;
11013
11014 /* Figure out the bit width */
11015 if (fi->flags & FI_VARINT0x00040000)
11016 bitwidth = fi->length*8;
11017 else
11018 bitwidth = hfinfo_container_bitwidth(hfinfo);
11019
11020 /* Un-shift bits */
11021 if (is_signed)
11022 value = fvalue_get_sinteger64(fi->value);
11023 else
11024 value = fvalue_get_uinteger64(fi->value);
11025
11026 unshifted_value = value;
11027 if (hfinfo->bitmask) {
11028 unshifted_value <<= hfinfo_bitshift(hfinfo);
11029 }
11030
11031 /* Create the bitfield first */
11032 if (fi->flags & FI_VARINT0x00040000)
11033 p = decode_bitfield_varint_value(label_str, unshifted_value, hfinfo->bitmask, bitwidth);
11034 else
11035 p = decode_bitfield_value(label_str, unshifted_value, hfinfo->bitmask, bitwidth);
11036 bitfield_byte_length = (unsigned) (p - label_str);
11037
11038 /* Fill in the textual info using stored (shifted) value */
11039 if (hfinfo->display == BASE_CUSTOM) {
11040 char tmp[ITEM_LABEL_LENGTH240];
11041 const custom_fmt_func_64_t fmtfunc64 = (const custom_fmt_func_64_t)hfinfo->strings;
11042
11043 DISSECTOR_ASSERT(fmtfunc64)((void) ((fmtfunc64) ? (void)0 : (proto_report_dissector_bug(
"%s:%u: failed assertion \"%s\"", "epan/proto.c", 11043, "fmtfunc64"
))))
;
11044 fmtfunc64(tmp, value);
11045 label_fill(label_str, bitfield_byte_length, hfinfo, tmp, value_pos);
11046 }
11047 else if (hfinfo->strings) {
11048 const char *val_str = hf_try_val64_to_str(value, hfinfo);
11049
11050 out = hfinfo_number_vals_format64(hfinfo, buf, value);
11051 if (hfinfo->display & BASE_SPECIAL_VALS0x00008000) {
11052 /*
11053 * Unique values only display value_string string
11054 * if there is a match. Otherwise it's just a number
11055 */
11056 if (val_str) {
11057 label_fill_descr(label_str, bitfield_byte_length, hfinfo, val_str, out, value_pos);
11058 } else {
11059 label_fill(label_str, bitfield_byte_length, hfinfo, out, value_pos);
11060 }
11061 } else {
11062 if (val_str == NULL((void*)0))
11063 val_str = "Unknown";
11064
11065 if (out == NULL((void*)0)) /* BASE_NONE so don't put integer in descr */
11066 label_fill(label_str, bitfield_byte_length, hfinfo, val_str, value_pos);
11067 else
11068 label_fill_descr(label_str, bitfield_byte_length, hfinfo, val_str, out, value_pos);
11069 }
11070 }
11071 else {
11072 out = hfinfo_number_value_format64(hfinfo, buf, value);
11073
11074 label_fill(label_str, bitfield_byte_length, hfinfo, out, value_pos);
11075 }
11076}
11077
11078static void
11079fill_label_char(const field_info *fi, char *label_str, size_t *value_pos)
11080{
11081 const header_field_info *hfinfo = fi->hfinfo;
11082 uint32_t value;
11083
11084 char buf[32];
11085 const char *out;
11086
11087 value = fvalue_get_uinteger(fi->value);
11088
11089 /* Fill in the textual info */
11090 if (hfinfo->display == BASE_CUSTOM) {
11091 char tmp[ITEM_LABEL_LENGTH240];
11092 const custom_fmt_func_t fmtfunc = (const custom_fmt_func_t)hfinfo->strings;
11093
11094 DISSECTOR_ASSERT(fmtfunc)((void) ((fmtfunc) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 11094, "fmtfunc"))))
;
11095 fmtfunc(tmp, value);
11096 label_fill(label_str, 0, hfinfo, tmp, value_pos);
11097 }
11098 else if (hfinfo->strings) {
11099 const char *val_str = hf_try_val_to_str_const(value, hfinfo, "Unknown");
11100
11101 out = hfinfo_char_vals_format(hfinfo, buf, value);
11102 label_fill_descr(label_str, 0, hfinfo, val_str, out, value_pos);
11103 }
11104 else {
11105 out = hfinfo_char_value_format(hfinfo, buf, value);
11106
11107 label_fill(label_str, 0, hfinfo, out, value_pos);
11108 }
11109}
11110
11111static void
11112fill_label_number(const field_info *fi, char *label_str, size_t *value_pos, bool_Bool is_signed)
11113{
11114 const header_field_info *hfinfo = fi->hfinfo;
11115 uint32_t value;
11116
11117 char buf[NUMBER_LABEL_LENGTH80];
11118 const char *out;
11119
11120 if (is_signed)
11121 value = fvalue_get_sinteger(fi->value);
11122 else
11123 value = fvalue_get_uinteger(fi->value);
11124
11125 /* Fill in the textual info */
11126 if (hfinfo->display == BASE_CUSTOM) {
11127 char tmp[ITEM_LABEL_LENGTH240];
11128 const custom_fmt_func_t fmtfunc = (const custom_fmt_func_t)hfinfo->strings;
11129
11130 DISSECTOR_ASSERT(fmtfunc)((void) ((fmtfunc) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 11130, "fmtfunc"))))
;
11131 fmtfunc(tmp, value);
11132 label_fill(label_str, 0, hfinfo, tmp, value_pos);
11133 }
11134 else if (hfinfo->strings && hfinfo->type != FT_FRAMENUM) {
11135 /*
11136 * It makes no sense to have a value-string table for a
11137 * frame-number field - they're just integers giving
11138 * the ordinal frame number.
11139 */
11140 const char *val_str = hf_try_val_to_str(value, hfinfo);
11141
11142 out = hfinfo_number_vals_format(hfinfo, buf, value);
11143 if (hfinfo->display & BASE_SPECIAL_VALS0x00008000) {
11144 /*
11145 * Unique values only display value_string string
11146 * if there is a match. Otherwise it's just a number
11147 */
11148 if (val_str) {
11149 label_fill_descr(label_str, 0, hfinfo, val_str, out, value_pos);
11150 } else {
11151 label_fill(label_str, 0, hfinfo, out, value_pos);
11152 }
11153 } else {
11154 if (val_str == NULL((void*)0))
11155 val_str = "Unknown";
11156
11157 if (out == NULL((void*)0)) /* BASE_NONE so don't put integer in descr */
11158 label_fill(label_str, 0, hfinfo, val_str, value_pos);
11159 else
11160 label_fill_descr(label_str, 0, hfinfo, val_str, out, value_pos);
11161 }
11162 }
11163 else if (IS_BASE_PORT(hfinfo->display)(((hfinfo->display)==BASE_PT_UDP||(hfinfo->display)==BASE_PT_TCP
||(hfinfo->display)==BASE_PT_DCCP||(hfinfo->display)==BASE_PT_SCTP
))
) {
11164 char tmp[ITEM_LABEL_LENGTH240];
11165
11166 port_with_resolution_to_str_buf(tmp, sizeof(tmp),
11167 display_to_port_type((field_display_e)hfinfo->display), value);
11168 label_fill(label_str, 0, hfinfo, tmp, value_pos);
11169 }
11170 else {
11171 out = hfinfo_number_value_format(hfinfo, buf, value);
11172
11173 label_fill(label_str, 0, hfinfo, out, value_pos);
11174 }
11175}
11176
11177static void
11178fill_label_number64(const field_info *fi, char *label_str, size_t *value_pos, bool_Bool is_signed)
11179{
11180 const header_field_info *hfinfo = fi->hfinfo;
11181 uint64_t value;
11182
11183 char buf[NUMBER_LABEL_LENGTH80];
11184 const char *out;
11185
11186 if (is_signed)
11187 value = fvalue_get_sinteger64(fi->value);
11188 else
11189 value = fvalue_get_uinteger64(fi->value);
11190
11191 /* Fill in the textual info */
11192 if (hfinfo->display == BASE_CUSTOM) {
11193 char tmp[ITEM_LABEL_LENGTH240];
11194 const custom_fmt_func_64_t fmtfunc64 = (const custom_fmt_func_64_t)hfinfo->strings;
11195
11196 DISSECTOR_ASSERT(fmtfunc64)((void) ((fmtfunc64) ? (void)0 : (proto_report_dissector_bug(
"%s:%u: failed assertion \"%s\"", "epan/proto.c", 11196, "fmtfunc64"
))))
;
11197 fmtfunc64(tmp, value);
11198 label_fill(label_str, 0, hfinfo, tmp, value_pos);
11199 }
11200 else if (hfinfo->strings) {
11201 const char *val_str = hf_try_val64_to_str(value, hfinfo);
11202
11203 out = hfinfo_number_vals_format64(hfinfo, buf, value);
11204 if (hfinfo->display & BASE_SPECIAL_VALS0x00008000) {
11205 /*
11206 * Unique values only display value_string string
11207 * if there is a match. Otherwise it's just a number
11208 */
11209 if (val_str) {
11210 label_fill_descr(label_str, 0, hfinfo, val_str, out, value_pos);
11211 } else {
11212 label_fill(label_str, 0, hfinfo, out, value_pos);
11213 }
11214 } else {
11215 if (val_str == NULL((void*)0))
11216 val_str = "Unknown";
11217
11218 if (out == NULL((void*)0)) /* BASE_NONE so don't put integer in descr */
11219 label_fill(label_str, 0, hfinfo, val_str, value_pos);
11220 else
11221 label_fill_descr(label_str, 0, hfinfo, val_str, out, value_pos);
11222 }
11223 }
11224 else {
11225 out = hfinfo_number_value_format64(hfinfo, buf, value);
11226
11227 label_fill(label_str, 0, hfinfo, out, value_pos);
11228 }
11229}
11230
11231static size_t
11232fill_display_label_float(const field_info *fi, char *label_str, const int label_str_size)
11233{
11234 int display;
11235 int n;
11236 double value;
11237
11238 if (label_str_size < 12) {
11239 /* Not enough room to write an entire floating point value. */
11240 return 0;
11241 }
11242
11243 display = FIELD_DISPLAY(fi->hfinfo->display)((fi->hfinfo->display) & 0xFF);
11244 value = fvalue_get_floating(fi->value);
11245
11246 if (display == BASE_CUSTOM) {
11247 const custom_fmt_func_double_t fmtfunc = (const custom_fmt_func_double_t)fi->hfinfo->strings;
11248 DISSECTOR_ASSERT(fmtfunc)((void) ((fmtfunc) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 11248, "fmtfunc"))))
;
11249 fmtfunc(label_str, value);
11250 return strlen(label_str);
11251 }
11252
11253 switch (display) {
11254 case BASE_NONE:
11255 if (fi->hfinfo->type == FT_FLOAT) {
11256 n = snprintf(label_str, label_str_size, "%.*g", FLT_DIG6, value);
11257 } else {
11258 n = (int)strlen(dtoa_g_fmt(label_str, value));
11259 }
11260 break;
11261 case BASE_DEC:
11262 /* XXX - BASE_DEC is a bad choice for FT_DOUBLE, in that
11263 * it can require 317 characters for -DBL_MAX, that is,
11264 * 1 + 309 + 1 + 6 for sign + 10^308 + decimal + frac,
11265 * and then one more for the \0 terminator, and our
11266 * standard label width is 240. */
11267 n = snprintf(label_str, label_str_size, "%f", value);
11268 break;
11269 case BASE_HEX:
11270 n = snprintf(label_str, label_str_size, "%a", value);
11271 break;
11272 case BASE_EXP:
11273 n = snprintf(label_str, label_str_size, "%e", value);
11274 break;
11275 default:
11276 ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 11276
, __func__, "assertion \"not reached\" failed")
;
11277 }
11278 if (n < 0) {
11279 return 0; /* error */
11280 }
11281 if (n >= label_str_size) {
11282 /* XXX - We should perhaps do something other than a console
11283 * warning. */
11284 ws_warning("label length too small")do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 11284, __func__, "label length too small"); } } while (0)
;
11285 return strlen(label_str);
11286 }
11287 if ((fi->hfinfo->strings) && (fi->hfinfo->display & BASE_UNIT_STRING0x00001000)) {
11288 const char *hf_str_val;
11289 hf_str_val = hf_try_double_val_to_str(value, fi->hfinfo);
11290 n += proto_strlcpy(label_str + n, hf_str_val, label_str_size - n);
11291 if (n >= label_str_size) {
11292 ws_warning("label length too small")do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 11292, __func__, "label length too small"); } } while (0)
;
11293 return strlen(label_str);
11294 }
11295 }
11296
11297 return n;
11298}
11299
11300void
11301fill_label_float(const field_info *fi, char *label_str, size_t *value_pos)
11302{
11303 char tmp[ITEM_LABEL_LENGTH240];
11304
11305 fill_display_label_float(fi, tmp, ITEM_LABEL_LENGTH240);
11306 label_fill(label_str, 0, fi->hfinfo, tmp, value_pos);
11307}
11308
11309static size_t
11310fill_display_label_ieee_11073_float(const field_info *fi, char *label_str, const int label_str_size)
11311{
11312 int display;
11313 size_t pos = 0;
11314 double value;
11315 char* tmp_str;
11316
11317 if (label_str_size < 12) {
11318 /* Not enough room to write an entire floating point value. */
11319 return 0;
11320 }
11321
11322 display = FIELD_DISPLAY(fi->hfinfo->display)((fi->hfinfo->display) & 0xFF);
11323 tmp_str = fvalue_to_string_repr(NULL((void*)0), fi->value, FTREPR_DISPLAY, display);
11324 pos = label_concat(label_str, pos, (const uint8_t*)tmp_str)ws_label_strcpy(label_str, 240, pos, (const uint8_t*)tmp_str,
0)
;
11325 wmem_free(NULL((void*)0), tmp_str);
11326
11327 if ((fi->hfinfo->strings) && (fi->hfinfo->display & BASE_UNIT_STRING0x00001000)) {
11328 const char *hf_str_val;
11329 fvalue_to_double(fi->value, &value);
11330 hf_str_val = unit_name_string_get_double(value, (const struct unit_name_string*)fi->hfinfo->strings);
11331 pos = label_concat(label_str, pos, (const uint8_t*)hf_str_val)ws_label_strcpy(label_str, 240, pos, (const uint8_t*)hf_str_val
, 0)
;
11332 }
11333 if ((int)pos > label_str_size) {
11334 ws_warning("label length too small")do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 11334, __func__, "label length too small"); } } while (0)
;
11335 return strlen(label_str);
11336 }
11337
11338 return pos;
11339}
11340
11341void
11342fill_label_ieee_11073_float(const field_info *fi, char *label_str, size_t *value_pos)
11343{
11344 char tmp[ITEM_LABEL_LENGTH240];
11345
11346 fill_display_label_ieee_11073_float(fi, tmp, ITEM_LABEL_LENGTH240);
11347 label_fill(label_str, 0, fi->hfinfo, tmp, value_pos);
11348}
11349
11350int
11351hfinfo_bitshift(const header_field_info *hfinfo)
11352{
11353 return ws_ctz(hfinfo->bitmask);
11354}
11355
11356
11357static int
11358hfinfo_bitoffset(const header_field_info *hfinfo)
11359{
11360 if (!hfinfo->bitmask) {
11361 return 0;
11362 }
11363
11364 /* ilog2 = first set bit, counting 0 as the last bit; we want 0
11365 * as the first bit */
11366 return hfinfo_container_bitwidth(hfinfo) - 1 - ws_ilog2(hfinfo->bitmask);
11367}
11368
11369static int
11370hfinfo_mask_bitwidth(const header_field_info *hfinfo)
11371{
11372 if (!hfinfo->bitmask) {
11373 return 0;
11374 }
11375
11376 /* ilog2 = first set bit, ctz = last set bit */
11377 return ws_ilog2(hfinfo->bitmask) - ws_ctz(hfinfo->bitmask) + 1;
11378}
11379
11380static int
11381hfinfo_type_bitwidth(enum ftenum type)
11382{
11383 int bitwidth = 0;
11384
11385 switch (type) {
11386 case FT_CHAR:
11387 case FT_UINT8:
11388 case FT_INT8:
11389 bitwidth = 8;
11390 break;
11391 case FT_UINT16:
11392 case FT_INT16:
11393 bitwidth = 16;
11394 break;
11395 case FT_UINT24:
11396 case FT_INT24:
11397 bitwidth = 24;
11398 break;
11399 case FT_UINT32:
11400 case FT_INT32:
11401 bitwidth = 32;
11402 break;
11403 case FT_UINT40:
11404 case FT_INT40:
11405 bitwidth = 40;
11406 break;
11407 case FT_UINT48:
11408 case FT_INT48:
11409 bitwidth = 48;
11410 break;
11411 case FT_UINT56:
11412 case FT_INT56:
11413 bitwidth = 56;
11414 break;
11415 case FT_UINT64:
11416 case FT_INT64:
11417 bitwidth = 64;
11418 break;
11419 default:
11420 DISSECTOR_ASSERT_NOT_REACHED()(proto_report_dissector_bug("%s:%u: failed assertion \"DISSECTOR_ASSERT_NOT_REACHED\""
, "epan/proto.c", 11420))
;
11421 ;
11422 }
11423 return bitwidth;
11424}
11425
11426
11427static int
11428hfinfo_container_bitwidth(const header_field_info *hfinfo)
11429{
11430 if (!hfinfo->bitmask) {
11431 return 0;
11432 }
11433
11434 if (hfinfo->type == FT_BOOLEAN) {
11435 return hfinfo->display; /* hacky? :) */
11436 }
11437
11438 return hfinfo_type_bitwidth(hfinfo->type);
11439}
11440
11441static int
11442hfinfo_hex_digits(const header_field_info *hfinfo)
11443{
11444 int bitwidth;
11445
11446 /* If we have a bitmask, hfinfo->type is the width of the container, so not
11447 * appropriate to determine the number of hex digits for the field.
11448 * So instead, we compute it from the bitmask.
11449 */
11450 if (hfinfo->bitmask != 0) {
11451 bitwidth = hfinfo_mask_bitwidth(hfinfo);
11452 } else {
11453 bitwidth = hfinfo_type_bitwidth(hfinfo->type);
11454 }
11455
11456 /* Divide by 4, rounding up, to get number of hex digits. */
11457 return (bitwidth + 3) / 4;
11458}
11459
11460const char *
11461hfinfo_char_value_format_display(int display, char buf[7], uint32_t value)
11462{
11463 char *ptr = &buf[6];
11464 static const char hex_digits[16] =
11465 { '0', '1', '2', '3', '4', '5', '6', '7',
11466 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
11467
11468 *ptr = '\0';
11469 *(--ptr) = '\'';
11470 /* Properly format value */
11471 if (g_ascii_isprint(value)((g_ascii_table[(guchar) (value)] & G_ASCII_PRINT) != 0)) {
11472 /*
11473 * Printable, so just show the character, and, if it needs
11474 * to be escaped, escape it.
11475 */
11476 *(--ptr) = value;
11477 if (value == '\\' || value == '\'')
11478 *(--ptr) = '\\';
11479 } else {
11480 /*
11481 * Non-printable; show it as an escape sequence.
11482 */
11483 switch (value) {
11484
11485 case '\0':
11486 /*
11487 * Show a NUL with only one digit.
11488 */
11489 *(--ptr) = '0';
11490 break;
11491
11492 case '\a':
11493 case '\b':
11494 case '\f':
11495 case '\n':
11496 case '\r':
11497 case '\t':
11498 case '\v':
11499 *(--ptr) = value - '\a' + 'a';
11500 break;
11501
11502 default:
11503 switch (FIELD_DISPLAY(display)((display) & 0xFF)) {
11504
11505 case BASE_OCT:
11506 *(--ptr) = (value & 0x7) + '0';
11507 value >>= 3;
11508 *(--ptr) = (value & 0x7) + '0';
11509 value >>= 3;
11510 *(--ptr) = (value & 0x7) + '0';
11511 break;
11512
11513 case BASE_HEX:
11514 *(--ptr) = hex_digits[value & 0x0F];
11515 value >>= 4;
11516 *(--ptr) = hex_digits[value & 0x0F];
11517 *(--ptr) = 'x';
11518 break;
11519
11520 default:
11521 REPORT_DISSECTOR_BUG("Invalid base: %d", FIELD_DISPLAY(display))proto_report_dissector_bug("Invalid base: %d", ((display) &
0xFF))
;
11522 }
11523 }
11524 *(--ptr) = '\\';
11525 }
11526 *(--ptr) = '\'';
11527 return ptr;
11528}
11529
11530static const char *
11531hfinfo_number_value_format_display(const header_field_info *hfinfo, int display, char buf[NUMBER_LABEL_LENGTH80], uint32_t value)
11532{
11533 char *ptr = &buf[NUMBER_LABEL_LENGTH80-1];
11534 bool_Bool isint = FT_IS_INT(hfinfo->type)(((hfinfo->type) == FT_INT8 || (hfinfo->type) == FT_INT16
|| (hfinfo->type) == FT_INT24 || (hfinfo->type) == FT_INT32
) || ((hfinfo->type) == FT_INT40 || (hfinfo->type) == FT_INT48
|| (hfinfo->type) == FT_INT56 || (hfinfo->type) == FT_INT64
))
;
11535
11536 *ptr = '\0';
11537 /* Properly format value */
11538 switch (FIELD_DISPLAY(display)((display) & 0xFF)) {
11539 case BASE_DEC:
11540 return isint ? int_to_str_back(ptr, (int32_t) value) : uint_to_str_back(ptr, value);
11541
11542 case BASE_DEC_HEX:
11543 *(--ptr) = ')';
11544 ptr = hex_to_str_back_len(ptr, value, hfinfo_hex_digits(hfinfo));
11545 *(--ptr) = '(';
11546 *(--ptr) = ' ';
11547 ptr = isint ? int_to_str_back(ptr, (int32_t) value) : uint_to_str_back(ptr, value);
11548 return ptr;
11549
11550 case BASE_OCT:
11551 return oct_to_str_back(ptr, value);
11552
11553 case BASE_HEX:
11554 return hex_to_str_back_len(ptr, value, hfinfo_hex_digits(hfinfo));
11555
11556 case BASE_HEX_DEC:
11557 *(--ptr) = ')';
11558 ptr = isint ? int_to_str_back(ptr, (int32_t) value) : uint_to_str_back(ptr, value);
11559 *(--ptr) = '(';
11560 *(--ptr) = ' ';
11561 ptr = hex_to_str_back_len(ptr, value, hfinfo_hex_digits(hfinfo));
11562 return ptr;
11563
11564 case BASE_PT_UDP:
11565 case BASE_PT_TCP:
11566 case BASE_PT_DCCP:
11567 case BASE_PT_SCTP:
11568 port_with_resolution_to_str_buf(buf, NUMBER_LABEL_LENGTH80,
11569 display_to_port_type((field_display_e)display), value);
11570 return buf;
11571 case BASE_OUI:
11572 {
11573 uint8_t p_oui[3];
11574 const char *manuf_name;
11575
11576 p_oui[0] = value >> 16 & 0xFF;
11577 p_oui[1] = value >> 8 & 0xFF;
11578 p_oui[2] = value & 0xFF;
11579
11580 /* Attempt an OUI lookup. */
11581 manuf_name = uint_get_manuf_name_if_known(value);
11582 if (manuf_name == NULL((void*)0)) {
11583 /* Could not find an OUI. */
11584 snprintf(buf, NUMBER_LABEL_LENGTH80, "%02x:%02x:%02x", p_oui[0], p_oui[1], p_oui[2]);
11585 }
11586 else {
11587 /* Found an address string. */
11588 snprintf(buf, NUMBER_LABEL_LENGTH80, "%02x:%02x:%02x (%s)", p_oui[0], p_oui[1], p_oui[2], manuf_name);
11589 }
11590 return buf;
11591 }
11592
11593 default:
11594 REPORT_DISSECTOR_BUG("Invalid base: %d", FIELD_DISPLAY(display))proto_report_dissector_bug("Invalid base: %d", ((display) &
0xFF))
;
11595 }
11596 return ptr;
11597}
11598
11599static const char *
11600hfinfo_number_value_format_display64(const header_field_info *hfinfo, int display, char buf[NUMBER_LABEL_LENGTH80], uint64_t value)
11601{
11602 char *ptr = &buf[NUMBER_LABEL_LENGTH80-1];
11603 bool_Bool isint = FT_IS_INT(hfinfo->type)(((hfinfo->type) == FT_INT8 || (hfinfo->type) == FT_INT16
|| (hfinfo->type) == FT_INT24 || (hfinfo->type) == FT_INT32
) || ((hfinfo->type) == FT_INT40 || (hfinfo->type) == FT_INT48
|| (hfinfo->type) == FT_INT56 || (hfinfo->type) == FT_INT64
))
;
11604
11605 *ptr = '\0';
11606 /* Properly format value */
11607 switch (FIELD_DISPLAY(display)((display) & 0xFF)) {
11608 case BASE_DEC:
11609 return isint ? int64_to_str_back(ptr, (int64_t) value) : uint64_to_str_back(ptr, value);
11610
11611 case BASE_DEC_HEX:
11612 *(--ptr) = ')';
11613 ptr = hex64_to_str_back_len(ptr, value, hfinfo_hex_digits(hfinfo));
11614 *(--ptr) = '(';
11615 *(--ptr) = ' ';
11616 ptr = isint ? int64_to_str_back(ptr, (int64_t) value) : uint64_to_str_back(ptr, value);
11617 return ptr;
11618
11619 case BASE_OCT:
11620 return oct64_to_str_back(ptr, value);
11621
11622 case BASE_HEX:
11623 return hex64_to_str_back_len(ptr, value, hfinfo_hex_digits(hfinfo));
11624
11625 case BASE_HEX_DEC:
11626 *(--ptr) = ')';
11627 ptr = isint ? int64_to_str_back(ptr, (int64_t) value) : uint64_to_str_back(ptr, value);
11628 *(--ptr) = '(';
11629 *(--ptr) = ' ';
11630 ptr = hex64_to_str_back_len(ptr, value, hfinfo_hex_digits(hfinfo));
11631 return ptr;
11632
11633 default:
11634 REPORT_DISSECTOR_BUG("Invalid base: %d", FIELD_DISPLAY(display))proto_report_dissector_bug("Invalid base: %d", ((display) &
0xFF))
;
11635 }
11636
11637 return ptr;
11638}
11639
11640static const char *
11641hfinfo_number_value_format(const header_field_info *hfinfo, char buf[NUMBER_LABEL_LENGTH80], uint32_t value)
11642{
11643 int display = hfinfo->display;
11644
11645 if (hfinfo->type == FT_FRAMENUM) {
11646 /*
11647 * Frame numbers are always displayed in decimal.
11648 */
11649 display = BASE_DEC;
11650 }
11651
11652 return hfinfo_number_value_format_display(hfinfo, display, buf, value);
11653}
11654
11655static const char *
11656hfinfo_number_value_format64(const header_field_info *hfinfo, char buf[NUMBER_LABEL_LENGTH80], uint64_t value)
11657{
11658 int display = hfinfo->display;
11659
11660 if (hfinfo->type == FT_FRAMENUM) {
11661 /*
11662 * Frame numbers are always displayed in decimal.
11663 */
11664 display = BASE_DEC;
11665 }
11666
11667 return hfinfo_number_value_format_display64(hfinfo, display, buf, value);
11668}
11669
11670static const char *
11671hfinfo_char_value_format(const header_field_info *hfinfo, char buf[32], uint32_t value)
11672{
11673 /* Get the underlying BASE_ value */
11674 int display = FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF);
11675
11676 return hfinfo_char_value_format_display(display, buf, value);
11677}
11678
11679static const char *
11680hfinfo_numeric_value_format(const header_field_info *hfinfo, char buf[NUMBER_LABEL_LENGTH80], uint32_t value)
11681{
11682 /* Get the underlying BASE_ value */
11683 int display = FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF);
11684
11685 if (hfinfo->type == FT_FRAMENUM) {
11686 /*
11687 * Frame numbers are always displayed in decimal.
11688 */
11689 display = BASE_DEC;
11690 }
11691
11692 if (IS_BASE_PORT(display)(((display)==BASE_PT_UDP||(display)==BASE_PT_TCP||(display)==
BASE_PT_DCCP||(display)==BASE_PT_SCTP))
) {
11693 display = BASE_DEC;
11694 } else if (display == BASE_OUI) {
11695 display = BASE_HEX;
11696 }
11697
11698 switch (display) {
11699 case BASE_NONE:
11700 /* case BASE_DEC: */
11701 case BASE_DEC_HEX:
11702 case BASE_OCT: /* XXX, why we're changing BASE_OCT to BASE_DEC? */
11703 case BASE_CUSTOM:
11704 display = BASE_DEC;
11705 break;
11706
11707 /* case BASE_HEX: */
11708 case BASE_HEX_DEC:
11709 display = BASE_HEX;
11710 break;
11711 }
11712
11713 return hfinfo_number_value_format_display(hfinfo, display, buf, value);
11714}
11715
11716static const char *
11717hfinfo_numeric_value_format64(const header_field_info *hfinfo, char buf[NUMBER_LABEL_LENGTH80], uint64_t value)
11718{
11719 /* Get the underlying BASE_ value */
11720 int display = FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF);
11721
11722 if (hfinfo->type == FT_FRAMENUM) {
11723 /*
11724 * Frame numbers are always displayed in decimal.
11725 */
11726 display = BASE_DEC;
11727 }
11728
11729 switch (display) {
11730 case BASE_NONE:
11731 /* case BASE_DEC: */
11732 case BASE_DEC_HEX:
11733 case BASE_OCT: /* XXX, why we're changing BASE_OCT to BASE_DEC? */
11734 case BASE_CUSTOM:
11735 display = BASE_DEC;
11736 break;
11737
11738 /* case BASE_HEX: */
11739 case BASE_HEX_DEC:
11740 display = BASE_HEX;
11741 break;
11742 }
11743
11744 return hfinfo_number_value_format_display64(hfinfo, display, buf, value);
11745}
11746
11747static const char *
11748hfinfo_char_vals_format(const header_field_info *hfinfo, char buf[32], uint32_t value)
11749{
11750 /* Get the underlying BASE_ value */
11751 int display = FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF);
11752
11753 return hfinfo_char_value_format_display(display, buf, value);
11754}
11755
11756static const char *
11757hfinfo_number_vals_format(const header_field_info *hfinfo, char buf[NUMBER_LABEL_LENGTH80], uint32_t value)
11758{
11759 /* Get the underlying BASE_ value */
11760 int display = FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF);
11761
11762 if (display == BASE_NONE)
11763 return NULL((void*)0);
11764
11765 if (display == BASE_DEC_HEX)
11766 display = BASE_DEC;
11767 if (display == BASE_HEX_DEC)
11768 display = BASE_HEX;
11769
11770 return hfinfo_number_value_format_display(hfinfo, display, buf, value);
11771}
11772
11773static const char *
11774hfinfo_number_vals_format64(const header_field_info *hfinfo, char buf[NUMBER_LABEL_LENGTH80], uint64_t value)
11775{
11776 /* Get the underlying BASE_ value */
11777 int display = FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF);
11778
11779 if (display == BASE_NONE)
11780 return NULL((void*)0);
11781
11782 if (display == BASE_DEC_HEX)
11783 display = BASE_DEC;
11784 if (display == BASE_HEX_DEC)
11785 display = BASE_HEX;
11786
11787 return hfinfo_number_value_format_display64(hfinfo, display, buf, value);
11788}
11789
11790const char *
11791proto_registrar_get_name(const int n)
11792{
11793 header_field_info *hfinfo;
11794
11795 PROTO_REGISTRAR_GET_NTH(n, hfinfo)if((n == 0 || (unsigned)n > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 11795
, __func__, "Unregistered hf! index=%d", n); ((void) ((n >
0 && (unsigned)n < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 11795
, "n > 0 && (unsigned)n < gpa_hfinfo.len", "Unregistered hf."
)))) ; ((void) ((gpa_hfinfo.hfi[n] != ((void*)0)) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 11795, "gpa_hfinfo.hfi[n] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[n];
;
11796 return hfinfo->name;
11797}
11798
11799const char *
11800proto_registrar_get_abbrev(const int n)
11801{
11802 header_field_info *hfinfo;
11803
11804 PROTO_REGISTRAR_GET_NTH(n, hfinfo)if((n == 0 || (unsigned)n > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 11804
, __func__, "Unregistered hf! index=%d", n); ((void) ((n >
0 && (unsigned)n < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 11804
, "n > 0 && (unsigned)n < gpa_hfinfo.len", "Unregistered hf."
)))) ; ((void) ((gpa_hfinfo.hfi[n] != ((void*)0)) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 11804, "gpa_hfinfo.hfi[n] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[n];
;
11805 return hfinfo->abbrev;
11806}
11807
11808enum ftenum
11809proto_registrar_get_ftype(const int n)
11810{
11811 header_field_info *hfinfo;
11812
11813 PROTO_REGISTRAR_GET_NTH(n, hfinfo)if((n == 0 || (unsigned)n > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 11813
, __func__, "Unregistered hf! index=%d", n); ((void) ((n >
0 && (unsigned)n < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 11813
, "n > 0 && (unsigned)n < gpa_hfinfo.len", "Unregistered hf."
)))) ; ((void) ((gpa_hfinfo.hfi[n] != ((void*)0)) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 11813, "gpa_hfinfo.hfi[n] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[n];
;
11814 return hfinfo->type;
11815}
11816
11817int
11818proto_registrar_get_parent(const int n)
11819{
11820 header_field_info *hfinfo;
11821
11822 PROTO_REGISTRAR_GET_NTH(n, hfinfo)if((n == 0 || (unsigned)n > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 11822
, __func__, "Unregistered hf! index=%d", n); ((void) ((n >
0 && (unsigned)n < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 11822
, "n > 0 && (unsigned)n < gpa_hfinfo.len", "Unregistered hf."
)))) ; ((void) ((gpa_hfinfo.hfi[n] != ((void*)0)) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 11822, "gpa_hfinfo.hfi[n] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[n];
;
11823 return hfinfo->parent;
11824}
11825
11826bool_Bool
11827proto_registrar_is_protocol(const int n)
11828{
11829 header_field_info *hfinfo;
11830
11831 PROTO_REGISTRAR_GET_NTH(n, hfinfo)if((n == 0 || (unsigned)n > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 11831
, __func__, "Unregistered hf! index=%d", n); ((void) ((n >
0 && (unsigned)n < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 11831
, "n > 0 && (unsigned)n < gpa_hfinfo.len", "Unregistered hf."
)))) ; ((void) ((gpa_hfinfo.hfi[n] != ((void*)0)) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 11831, "gpa_hfinfo.hfi[n] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[n];
;
11832 return (((hfinfo->id != hf_text_only) && (hfinfo->parent == -1)) ? true1 : false0);
11833}
11834
11835/* Returns length of field in packet (not necessarily the length
11836 * in our internal representation, as in the case of IPv4).
11837 * 0 means undeterminable at time of registration
11838 * -1 means the field is not registered. */
11839int
11840proto_registrar_get_length(const int n)
11841{
11842 header_field_info *hfinfo;
11843
11844 PROTO_REGISTRAR_GET_NTH(n, hfinfo)if((n == 0 || (unsigned)n > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 11844
, __func__, "Unregistered hf! index=%d", n); ((void) ((n >
0 && (unsigned)n < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 11844
, "n > 0 && (unsigned)n < gpa_hfinfo.len", "Unregistered hf."
)))) ; ((void) ((gpa_hfinfo.hfi[n] != ((void*)0)) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 11844, "gpa_hfinfo.hfi[n] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[n];
;
11845 return ftype_wire_size(hfinfo->type);
11846}
11847
11848size_t
11849proto_registrar_get_count(struct proto_registrar_stats *stats)
11850{
11851 header_field_info *hfinfo;
11852
11853 // Index zero is not used. We have to skip it.
11854 size_t total_count = gpa_hfinfo.len - 1;
11855 if (stats == NULL((void*)0)) {
11856 return total_count;
11857 }
11858 for (uint32_t id = 1; id < gpa_hfinfo.len; id++) {
11859 if (gpa_hfinfo.hfi[id] == NULL((void*)0)) {
11860 stats->deregistered_count++;
11861 continue; /* This is a deregistered protocol or header field */
11862 }
11863
11864 PROTO_REGISTRAR_GET_NTH(id, hfinfo)if((id == 0 || (unsigned)id > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 11864
, __func__, "Unregistered hf! index=%d", id); ((void) ((id >
0 && (unsigned)id < gpa_hfinfo.len) ? (void)0 : (
proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 11864, "id > 0 && (unsigned)id < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[id] != ((
void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 11864, "gpa_hfinfo.hfi[id] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[id];
;
11865
11866 if (proto_registrar_is_protocol(id))
11867 stats->protocol_count++;
11868
11869 if (hfinfo->same_name_prev_id != -1)
11870 stats->same_name_count++;
11871 }
11872
11873 return total_count;
11874}
11875
11876/* Looks for a protocol or a field in a proto_tree. Returns true if
11877 * it exists anywhere, or false if it exists nowhere. */
11878bool_Bool
11879proto_check_for_protocol_or_field(const proto_tree* tree, const int id)
11880{
11881 GPtrArray *ptrs = proto_get_finfo_ptr_array(tree, id);
11882
11883 if (g_ptr_array_len(ptrs)((ptrs) ? (ptrs)->len : 0) > 0) {
11884 return true1;
11885 }
11886 else {
11887 return false0;
11888 }
11889}
11890
11891/* Return GPtrArray* of field_info pointers for all hfindex that appear in tree.
11892 * This only works if the hfindex was "primed" before the dissection
11893 * took place, as we just pass back the already-created GPtrArray*.
11894 * The caller should *not* free the GPtrArray*; proto_tree_free_node()
11895 * handles that. */
11896GPtrArray *
11897proto_get_finfo_ptr_array(const proto_tree *tree, const int id)
11898{
11899 if (!tree)
11900 return NULL((void*)0);
11901
11902 if (PTREE_DATA(tree)((tree)->tree_data)->interesting_hfids != NULL((void*)0))
11903 return (GPtrArray *)g_hash_table_lookup(PTREE_DATA(tree)((tree)->tree_data)->interesting_hfids,
11904 GINT_TO_POINTER(id)((gpointer) (glong) (id)));
11905 else
11906 return NULL((void*)0);
11907}
11908
11909bool_Bool
11910proto_tracking_interesting_fields(const proto_tree *tree)
11911{
11912 GHashTable *interesting_hfids;
11913
11914 if (!tree)
11915 return false0;
11916
11917 interesting_hfids = PTREE_DATA(tree)((tree)->tree_data)->interesting_hfids;
11918
11919 return (interesting_hfids != NULL((void*)0)) && g_hash_table_size(interesting_hfids);
11920}
11921
11922/* Helper struct for proto_find_info() and proto_all_finfos() */
11923typedef struct {
11924 GPtrArray *array;
11925 int id;
11926} ffdata_t;
11927
11928/* Helper function for proto_find_info() */
11929static bool_Bool
11930find_finfo(proto_node *node, void * data)
11931{
11932 field_info *fi = PNODE_FINFO(node)((node)->finfo);
11933 if (fi && fi->hfinfo) {
11934 if (fi->hfinfo->id == ((ffdata_t*)data)->id) {
11935 g_ptr_array_add(((ffdata_t*)data)->array, fi);
11936 }
11937 }
11938
11939 /* Don't stop traversing. */
11940 return false0;
11941}
11942
11943/* Helper function for proto_find_first_info() */
11944static bool_Bool
11945find_first_finfo(proto_node *node, void *data)
11946{
11947 field_info *fi = PNODE_FINFO(node)((node)->finfo);
11948 if (fi && fi->hfinfo) {
11949 if (fi->hfinfo->id == ((ffdata_t*)data)->id) {
11950 g_ptr_array_add(((ffdata_t*)data)->array, fi);
11951
11952 /* Stop traversing. */
11953 return true1;
11954 }
11955 }
11956
11957 /* Continue traversing. */
11958 return false0;
11959}
11960
11961/* Return GPtrArray* of field_info pointers for all hfindex that appear in a tree.
11962* This works on any proto_tree, primed or unprimed, but actually searches
11963* the tree, so it is slower than using proto_get_finfo_ptr_array on a primed tree.
11964* The caller does need to free the returned GPtrArray with
11965* g_ptr_array_free(<array>, true).
11966*/
11967GPtrArray *
11968proto_find_finfo(proto_tree *tree, const int id)
11969{
11970 ffdata_t ffdata;
11971
11972 ffdata.array = g_ptr_array_new();
11973 ffdata.id = id;
11974
11975 proto_tree_traverse_pre_order(tree, find_finfo, &ffdata);
11976
11977 return ffdata.array;
11978}
11979
11980/* Return GPtrArray* of first field_info pointers for the searched hfindex that appear in a tree.
11981* This works on any proto_tree, primed or unprimed, but actually searches
11982* the tree, so it is slower than using proto_get_finfo_ptr_array on a primed tree.
11983* The caller does need to free the returned GPtrArray with
11984* g_ptr_array_free(<array>, true).
11985*/
11986GPtrArray *
11987proto_find_first_finfo(proto_tree *tree, const int id)
11988{
11989 ffdata_t ffdata;
11990
11991 ffdata.array = g_ptr_array_new();
11992 ffdata.id = id;
11993
11994 proto_tree_traverse_pre_order(tree, find_first_finfo, &ffdata);
11995
11996 return ffdata.array;
11997}
11998
11999/* Helper function for proto_all_finfos() */
12000static bool_Bool
12001every_finfo(proto_node *node, void * data)
12002{
12003 field_info *fi = PNODE_FINFO(node)((node)->finfo);
12004 if (fi && fi->hfinfo) {
12005 g_ptr_array_add(((ffdata_t*)data)->array, fi);
12006 }
12007
12008 /* Don't stop traversing. */
12009 return false0;
12010}
12011
12012/* Return GPtrArray* of field_info pointers containing all hfindexes that appear in a tree.
12013 * The caller does need to free the returned GPtrArray with
12014 * g_ptr_array_free(<array>, true).
12015 */
12016GPtrArray *
12017proto_all_finfos(proto_tree *tree)
12018{
12019 ffdata_t ffdata;
12020
12021 /* Pre allocate enough space to hold all fields in most cases */
12022 ffdata.array = g_ptr_array_sized_new(512);
12023 ffdata.id = 0;
12024
12025 proto_tree_traverse_pre_order(tree, every_finfo, &ffdata);
12026
12027 return ffdata.array;
12028}
12029
12030
12031typedef struct {
12032 unsigned offset;
12033 field_info *finfo;
12034 tvbuff_t *tvb;
12035} offset_search_t;
12036
12037static bool_Bool
12038check_for_offset(proto_node *node, void * data)
12039{
12040 field_info *fi = PNODE_FINFO(node)((node)->finfo);
12041 offset_search_t *offsearch = (offset_search_t *)data;
12042
12043 /* !fi == the top most container node which holds nothing */
12044 if (fi && !proto_item_is_hidden(node) && !proto_item_is_generated(node) && fi->ds_tvb && offsearch->tvb == fi->ds_tvb) {
12045 if (offsearch->offset >= (unsigned) fi->start &&
12046 offsearch->offset < (unsigned) (fi->start + fi->length)) {
12047
12048 offsearch->finfo = fi;
12049 return false0; /* keep traversing */
12050 }
12051 }
12052 return false0; /* keep traversing */
12053}
12054
12055/* Search a proto_tree backwards (from leaves to root) looking for the field
12056 * whose start/length occupies 'offset' */
12057/* XXX - I couldn't find an easy way to search backwards, so I search
12058 * forwards, w/o stopping. Therefore, the last finfo I find will the be
12059 * the one I want to return to the user. This algorithm is inefficient
12060 * and could be re-done, but I'd have to handle all the children and
12061 * siblings of each node myself. When I have more time I'll do that.
12062 * (yeah right) */
12063field_info *
12064proto_find_field_from_offset(proto_tree *tree, unsigned offset, tvbuff_t *tvb)
12065{
12066 offset_search_t offsearch;
12067
12068 offsearch.offset = offset;
12069 offsearch.finfo = NULL((void*)0);
12070 offsearch.tvb = tvb;
12071
12072 proto_tree_traverse_pre_order(tree, check_for_offset, &offsearch);
12073
12074 return offsearch.finfo;
12075}
12076
12077typedef struct {
12078 unsigned length;
12079 char *buf;
12080} decoded_data_t;
12081
12082static bool_Bool
12083check_for_undecoded(proto_node *node, void * data)
12084{
12085 field_info *fi = PNODE_FINFO(node)((node)->finfo);
12086 decoded_data_t* decoded = (decoded_data_t*)data;
12087 unsigned i;
12088 unsigned byte;
12089 unsigned bit;
12090
12091 if (fi && fi->hfinfo->type != FT_PROTOCOL) {
12092 for (i = fi->start; i < fi->start + fi->length && i < decoded->length; i++) {
12093 byte = i / 8;
12094 bit = i % 8;
12095 decoded->buf[byte] |= (1 << bit);
12096 }
12097 }
12098
12099 return false0;
12100}
12101
12102char*
12103proto_find_undecoded_data(proto_tree *tree, unsigned length)
12104{
12105 decoded_data_t decoded;
12106 decoded.length = length;
12107 decoded.buf = (char*)wmem_alloc0(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool), length / 8 + 1);
12108
12109 proto_tree_traverse_pre_order(tree, check_for_undecoded, &decoded);
12110 return decoded.buf;
12111}
12112
12113/* Dumps the protocols in the registration database to stdout. An independent
12114 * program can take this output and format it into nice tables or HTML or
12115 * whatever.
12116 *
12117 * There is one record per line. The fields are tab-delimited.
12118 *
12119 * Field 1 = protocol name
12120 * Field 2 = protocol short name
12121 * Field 3 = protocol filter name
12122 * Field 4 = protocol enabled
12123 * Field 5 = protocol enabled by default
12124 * Field 6 = protocol can toggle
12125 */
12126void
12127proto_registrar_dump_protocols(void)
12128{
12129 protocol_t *protocol;
12130 int i;
12131 void *cookie = NULL((void*)0);
12132
12133
12134 i = proto_get_first_protocol(&cookie);
12135 while (i != -1) {
12136 protocol = find_protocol_by_id(i);
12137 printf("%s\t%s\t%s\t%c\t%c\t%c\n",
12138 protocol->name,
12139 protocol->short_name,
12140 protocol->filter_name,
12141 (proto_is_protocol_enabled_by_default(protocol) ? 'T' : 'F'),
12142 (proto_is_protocol_enabled(protocol) ? 'T' : 'F'),
12143 (proto_can_toggle_protocol(protocol->proto_id) ? 'T' : 'F'));
12144 i = proto_get_next_protocol(&cookie);
12145 }
12146}
12147
12148/* Dumps the value_strings, extended value string headers, range_strings
12149 * or true/false strings for fields that have them.
12150 * There is one record per line. Fields are tab-delimited.
12151 * There are four types of records: Value String, Extended Value String Header,
12152 * Range String and True/False String. The first field, 'V', 'E', 'R' or 'T', indicates
12153 * the type of record.
12154 *
12155 * Note that a record will be generated only if the value_string,... is referenced
12156 * in a registered hfinfo entry.
12157 *
12158 *
12159 * Value Strings
12160 * -------------
12161 * Field 1 = 'V'
12162 * Field 2 = Field abbreviation to which this value string corresponds
12163 * Field 3 = Integer value
12164 * Field 4 = String
12165 *
12166 * Extended Value String Headers
12167 * -----------------------------
12168 * Field 1 = 'E'
12169 * Field 2 = Field abbreviation to which this extended value string header corresponds
12170 * Field 3 = Extended Value String "Name"
12171 * Field 4 = Number of entries in the associated value_string array
12172 * Field 5 = Access Type: "Linear Search", "Binary Search", "Direct (indexed) Access"
12173 *
12174 * Range Strings
12175 * -------------
12176 * Field 1 = 'R'
12177 * Field 2 = Field abbreviation to which this range string corresponds
12178 * Field 3 = Integer value: lower bound
12179 * Field 4 = Integer value: upper bound
12180 * Field 5 = String
12181 *
12182 * True/False Strings
12183 * ------------------
12184 * Field 1 = 'T'
12185 * Field 2 = Field abbreviation to which this true/false string corresponds
12186 * Field 3 = True String
12187 * Field 4 = False String
12188 */
12189void
12190proto_registrar_dump_values(void)
12191{
12192 header_field_info *hfinfo;
12193 int i, len, vi;
12194 const value_string *vals;
12195 const val64_string *vals64;
12196 const range_string *range;
12197 const true_false_string *tfs;
12198 const unit_name_string *units;
12199
12200 len = gpa_hfinfo.len;
12201 for (i = 1; i < len ; i++) {
12202 if (gpa_hfinfo.hfi[i] == NULL((void*)0))
12203 continue; /* This is a deregistered protocol or field */
12204
12205 PROTO_REGISTRAR_GET_NTH(i, hfinfo)if((i == 0 || (unsigned)i > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 12205
, __func__, "Unregistered hf! index=%d", i); ((void) ((i >
0 && (unsigned)i < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 12205
, "i > 0 && (unsigned)i < gpa_hfinfo.len", "Unregistered hf."
)))) ; ((void) ((gpa_hfinfo.hfi[i] != ((void*)0)) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 12205, "gpa_hfinfo.hfi[i] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[i];
;
12206
12207 if (hfinfo->id == hf_text_only) {
12208 continue;
12209 }
12210
12211 /* ignore protocols */
12212 if (proto_registrar_is_protocol(i)) {
12213 continue;
12214 }
12215 /* process header fields */
12216#if 0 /* XXX: We apparently allow fields with the same name but with differing "strings" content */
12217 /*
12218 * If this field isn't at the head of the list of
12219 * fields with this name, skip this field - all
12220 * fields with the same name are really just versions
12221 * of the same field stored in different bits, and
12222 * should have the same type/radix/value list, and
12223 * just differ in their bit masks. (If a field isn't
12224 * a bitfield, but can be, say, 1 or 2 bytes long,
12225 * it can just be made FT_UINT16, meaning the
12226 * *maximum* length is 2 bytes, and be used
12227 * for all lengths.)
12228 */
12229 if (hfinfo->same_name_prev_id != -1)
12230 continue;
12231#endif
12232 vals = NULL((void*)0);
12233 vals64 = NULL((void*)0);
12234 range = NULL((void*)0);
12235 tfs = NULL((void*)0);
12236 units = NULL((void*)0);
12237
12238 if (hfinfo->strings != NULL((void*)0)) {
12239 if (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF) != BASE_CUSTOM &&
12240 (hfinfo->type == FT_CHAR ||
12241 hfinfo->type == FT_UINT8 ||
12242 hfinfo->type == FT_UINT16 ||
12243 hfinfo->type == FT_UINT24 ||
12244 hfinfo->type == FT_UINT32 ||
12245 hfinfo->type == FT_UINT40 ||
12246 hfinfo->type == FT_UINT48 ||
12247 hfinfo->type == FT_UINT56 ||
12248 hfinfo->type == FT_UINT64 ||
12249 hfinfo->type == FT_INT8 ||
12250 hfinfo->type == FT_INT16 ||
12251 hfinfo->type == FT_INT24 ||
12252 hfinfo->type == FT_INT32 ||
12253 hfinfo->type == FT_INT40 ||
12254 hfinfo->type == FT_INT48 ||
12255 hfinfo->type == FT_INT56 ||
12256 hfinfo->type == FT_INT64 ||
12257 hfinfo->type == FT_FLOAT ||
12258 hfinfo->type == FT_DOUBLE)) {
12259
12260 if (hfinfo->display & BASE_RANGE_STRING0x00000100) {
12261 range = (const range_string *)hfinfo->strings;
12262 } else if (hfinfo->display & BASE_EXT_STRING0x00000200) {
12263 if (hfinfo->display & BASE_VAL64_STRING0x00000400) {
12264 vals64 = VAL64_STRING_EXT_VS_P((const val64_string_ext *)hfinfo->strings)((const val64_string_ext *)hfinfo->strings)->_vs_p;
12265 } else {
12266 vals = VALUE_STRING_EXT_VS_P((const value_string_ext *)hfinfo->strings)((const value_string_ext *)hfinfo->strings)->_vs_p;
12267 }
12268 } else if (hfinfo->display & BASE_VAL64_STRING0x00000400) {
12269 vals64 = (const val64_string *)hfinfo->strings;
12270 } else if (hfinfo->display & BASE_UNIT_STRING0x00001000) {
12271 units = (const unit_name_string *)hfinfo->strings;
12272 } else {
12273 vals = (const value_string *)hfinfo->strings;
12274 }
12275 }
12276 else if (hfinfo->type == FT_BOOLEAN) {
12277 tfs = (const struct true_false_string *)hfinfo->strings;
12278 }
12279 }
12280
12281 /* Print value strings? */
12282 if (vals) {
12283 if (hfinfo->display & BASE_EXT_STRING0x00000200) {
12284 if (hfinfo->display & BASE_VAL64_STRING0x00000400) {
12285 val64_string_ext *vse_p = (val64_string_ext *)hfinfo->strings;
12286 if (!val64_string_ext_validate(vse_p)) {
12287 ws_warning("Invalid val64_string_ext ptr for: %s", hfinfo->abbrev)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 12287, __func__, "Invalid val64_string_ext ptr for: %s", hfinfo
->abbrev); } } while (0)
;
12288 continue;
12289 }
12290 try_val64_to_str_ext(0, vse_p); /* "prime" the extended val64_string */
12291 printf("E\t%s\t%u\t%s\t%s\n",
12292 hfinfo->abbrev,
12293 VAL64_STRING_EXT_VS_NUM_ENTRIES(vse_p)(vse_p)->_vs_num_entries,
12294 VAL64_STRING_EXT_VS_NAME(vse_p)(vse_p)->_vs_name,
12295 val64_string_ext_match_type_str(vse_p));
12296 } else {
12297 value_string_ext *vse_p = (value_string_ext *)hfinfo->strings;
12298 if (!value_string_ext_validate(vse_p)) {
12299 ws_warning("Invalid value_string_ext ptr for: %s", hfinfo->abbrev)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/proto.c"
, 12299, __func__, "Invalid value_string_ext ptr for: %s", hfinfo
->abbrev); } } while (0)
;
12300 continue;
12301 }
12302 try_val_to_str_ext(0, vse_p); /* "prime" the extended value_string */
12303 printf("E\t%s\t%u\t%s\t%s\n",
12304 hfinfo->abbrev,
12305 VALUE_STRING_EXT_VS_NUM_ENTRIES(vse_p)(vse_p)->_vs_num_entries,
12306 VALUE_STRING_EXT_VS_NAME(vse_p)(vse_p)->_vs_name,
12307 value_string_ext_match_type_str(vse_p));
12308 }
12309 }
12310 vi = 0;
12311 while (vals[vi].strptr) {
12312 /* Print in the proper base */
12313 if (hfinfo->type == FT_CHAR) {
12314 if (g_ascii_isprint(vals[vi].value)((g_ascii_table[(guchar) (vals[vi].value)] & G_ASCII_PRINT
) != 0)
) {
12315 printf("V\t%s\t'%c'\t%s\n",
12316 hfinfo->abbrev,
12317 vals[vi].value,
12318 vals[vi].strptr);
12319 } else {
12320 if (hfinfo->display == BASE_HEX) {
12321 printf("V\t%s\t'\\x%02x'\t%s\n",
12322 hfinfo->abbrev,
12323 vals[vi].value,
12324 vals[vi].strptr);
12325 }
12326 else {
12327 printf("V\t%s\t'\\%03o'\t%s\n",
12328 hfinfo->abbrev,
12329 vals[vi].value,
12330 vals[vi].strptr);
12331 }
12332 }
12333 } else {
12334 if (hfinfo->display == BASE_HEX) {
12335 printf("V\t%s\t0x%x\t%s\n",
12336 hfinfo->abbrev,
12337 vals[vi].value,
12338 vals[vi].strptr);
12339 }
12340 else {
12341 printf("V\t%s\t%u\t%s\n",
12342 hfinfo->abbrev,
12343 vals[vi].value,
12344 vals[vi].strptr);
12345 }
12346 }
12347 vi++;
12348 }
12349 }
12350 else if (vals64) {
12351 vi = 0;
12352 while (vals64[vi].strptr) {
12353 printf("V64\t%s\t%" PRIu64"l" "u" "\t%s\n",
12354 hfinfo->abbrev,
12355 vals64[vi].value,
12356 vals64[vi].strptr);
12357 vi++;
12358 }
12359 }
12360
12361 /* print range strings? */
12362 else if (range) {
12363 vi = 0;
12364 while (range[vi].strptr) {
12365 /* Print in the proper base */
12366 if (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF) == BASE_HEX) {
12367 printf("R\t%s\t0x%"PRIx64"l" "x""\t0x%"PRIx64"l" "x""\t%s\n",
12368 hfinfo->abbrev,
12369 range[vi].value_min,
12370 range[vi].value_max,
12371 range[vi].strptr);
12372 }
12373 else {
12374 printf("R\t%s\t%"PRIu64"l" "u""\t%"PRIu64"l" "u""\t%s\n",
12375 hfinfo->abbrev,
12376 range[vi].value_min,
12377 range[vi].value_max,
12378 range[vi].strptr);
12379 }
12380 vi++;
12381 }
12382 }
12383
12384 /* Print true/false strings? */
12385 else if (tfs) {
12386 printf("T\t%s\t%s\t%s\n", hfinfo->abbrev,
12387 tfs->true_string, tfs->false_string);
12388 }
12389 /* Print unit strings? */
12390 else if (units) {
12391 printf("U\t%s\t%s\t%s\n", hfinfo->abbrev,
12392 units->singular, units->plural ? units->plural : "(no plural)");
12393 }
12394 }
12395}
12396
12397/* Prints the number of registered fields.
12398 * Useful for determining an appropriate value for
12399 * PROTO_PRE_ALLOC_HF_FIELDS_MEM.
12400 *
12401 * Returns false if PROTO_PRE_ALLOC_HF_FIELDS_MEM is larger than or equal to
12402 * the number of fields, true otherwise.
12403 */
12404bool_Bool
12405proto_registrar_dump_fieldcount(void)
12406{
12407 struct proto_registrar_stats stats = {0, 0, 0};
12408 size_t total_count = proto_registrar_get_count(&stats);
12409
12410 printf("There are %zu header fields registered, of which:\n"
12411 "\t%zu are deregistered\n"
12412 "\t%zu are protocols\n"
12413 "\t%zu have the same name as another field\n\n",
12414 total_count, stats.deregistered_count, stats.protocol_count,
12415 stats.same_name_count);
12416
12417 printf("%d fields were pre-allocated.\n%s", PROTO_PRE_ALLOC_HF_FIELDS_MEM(300000+5000),
12418 (gpa_hfinfo.allocated_len > PROTO_PRE_ALLOC_HF_FIELDS_MEM(300000+5000)) ?
12419 "* * Please increase PROTO_PRE_ALLOC_HF_FIELDS_MEM (in epan/proto.c)! * *\n\n" :
12420 "\n");
12421
12422 printf("The header field table consumes %u KiB of memory.\n",
12423 (unsigned int)(gpa_hfinfo.allocated_len * sizeof(header_field_info *) / 1024));
12424 printf("The fields themselves consume %u KiB of memory.\n",
12425 (unsigned int)(gpa_hfinfo.len * sizeof(header_field_info) / 1024));
12426
12427 return (gpa_hfinfo.allocated_len > PROTO_PRE_ALLOC_HF_FIELDS_MEM(300000+5000));
12428}
12429
12430static void
12431elastic_add_base_mapping(json_dumper *dumper)
12432{
12433 json_dumper_set_member_name(dumper, "index_patterns");
12434 json_dumper_begin_array(dumper);
12435 // The index names from write_json_index() in print.c
12436 json_dumper_value_string(dumper, "packets-*");
12437 json_dumper_end_array(dumper);
12438
12439 json_dumper_set_member_name(dumper, "settings");
12440 json_dumper_begin_object(dumper);
12441 json_dumper_set_member_name(dumper, "index.mapping.total_fields.limit");
12442 json_dumper_value_anyf(dumper, "%d", 1000000);
12443 json_dumper_end_object(dumper);
12444}
12445
12446static char*
12447ws_type_to_elastic(unsigned type)
12448{
12449 switch(type) {
12450 case FT_INT8:
12451 return "byte";
12452 case FT_UINT8:
12453 case FT_INT16:
12454 return "short";
12455 case FT_UINT16:
12456 case FT_INT32:
12457 case FT_UINT24:
12458 case FT_INT24:
12459 return "integer";
12460 case FT_FRAMENUM:
12461 case FT_UINT32:
12462 case FT_UINT40:
12463 case FT_UINT48:
12464 case FT_UINT56:
12465 case FT_INT40:
12466 case FT_INT48:
12467 case FT_INT56:
12468 case FT_INT64:
12469 return "long";
12470 case FT_UINT64:
12471 return "unsigned long"; // ElasticSearch since 7.0, OpenSearch 2.8
12472 case FT_FLOAT:
12473 return "float";
12474 case FT_DOUBLE:
12475 case FT_RELATIVE_TIME: // "scaled_float" with "scaling_factor" 1e9 superior?
12476 return "double";
12477 case FT_IPv6:
12478 case FT_IPv4:
12479 return "ip";
12480 case FT_ABSOLUTE_TIME:
12481 return "date_nanos"; // This is a 64 bit integer of nanoseconds, so it does have a Y2262 problem
12482 case FT_BOOLEAN:
12483 return "boolean";
12484 default:
12485 return NULL((void*)0);
12486 }
12487}
12488
12489static char*
12490dot_to_underscore(char* str)
12491{
12492 unsigned i;
12493 for (i = 0; i < strlen(str); i++) {
12494 if (str[i] == '.')
12495 str[i] = '_';
12496 }
12497 return str;
12498}
12499
12500/* Dumps a mapping file for ElasticSearch
12501 * This is the v1 (legacy) _template API.
12502 * At some point it may need to be updated with the composable templates
12503 * introduced in Elasticsearch 7.8 (_index_template)
12504 */
12505void
12506proto_registrar_dump_elastic(const char* filter)
12507{
12508 header_field_info *hfinfo;
12509 header_field_info *parent_hfinfo;
12510 unsigned i;
12511 bool_Bool open_object = true1;
12512 const char* prev_proto = NULL((void*)0);
12513 char* str;
12514 char** protos = NULL((void*)0);
12515 char* proto;
12516 bool_Bool found;
12517 unsigned j;
12518 char* type;
12519 char* prev_item = NULL((void*)0);
12520
12521 /* We have filtering protocols. Extract them. */
12522 if (filter) {
12523 protos = g_strsplit(filter, ",", -1);
12524 }
12525
12526 /*
12527 * To help tracking down the json tree, objects have been appended with a comment:
12528 * n.label -> where n is the indentation level and label the name of the object
12529 */
12530
12531 json_dumper dumper = {
12532 .output_file = stdoutstdout,
12533 .flags = JSON_DUMPER_FLAGS_PRETTY_PRINT(1 << 0),
12534 };
12535 json_dumper_begin_object(&dumper); // 1.root
12536 elastic_add_base_mapping(&dumper);
12537
12538 json_dumper_set_member_name(&dumper, "mappings");
12539 json_dumper_begin_object(&dumper); // 2.mappings
12540
12541 json_dumper_set_member_name(&dumper, "properties");
12542 json_dumper_begin_object(&dumper); // 3.properties
12543 json_dumper_set_member_name(&dumper, "timestamp");
12544 json_dumper_begin_object(&dumper); // 4.timestamp
12545 json_dumper_set_member_name(&dumper, "type");
12546 json_dumper_value_string(&dumper, "date");
12547 json_dumper_end_object(&dumper); // 4.timestamp
12548
12549 json_dumper_set_member_name(&dumper, "layers");
12550 json_dumper_begin_object(&dumper); // 4.layers
12551 json_dumper_set_member_name(&dumper, "properties");
12552 json_dumper_begin_object(&dumper); // 5.properties
12553
12554 for (i = 1; i < gpa_hfinfo.len; i++) {
12555 if (gpa_hfinfo.hfi[i] == NULL((void*)0))
12556 continue; /* This is a deregistered protocol or header field */
12557
12558 PROTO_REGISTRAR_GET_NTH(i, hfinfo)if((i == 0 || (unsigned)i > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 12558
, __func__, "Unregistered hf! index=%d", i); ((void) ((i >
0 && (unsigned)i < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 12558
, "i > 0 && (unsigned)i < gpa_hfinfo.len", "Unregistered hf."
)))) ; ((void) ((gpa_hfinfo.hfi[i] != ((void*)0)) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 12558, "gpa_hfinfo.hfi[i] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[i];
;
12559
12560 /*
12561 * Skip the pseudo-field for "proto_tree_add_text()" since
12562 * we don't want it in the list of filterable protocols.
12563 */
12564 if (hfinfo->id == hf_text_only)
12565 continue;
12566
12567 if (!proto_registrar_is_protocol(i)) {
12568 PROTO_REGISTRAR_GET_NTH(hfinfo->parent, parent_hfinfo)if((hfinfo->parent == 0 || (unsigned)hfinfo->parent >
gpa_hfinfo.len) && wireshark_abort_on_dissector_bug)
ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 12568
, __func__, "Unregistered hf! index=%d", hfinfo->parent); (
(void) ((hfinfo->parent > 0 && (unsigned)hfinfo
->parent < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 12568
, "hfinfo->parent > 0 && (unsigned)hfinfo->parent < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
parent] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 12568
, "gpa_hfinfo.hfi[hfinfo->parent] != ((void*)0)", "Unregistered hf."
)))) ; parent_hfinfo = gpa_hfinfo.hfi[hfinfo->parent];
;
12569
12570 /*
12571 * Skip the field if filter protocols have been set and this one's
12572 * parent is not listed.
12573 */
12574 if (protos) {
12575 found = false0;
12576 j = 0;
12577 proto = protos[0];
12578 while(proto) {
12579 if (!g_strcmp0(proto, parent_hfinfo->abbrev)) {
12580 found = true1;
12581 break;
12582 }
12583 j++;
12584 proto = protos[j];
12585 }
12586 if (!found)
12587 continue;
12588 }
12589
12590 if (prev_proto && g_strcmp0(parent_hfinfo->abbrev, prev_proto)) {
12591 json_dumper_end_object(&dumper); // 7.properties
12592 json_dumper_end_object(&dumper); // 8.parent_hfinfo->abbrev
12593 open_object = true1;
12594 }
12595
12596 prev_proto = parent_hfinfo->abbrev;
12597
12598 if (open_object) {
12599 json_dumper_set_member_name(&dumper, parent_hfinfo->abbrev);
12600 json_dumper_begin_object(&dumper); // 6.parent_hfinfo->abbrev
12601 json_dumper_set_member_name(&dumper, "properties");
12602 json_dumper_begin_object(&dumper); // 7.properties
12603 open_object = false0;
12604 }
12605 /* Skip the fields that would map into string. This is the default in elasticsearch. */
12606 type = ws_type_to_elastic(hfinfo->type);
12607 /* when type is NULL, we have the default mapping: string */
12608 if (type) {
12609 str = ws_strdup_printf("%s_%s", prev_proto, hfinfo->abbrev)wmem_strdup_printf(((void*)0), "%s_%s", prev_proto, hfinfo->
abbrev)
;
12610 dot_to_underscore(str);
12611 if (g_strcmp0(prev_item, str)) {
12612 json_dumper_set_member_name(&dumper, str);
12613 json_dumper_begin_object(&dumper); // 8.hfinfo->abbrev
12614 json_dumper_set_member_name(&dumper, "type");
12615 json_dumper_value_string(&dumper, type);
12616 json_dumper_end_object(&dumper); // 8.hfinfo->abbrev
12617 }
12618 g_free(prev_item)(__builtin_object_size ((prev_item), 0) != ((size_t) - 1)) ? g_free_sized
(prev_item, __builtin_object_size ((prev_item), 0)) : (g_free
) (prev_item)
;
12619 prev_item = str;
12620 }
12621 }
12622 }
12623 g_free(prev_item)(__builtin_object_size ((prev_item), 0) != ((size_t) - 1)) ? g_free_sized
(prev_item, __builtin_object_size ((prev_item), 0)) : (g_free
) (prev_item)
;
12624
12625 if (prev_proto) {
12626 json_dumper_end_object(&dumper); // 7.properties
12627 json_dumper_end_object(&dumper); // 6.parent_hfinfo->abbrev
12628 }
12629
12630 json_dumper_end_object(&dumper); // 5.properties
12631 json_dumper_end_object(&dumper); // 4.layers
12632 json_dumper_end_object(&dumper); // 3.properties
12633 json_dumper_end_object(&dumper); // 2.mappings
12634 json_dumper_end_object(&dumper); // 1.root
12635 bool_Bool ret = json_dumper_finish(&dumper);
12636 DISSECTOR_ASSERT(ret)((void) ((ret) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 12636, "ret"))))
;
12637
12638 g_strfreev(protos);
12639}
12640
12641/* Dumps the contents of the registration database to stdout. An independent
12642 * program can take this output and format it into nice tables or HTML or
12643 * whatever.
12644 *
12645 * There is one record per line. Each record is either a protocol or a header
12646 * field, differentiated by the first field. The fields are tab-delimited.
12647 *
12648 * Protocols
12649 * ---------
12650 * Field 1 = 'P'
12651 * Field 2 = descriptive protocol name
12652 * Field 3 = protocol abbreviation
12653 *
12654 * Header Fields
12655 * -------------
12656 * Field 1 = 'F'
12657 * Field 2 = descriptive field name
12658 * Field 3 = field abbreviation
12659 * Field 4 = type ( textual representation of the ftenum type )
12660 * Field 5 = parent protocol abbreviation
12661 * Field 6 = base for display (for integer types); "parent bitfield width" for FT_BOOLEAN
12662 * Field 7 = bitmask: format: hex: 0x....
12663 * Field 8 = blurb describing field
12664 */
12665void
12666proto_registrar_dump_fields(void)
12667{
12668 header_field_info *hfinfo, *parent_hfinfo;
12669 int i, len;
12670 const char *enum_name;
12671 const char *base_name;
12672 const char *blurb;
12673 char width[5];
12674
12675 len = gpa_hfinfo.len;
12676 for (i = 1; i < len ; i++) {
12677 if (gpa_hfinfo.hfi[i] == NULL((void*)0))
12678 continue; /* This is a deregistered protocol or header field */
12679
12680 PROTO_REGISTRAR_GET_NTH(i, hfinfo)if((i == 0 || (unsigned)i > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 12680
, __func__, "Unregistered hf! index=%d", i); ((void) ((i >
0 && (unsigned)i < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 12680
, "i > 0 && (unsigned)i < gpa_hfinfo.len", "Unregistered hf."
)))) ; ((void) ((gpa_hfinfo.hfi[i] != ((void*)0)) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 12680, "gpa_hfinfo.hfi[i] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[i];
;
12681
12682 /*
12683 * Skip the pseudo-field for "proto_tree_add_text()" since
12684 * we don't want it in the list of filterable fields.
12685 */
12686 if (hfinfo->id == hf_text_only)
12687 continue;
12688
12689 /* format for protocols */
12690 if (proto_registrar_is_protocol(i)) {
12691 printf("P\t%s\t%s\n", hfinfo->name, hfinfo->abbrev);
12692 }
12693 /* format for header fields */
12694 else {
12695 /*
12696 * If this field isn't at the head of the list of
12697 * fields with this name, skip this field - all
12698 * fields with the same name are really just versions
12699 * of the same field stored in different bits, and
12700 * should have the same type/radix/value list, and
12701 * just differ in their bit masks. (If a field isn't
12702 * a bitfield, but can be, say, 1 or 2 bytes long,
12703 * it can just be made FT_UINT16, meaning the
12704 * *maximum* length is 2 bytes, and be used
12705 * for all lengths.)
12706 */
12707 if (hfinfo->same_name_prev_id != -1)
12708 continue;
12709
12710 PROTO_REGISTRAR_GET_NTH(hfinfo->parent, parent_hfinfo)if((hfinfo->parent == 0 || (unsigned)hfinfo->parent >
gpa_hfinfo.len) && wireshark_abort_on_dissector_bug)
ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 12710
, __func__, "Unregistered hf! index=%d", hfinfo->parent); (
(void) ((hfinfo->parent > 0 && (unsigned)hfinfo
->parent < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 12710
, "hfinfo->parent > 0 && (unsigned)hfinfo->parent < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfinfo->
parent] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 12710
, "gpa_hfinfo.hfi[hfinfo->parent] != ((void*)0)", "Unregistered hf."
)))) ; parent_hfinfo = gpa_hfinfo.hfi[hfinfo->parent];
;
12711
12712 enum_name = ftype_name(hfinfo->type);
12713 base_name = "";
12714
12715 if (hfinfo->type == FT_CHAR ||
12716 hfinfo->type == FT_UINT8 ||
12717 hfinfo->type == FT_UINT16 ||
12718 hfinfo->type == FT_UINT24 ||
12719 hfinfo->type == FT_UINT32 ||
12720 hfinfo->type == FT_UINT40 ||
12721 hfinfo->type == FT_UINT48 ||
12722 hfinfo->type == FT_UINT56 ||
12723 hfinfo->type == FT_UINT64 ||
12724 hfinfo->type == FT_INT8 ||
12725 hfinfo->type == FT_INT16 ||
12726 hfinfo->type == FT_INT24 ||
12727 hfinfo->type == FT_INT32 ||
12728 hfinfo->type == FT_INT40 ||
12729 hfinfo->type == FT_INT48 ||
12730 hfinfo->type == FT_INT56 ||
12731 hfinfo->type == FT_INT64) {
12732
12733 switch (FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF)) {
12734 case BASE_NONE:
12735 case BASE_DEC:
12736 case BASE_HEX:
12737 case BASE_OCT:
12738 case BASE_DEC_HEX:
12739 case BASE_HEX_DEC:
12740 case BASE_CUSTOM:
12741 case BASE_PT_UDP:
12742 case BASE_PT_TCP:
12743 case BASE_PT_DCCP:
12744 case BASE_PT_SCTP:
12745 case BASE_OUI:
12746 base_name = val_to_str_const(FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF), hf_display, "????");
12747 break;
12748 default:
12749 base_name = "????";
12750 break;
12751 }
12752 } else if (hfinfo->type == FT_BOOLEAN) {
12753 /* For FT_BOOLEAN: 'display' can be "parent bitfield width" */
12754 snprintf(width, sizeof(width), "%d", hfinfo->display);
12755 base_name = width;
12756 }
12757
12758 blurb = hfinfo->blurb;
12759 if (blurb == NULL((void*)0))
12760 blurb = "";
12761 else if (strlen(blurb) == 0)
12762 blurb = "\"\"";
12763
12764 printf("F\t%s\t%s\t%s\t%s\t%s\t0x%" PRIx64"l" "x" "\t%s\n",
12765 hfinfo->name, hfinfo->abbrev, enum_name,
12766 parent_hfinfo->abbrev, base_name,
12767 hfinfo->bitmask, blurb);
12768 }
12769 }
12770}
12771
12772/* Dumps all abbreviated field and protocol completions of the given string to
12773 * stdout. An independent program may use this for command-line tab completion
12774 * of fields.
12775 */
12776bool_Bool
12777proto_registrar_dump_field_completions(const char *prefix)
12778{
12779 header_field_info *hfinfo;
12780 int i, len;
12781 size_t prefix_len;
12782 bool_Bool matched = false0;
12783
12784 prefix_len = strlen(prefix);
12785 len = gpa_hfinfo.len;
12786 for (i = 1; i < len ; i++) {
12787 if (gpa_hfinfo.hfi[i] == NULL((void*)0))
12788 continue; /* This is a deregistered protocol or header field */
12789
12790 PROTO_REGISTRAR_GET_NTH(i, hfinfo)if((i == 0 || (unsigned)i > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 12790
, __func__, "Unregistered hf! index=%d", i); ((void) ((i >
0 && (unsigned)i < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 12790
, "i > 0 && (unsigned)i < gpa_hfinfo.len", "Unregistered hf."
)))) ; ((void) ((gpa_hfinfo.hfi[i] != ((void*)0)) ? (void)0 :
(proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 12790, "gpa_hfinfo.hfi[i] != ((void*)0)", "Unregistered hf."
)))) ; hfinfo = gpa_hfinfo.hfi[i];
;
12791
12792 /*
12793 * Skip the pseudo-field for "proto_tree_add_text()" since
12794 * we don't want it in the list of filterable fields.
12795 */
12796 if (hfinfo->id == hf_text_only)
12797 continue;
12798
12799 /* format for protocols */
12800 if (proto_registrar_is_protocol(i)) {
12801 if(0 == strncmp(hfinfo->abbrev, prefix, prefix_len)) {
12802 matched = true1;
12803 printf("%s\t%s\n", hfinfo->abbrev, hfinfo->name);
12804 }
12805 }
12806 /* format for header fields */
12807 else {
12808 /*
12809 * If this field isn't at the head of the list of
12810 * fields with this name, skip this field - all
12811 * fields with the same name are really just versions
12812 * of the same field stored in different bits, and
12813 * should have the same type/radix/value list, and
12814 * just differ in their bit masks. (If a field isn't
12815 * a bitfield, but can be, say, 1 or 2 bytes long,
12816 * it can just be made FT_UINT16, meaning the
12817 * *maximum* length is 2 bytes, and be used
12818 * for all lengths.)
12819 */
12820 if (hfinfo->same_name_prev_id != -1)
12821 continue;
12822
12823 if(0 == strncmp(hfinfo->abbrev, prefix, prefix_len)) {
12824 matched = true1;
12825 printf("%s\t%s\n", hfinfo->abbrev, hfinfo->name);
12826 }
12827 }
12828 }
12829 return matched;
12830}
12831
12832/* Dumps field types and descriptive names to stdout. An independent
12833 * program can take this output and format it into nice tables or HTML or
12834 * whatever.
12835 *
12836 * There is one record per line. The fields are tab-delimited.
12837 *
12838 * Field 1 = field type name, e.g. FT_UINT8
12839 * Field 2 = descriptive name, e.g. "Unsigned, 1 byte"
12840 */
12841void
12842proto_registrar_dump_ftypes(void)
12843{
12844 int fte;
12845
12846 for (fte = 0; fte < FT_NUM_TYPES; fte++) {
12847 printf("%s\t%s\n", ftype_name((ftenum_t)fte), ftype_pretty_name((ftenum_t)fte));
12848 }
12849}
12850
12851/* This function indicates whether it's possible to construct a
12852 * "match selected" display filter string for the specified field,
12853 * returns an indication of whether it's possible, and, if it's
12854 * possible and "filter" is non-null, constructs the filter and
12855 * sets "*filter" to point to it.
12856 * You do not need to [g_]free() this string since it will be automatically
12857 * freed once the next packet is dissected.
12858 */
12859static bool_Bool
12860construct_match_selected_string(const field_info *finfo, epan_dissect_t *edt,
12861 char **filter)
12862{
12863 const header_field_info *hfinfo;
12864 int start, length, length_remaining;
12865
12866 if (!finfo)
12867 return false0;
12868
12869 hfinfo = finfo->hfinfo;
12870 DISSECTOR_ASSERT(hfinfo)((void) ((hfinfo) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 12870, "hfinfo"))))
;
12871
12872 /* If we have BASE_NONE and strings (a non-NULL FIELDCONVERT),
12873 * then "the numeric value ... is not used when preparing
12874 * filters for the field in question." If it's any other
12875 * base, we'll generate the filter normally (which will
12876 * be numeric, even though the human-readable string does
12877 * work for filtering.)
12878 *
12879 * XXX - It might be nice to use fvalue_to_string_repr() in
12880 * "proto_item_fill_label()" as well, although, there, you'd
12881 * have to deal with the base *and* with resolved values for
12882 * addresses.
12883 *
12884 * Perhaps in addition to taking the repr type (DISPLAY
12885 * or DFILTER) and the display (base), fvalue_to_string_repr()
12886 * should have the the "strings" values in the header_field_info
12887 * structure for the field as a parameter, so it can have
12888 * if the field is Boolean or an enumerated integer type,
12889 * the tables used to generate human-readable values.
12890 */
12891 if (hfinfo->strings && FIELD_DISPLAY(hfinfo->display)((hfinfo->display) & 0xFF) == BASE_NONE) {
12892 const char *str = NULL((void*)0);
12893
12894 switch (hfinfo->type) {
12895
12896 case FT_INT8:
12897 case FT_INT16:
12898 case FT_INT24:
12899 case FT_INT32:
12900 str = hf_try_val_to_str(fvalue_get_sinteger(finfo->value), hfinfo);
12901 break;
12902
12903 case FT_CHAR:
12904 case FT_UINT8:
12905 case FT_UINT16:
12906 case FT_UINT24:
12907 case FT_UINT32:
12908 str = hf_try_val_to_str(fvalue_get_uinteger(finfo->value), hfinfo);
12909 break;
12910
12911 default:
12912 break;
12913 }
12914
12915 if (str != NULL((void*)0) && filter != NULL((void*)0)) {
12916 *filter = wmem_strdup_printf(NULL((void*)0), "%s == \"%s\"", hfinfo->abbrev, str);
12917 return true1;
12918 }
12919 }
12920
12921 switch (hfinfo->type) {
12922
12923 case FT_PROTOCOL:
12924 if (filter != NULL((void*)0))
12925 *filter = wmem_strdup(NULL((void*)0), finfo->hfinfo->abbrev);
12926 break;
12927
12928 case FT_NONE:
12929 /*
12930 * If the length is 0, just match the name of the
12931 * field.
12932 *
12933 * (Also check for negative values, just in case,
12934 * as we'll cast it to an unsigned value later.)
12935 */
12936 length = finfo->length;
12937 if (length == 0) {
12938 if (filter != NULL((void*)0))
12939 *filter = wmem_strdup(NULL((void*)0), finfo->hfinfo->abbrev);
12940 break;
12941 }
12942 if (length < 0)
12943 return false0;
12944
12945 /*
12946 * This doesn't have a value, so we'd match
12947 * on the raw bytes at this address.
12948 *
12949 * Should we be allowed to access to the raw bytes?
12950 * If "edt" is NULL, the answer is "no".
12951 */
12952 if (edt == NULL((void*)0))
12953 return false0;
12954
12955 /*
12956 * Is this field part of the raw frame tvbuff?
12957 * If not, we can't use "frame[N:M]" to match
12958 * it.
12959 *
12960 * XXX - should this be frame-relative, or
12961 * protocol-relative?
12962 *
12963 * XXX - does this fallback for non-registered
12964 * fields even make sense?
12965 */
12966 if (finfo->ds_tvb != edt->tvb)
12967 return false0; /* you lose */
12968
12969 /*
12970 * Don't go past the end of that tvbuff.
12971 */
12972 length_remaining = tvb_captured_length_remaining(finfo->ds_tvb, finfo->start);
12973 if (length > length_remaining)
12974 length = length_remaining;
12975 if (length <= 0)
12976 return false0;
12977
12978 if (filter != NULL((void*)0)) {
12979 start = finfo->start;
12980 char *str = bytes_to_dfilter_repr(NULL((void*)0), tvb_get_ptr(finfo->ds_tvb, start, length), length);
12981 *filter = wmem_strdup_printf(NULL((void*)0), "frame[%d:%d] == %s", finfo->start, length, str);
12982 wmem_free(NULL((void*)0), str);
12983 }
12984 break;
12985
12986 /* By default, use the fvalue's "to_string_repr" method. */
12987 default:
12988 if (filter != NULL((void*)0)) {
12989 char *str = fvalue_to_string_repr(NULL((void*)0), finfo->value, FTREPR_DFILTER, finfo->hfinfo->display);
12990 *filter = wmem_strdup_printf(NULL((void*)0), "%s == %s", hfinfo->abbrev, str);
12991 wmem_free(NULL((void*)0), str);
12992 }
12993 break;
12994 }
12995
12996 return true1;
12997}
12998
12999/*
13000 * Returns true if we can do a "match selected" on the field, false
13001 * otherwise.
13002 */
13003bool_Bool
13004proto_can_match_selected(const field_info *finfo, epan_dissect_t *edt)
13005{
13006 return construct_match_selected_string(finfo, edt, NULL((void*)0));
13007}
13008
13009/* This function attempts to construct a "match selected" display filter
13010 * string for the specified field; if it can do so, it returns a pointer
13011 * to the string, otherwise it returns NULL.
13012 *
13013 * The string is wmem allocated and must be freed with "wmem_free(NULL, ...)".
13014 */
13015char *
13016proto_construct_match_selected_string(const field_info *finfo, epan_dissect_t *edt)
13017{
13018 char *filter = NULL((void*)0);
13019
13020 if (!construct_match_selected_string(finfo, edt, &filter))
13021 {
13022 wmem_free(NULL((void*)0), filter);
13023 return NULL((void*)0);
13024 }
13025 return filter;
13026}
13027
13028/* This function is common code for all proto_tree_add_bitmask... functions.
13029 */
13030
13031static bool_Bool
13032proto_item_add_bitmask_tree(proto_item *item, tvbuff_t *tvb, const unsigned offset,
13033 const unsigned len, const int ett, int * const *fields,
13034 const int flags, bool_Bool first,
13035 bool_Bool use_parent_tree,
13036 proto_tree* tree, uint64_t value)
13037{
13038 uint64_t available_bits = UINT64_MAX(18446744073709551615UL);
13039 uint64_t bitmask = 0;
13040 uint64_t tmpval;
13041 header_field_info *hf;
13042 uint32_t integer32;
13043 int bit_offset;
13044 int no_of_bits;
13045
13046 if (!*fields)
13047 REPORT_DISSECTOR_BUG("Illegal call of proto_item_add_bitmask_tree without fields")proto_report_dissector_bug("Illegal call of proto_item_add_bitmask_tree without fields"
)
;
13048
13049 if (len > 8)
13050 REPORT_DISSECTOR_BUG("Invalid len: %d", len)proto_report_dissector_bug("Invalid len: %d", len);
13051 /**
13052 * packet-frame.c uses len=0 since the value is taken from the packet
13053 * metadata, not the packet bytes. In that case, assume that all bits
13054 * in the provided value are valid.
13055 */
13056 if (len > 0) {
13057 available_bits >>= (8 - len)*8;
13058 }
13059
13060 if (use_parent_tree == false0)
13061 tree = proto_item_add_subtree(item, ett);
13062
13063 while (*fields) {
13064 uint64_t present_bits;
13065 PROTO_REGISTRAR_GET_NTH(**fields,hf)if((**fields == 0 || (unsigned)**fields > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 13065, __func__, "Unregistered hf! index=%d"
, **fields); ((void) ((**fields > 0 && (unsigned)*
*fields < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 13065
, "**fields > 0 && (unsigned)**fields < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[**fields]
!= ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13065, "gpa_hfinfo.hfi[**fields] != ((void*)0)"
, "Unregistered hf.")))) ; hf = gpa_hfinfo.hfi[**fields];
;
13066 DISSECTOR_ASSERT_HINT(hf->bitmask != 0, hf->abbrev)((void) ((hf->bitmask != 0) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 13066
, "hf->bitmask != 0", hf->abbrev))))
;
13067
13068 bitmask |= hf->bitmask;
13069
13070 /* Skip fields that aren't fully present */
13071 present_bits = available_bits & hf->bitmask;
13072 if (present_bits != hf->bitmask) {
13073 fields++;
13074 continue;
13075 }
13076
13077 switch (hf->type) {
13078 case FT_CHAR:
13079 case FT_UINT8:
13080 case FT_UINT16:
13081 case FT_UINT24:
13082 case FT_UINT32:
13083 proto_tree_add_uint(tree, **fields, tvb, offset, len, (uint32_t)value);
13084 break;
13085
13086 case FT_INT8:
13087 case FT_INT16:
13088 case FT_INT24:
13089 case FT_INT32:
13090 proto_tree_add_int(tree, **fields, tvb, offset, len, (int32_t)value);
13091 break;
13092
13093 case FT_UINT40:
13094 case FT_UINT48:
13095 case FT_UINT56:
13096 case FT_UINT64:
13097 proto_tree_add_uint64(tree, **fields, tvb, offset, len, value);
13098 break;
13099
13100 case FT_INT40:
13101 case FT_INT48:
13102 case FT_INT56:
13103 case FT_INT64:
13104 proto_tree_add_int64(tree, **fields, tvb, offset, len, (int64_t)value);
13105 break;
13106
13107 case FT_BOOLEAN:
13108 proto_tree_add_boolean(tree, **fields, tvb, offset, len, value);
13109 break;
13110
13111 default:
13112 REPORT_DISSECTOR_BUG("field %s has type %d (%s) not handled in proto_item_add_bitmask_tree()",proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_item_add_bitmask_tree()"
, hf->abbrev, hf->type, ftype_name(hf->type))
13113 hf->abbrev,proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_item_add_bitmask_tree()"
, hf->abbrev, hf->type, ftype_name(hf->type))
13114 hf->type,proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_item_add_bitmask_tree()"
, hf->abbrev, hf->type, ftype_name(hf->type))
13115 ftype_name(hf->type))proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_item_add_bitmask_tree()"
, hf->abbrev, hf->type, ftype_name(hf->type))
;
13116 break;
13117 }
13118 if (flags & BMT_NO_APPEND0x01) {
13119 fields++;
13120 continue;
13121 }
13122 tmpval = (value & hf->bitmask) >> hfinfo_bitshift(hf);
13123
13124 /* XXX: README.developer and the comments have always defined
13125 * BMT_NO_INT as "only boolean flags are added to the title /
13126 * don't add non-boolean (integral) fields", but the
13127 * implementation has always added BASE_CUSTOM and fields with
13128 * value_strings, though not fields with unit_strings.
13129 * Possibly this is because some dissectors use a FT_UINT8
13130 * with a value_string for fields that should be a FT_BOOLEAN.
13131 */
13132 switch (hf->type) {
13133 case FT_CHAR:
13134 if (hf->display == BASE_CUSTOM) {
13135 char lbl[ITEM_LABEL_LENGTH240];
13136 const custom_fmt_func_t fmtfunc = (const custom_fmt_func_t)hf->strings;
13137
13138 DISSECTOR_ASSERT(fmtfunc)((void) ((fmtfunc) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 13138, "fmtfunc"))))
;
13139 fmtfunc(lbl, (uint32_t) tmpval);
13140 proto_item_append_text(item, "%s%s: %s", first ? "" : ", ",
13141 hf->name, lbl);
13142 first = false0;
13143 }
13144 else if (hf->strings) {
13145 proto_item_append_text(item, "%s%s: %s", first ? "" : ", ",
13146 hf->name, hf_try_val_to_str_const((uint32_t) tmpval, hf, "Unknown"));
13147 first = false0;
13148 }
13149 else if (!(flags & BMT_NO_INT0x02)) {
13150 char buf[32];
13151 const char *out;
13152
13153 if (!first) {
13154 proto_item_append_text(item, ", ");
13155 }
13156
13157 out = hfinfo_char_value_format(hf, buf, (uint32_t) tmpval);
13158 proto_item_append_text(item, "%s: %s", hf->name, out);
13159 first = false0;
13160 }
13161
13162 break;
13163
13164 case FT_UINT8:
13165 case FT_UINT16:
13166 case FT_UINT24:
13167 case FT_UINT32:
13168 if (hf->display == BASE_CUSTOM) {
13169 char lbl[ITEM_LABEL_LENGTH240];
13170 const custom_fmt_func_t fmtfunc = (const custom_fmt_func_t)hf->strings;
13171
13172 DISSECTOR_ASSERT(fmtfunc)((void) ((fmtfunc) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 13172, "fmtfunc"))))
;
13173 fmtfunc(lbl, (uint32_t) tmpval);
13174 proto_item_append_text(item, "%s%s: %s", first ? "" : ", ",
13175 hf->name, lbl);
13176 first = false0;
13177 }
13178 else if ((hf->strings) &&(!(hf->display & (BASE_UNIT_STRING0x00001000|BASE_SPECIAL_VALS0x00008000)))) {
13179 proto_item_append_text(item, "%s%s: %s", first ? "" : ", ",
13180 hf->name, hf_try_val_to_str_const((uint32_t) tmpval, hf, "Unknown"));
13181 first = false0;
13182 }
13183 else if (!(flags & BMT_NO_INT0x02)) {
13184 char buf[NUMBER_LABEL_LENGTH80];
13185 const char *out = NULL((void*)0);
13186
13187 if (!first) {
13188 proto_item_append_text(item, ", ");
13189 }
13190
13191 if (hf->strings && hf->display & BASE_SPECIAL_VALS0x00008000) {
13192 out = hf_try_val_to_str((uint32_t) tmpval, hf);
13193 }
13194 if (out == NULL((void*)0)) {
13195 out = hfinfo_number_value_format(hf, buf, (uint32_t) tmpval);
13196 }
13197 proto_item_append_text(item, "%s: %s", hf->name, out);
13198 if (hf->strings && hf->display & BASE_UNIT_STRING0x00001000) {
13199 proto_item_append_text(item, "%s", unit_name_string_get_value((uint32_t) tmpval, (const unit_name_string*)hf->strings));
13200 }
13201 first = false0;
13202 }
13203
13204 break;
13205
13206 case FT_INT8:
13207 case FT_INT16:
13208 case FT_INT24:
13209 case FT_INT32:
13210 integer32 = (uint32_t) tmpval;
13211 if (hf->bitmask) {
13212 no_of_bits = ws_count_ones(hf->bitmask);
13213 integer32 = ws_sign_ext32(integer32, no_of_bits);
13214 }
13215 if (hf->display == BASE_CUSTOM) {
13216 char lbl[ITEM_LABEL_LENGTH240];
13217 const custom_fmt_func_t fmtfunc = (const custom_fmt_func_t)hf->strings;
13218
13219 DISSECTOR_ASSERT(fmtfunc)((void) ((fmtfunc) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 13219, "fmtfunc"))))
;
13220 fmtfunc(lbl, (int32_t) integer32);
13221 proto_item_append_text(item, "%s%s: %s", first ? "" : ", ",
13222 hf->name, lbl);
13223 first = false0;
13224 }
13225 else if ((hf->strings) &&(!(hf->display & (BASE_UNIT_STRING0x00001000|BASE_SPECIAL_VALS0x00008000)))) {
13226 proto_item_append_text(item, "%s%s: %s", first ? "" : ", ",
13227 hf->name, hf_try_val_to_str_const((int32_t) integer32, hf, "Unknown"));
13228 first = false0;
13229 }
13230 else if (!(flags & BMT_NO_INT0x02)) {
13231 char buf[NUMBER_LABEL_LENGTH80];
13232 const char *out = NULL((void*)0);
13233
13234 if (!first) {
13235 proto_item_append_text(item, ", ");
13236 }
13237
13238 if (hf->strings && hf->display & BASE_SPECIAL_VALS0x00008000) {
13239 out = hf_try_val_to_str((int32_t) integer32, hf);
13240 }
13241 if (out == NULL((void*)0)) {
13242 out = hfinfo_number_value_format(hf, buf, (int32_t) integer32);
13243 }
13244 proto_item_append_text(item, "%s: %s", hf->name, out);
13245 if (hf->strings && hf->display & BASE_UNIT_STRING0x00001000) {
13246 proto_item_append_text(item, "%s", unit_name_string_get_value((uint32_t) tmpval, (const unit_name_string*)hf->strings));
13247 }
13248 first = false0;
13249 }
13250
13251 break;
13252
13253 case FT_UINT40:
13254 case FT_UINT48:
13255 case FT_UINT56:
13256 case FT_UINT64:
13257 if (hf->display == BASE_CUSTOM) {
13258 char lbl[ITEM_LABEL_LENGTH240];
13259 const custom_fmt_func_64_t fmtfunc = (const custom_fmt_func_64_t)hf->strings;
13260
13261 DISSECTOR_ASSERT(fmtfunc)((void) ((fmtfunc) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 13261, "fmtfunc"))))
;
13262 fmtfunc(lbl, tmpval);
13263 proto_item_append_text(item, "%s%s: %s", first ? "" : ", ",
13264 hf->name, lbl);
13265 first = false0;
13266 }
13267 else if ((hf->strings) &&(!(hf->display & (BASE_UNIT_STRING0x00001000|BASE_SPECIAL_VALS0x00008000)))) {
13268 proto_item_append_text(item, "%s%s: %s", first ? "" : ", ",
13269 hf->name, hf_try_val64_to_str_const(tmpval, hf, "Unknown"));
13270 first = false0;
13271 }
13272 else if (!(flags & BMT_NO_INT0x02)) {
13273 char buf[NUMBER_LABEL_LENGTH80];
13274 const char *out = NULL((void*)0);
13275
13276 if (!first) {
13277 proto_item_append_text(item, ", ");
13278 }
13279
13280 if (hf->strings && hf->display & BASE_SPECIAL_VALS0x00008000) {
13281 out = hf_try_val64_to_str(tmpval, hf);
13282 }
13283 if (out == NULL((void*)0)) {
13284 out = hfinfo_number_value_format64(hf, buf, tmpval);
13285 }
13286 proto_item_append_text(item, "%s: %s", hf->name, out);
13287 if (hf->strings && hf->display & BASE_UNIT_STRING0x00001000) {
13288 proto_item_append_text(item, "%s", unit_name_string_get_value64(tmpval, (const unit_name_string*)hf->strings));
13289 }
13290 first = false0;
13291 }
13292
13293 break;
13294
13295 case FT_INT40:
13296 case FT_INT48:
13297 case FT_INT56:
13298 case FT_INT64:
13299 if (hf->bitmask) {
13300 no_of_bits = ws_count_ones(hf->bitmask);
13301 tmpval = ws_sign_ext64(tmpval, no_of_bits);
13302 }
13303 if (hf->display == BASE_CUSTOM) {
13304 char lbl[ITEM_LABEL_LENGTH240];
13305 const custom_fmt_func_64_t fmtfunc = (const custom_fmt_func_64_t)hf->strings;
13306
13307 DISSECTOR_ASSERT(fmtfunc)((void) ((fmtfunc) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 13307, "fmtfunc"))))
;
13308 fmtfunc(lbl, (int64_t) tmpval);
13309 proto_item_append_text(item, "%s%s: %s", first ? "" : ", ",
13310 hf->name, lbl);
13311 first = false0;
13312 }
13313 else if ((hf->strings) &&(!(hf->display & (BASE_UNIT_STRING0x00001000|BASE_SPECIAL_VALS0x00008000)))) {
13314 proto_item_append_text(item, "%s%s: %s", first ? "" : ", ",
13315 hf->name, hf_try_val64_to_str_const((int64_t) tmpval, hf, "Unknown"));
13316 first = false0;
13317 }
13318 else if (!(flags & BMT_NO_INT0x02)) {
13319 char buf[NUMBER_LABEL_LENGTH80];
13320 const char *out = NULL((void*)0);
13321
13322 if (!first) {
13323 proto_item_append_text(item, ", ");
13324 }
13325
13326 if (hf->strings && hf->display & BASE_SPECIAL_VALS0x00008000) {
13327 out = hf_try_val64_to_str((int64_t) tmpval, hf);
13328 }
13329 if (out == NULL((void*)0)) {
13330 out = hfinfo_number_value_format64(hf, buf, (int64_t) tmpval);
13331 }
13332 proto_item_append_text(item, "%s: %s", hf->name, out);
13333 if (hf->strings && hf->display & BASE_UNIT_STRING0x00001000) {
13334 proto_item_append_text(item, "%s", unit_name_string_get_value64(tmpval, (const unit_name_string*)hf->strings));
13335 }
13336 first = false0;
13337 }
13338
13339 break;
13340
13341 case FT_BOOLEAN:
13342 if (hf->strings && !(flags & BMT_NO_TFS0x08)) {
13343 /* If we have true/false strings, emit full - otherwise messages
13344 might look weird */
13345 const struct true_false_string *tfs =
13346 (const struct true_false_string *)hf->strings;
13347
13348 if (tmpval) {
13349 proto_item_append_text(item, "%s%s: %s", first ? "" : ", ",
13350 hf->name, tfs->true_string);
13351 first = false0;
13352 } else if (!(flags & BMT_NO_FALSE0x04)) {
13353 proto_item_append_text(item, "%s%s: %s", first ? "" : ", ",
13354 hf->name, tfs->false_string);
13355 first = false0;
13356 }
13357 } else if (hf->bitmask & value) {
13358 /* If the flag is set, show the name */
13359 proto_item_append_text(item, "%s%s", first ? "" : ", ", hf->name);
13360 first = false0;
13361 }
13362 break;
13363 default:
13364 REPORT_DISSECTOR_BUG("field %s has type %d (%s) not handled in proto_item_add_bitmask_tree()",proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_item_add_bitmask_tree()"
, hf->abbrev, hf->type, ftype_name(hf->type))
13365 hf->abbrev,proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_item_add_bitmask_tree()"
, hf->abbrev, hf->type, ftype_name(hf->type))
13366 hf->type,proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_item_add_bitmask_tree()"
, hf->abbrev, hf->type, ftype_name(hf->type))
13367 ftype_name(hf->type))proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_item_add_bitmask_tree()"
, hf->abbrev, hf->type, ftype_name(hf->type))
;
13368 break;
13369 }
13370
13371 fields++;
13372 }
13373
13374 /* XXX: We don't pass the hfi into this function. Perhaps we should,
13375 * but then again most dissectors don't set the bitmask field for
13376 * the higher level bitmask hfi, so calculate the bitmask from the
13377 * fields present. */
13378 if (item) {
13379 bit_offset = len*8 - 1 - ws_ilog2(bitmask);
13380 no_of_bits = ws_ilog2(bitmask) - ws_ctz(bitmask) + 1;
13381 FI_SET_FLAG(PNODE_FINFO(item), FI_BITS_OFFSET(bit_offset))do { if (((item)->finfo)) (((item)->finfo))->flags =
(((item)->finfo))->flags | ((((bit_offset) & 63) <<
5)); } while(0)
;
13382 FI_SET_FLAG(PNODE_FINFO(item), FI_BITS_SIZE(no_of_bits))do { if (((item)->finfo)) (((item)->finfo))->flags =
(((item)->finfo))->flags | ((((no_of_bits) & 63) <<
12)); } while(0)
;
13383 }
13384 return first;
13385}
13386
13387/* This function will dissect a sequence of bytes that describe a
13388 * bitmask and supply the value of that sequence through a pointer.
13389 * hf_hdr is a 8/16/24/32/40/48/56/64 bit integer that describes the bitmask
13390 * to be dissected.
13391 * This field will form an expansion under which the individual fields of the
13392 * bitmask is dissected and displayed.
13393 * This field must be of the type FT_[U]INT{8|16|24|32|40|48|56|64}.
13394 *
13395 * fields is an array of pointers to int that lists all the fields of the
13396 * bitmask. These fields can be either of the type FT_BOOLEAN for flags
13397 * or another integer of the same type/size as hf_hdr with a mask specified.
13398 * This array is terminated by a NULL entry.
13399 *
13400 * FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
13401 * FT_integer fields that have a value_string attached will have the
13402 * matched string displayed on the expansion line.
13403 */
13404proto_item *
13405proto_tree_add_bitmask_ret_uint64(proto_tree *parent_tree, tvbuff_t *tvb,
13406 const unsigned offset, const int hf_hdr,
13407 const int ett, int * const *fields,
13408 const unsigned encoding, uint64_t *retval)
13409{
13410 return proto_tree_add_bitmask_with_flags_ret_uint64(parent_tree, tvb, offset, hf_hdr, ett, fields, encoding, BMT_NO_INT0x02|BMT_NO_TFS0x08, retval);
13411}
13412
13413/* This function will dissect a sequence of bytes that describe a
13414 * bitmask.
13415 * hf_hdr is a 8/16/24/32/40/48/56/64 bit integer that describes the bitmask
13416 * to be dissected.
13417 * This field will form an expansion under which the individual fields of the
13418 * bitmask is dissected and displayed.
13419 * This field must be of the type FT_[U]INT{8|16|24|32|40|48|56|64}.
13420 *
13421 * fields is an array of pointers to int that lists all the fields of the
13422 * bitmask. These fields can be either of the type FT_BOOLEAN for flags
13423 * or another integer of the same type/size as hf_hdr with a mask specified.
13424 * This array is terminated by a NULL entry.
13425 *
13426 * FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
13427 * FT_integer fields that have a value_string attached will have the
13428 * matched string displayed on the expansion line.
13429 */
13430proto_item *
13431proto_tree_add_bitmask(proto_tree *parent_tree, tvbuff_t *tvb,
13432 const unsigned offset, const int hf_hdr,
13433 const int ett, int * const *fields,
13434 const unsigned encoding)
13435{
13436 return proto_tree_add_bitmask_with_flags(parent_tree, tvb, offset, hf_hdr, ett, fields, encoding, BMT_NO_INT0x02|BMT_NO_TFS0x08);
13437}
13438
13439/* The same as proto_tree_add_bitmask_ret_uint64(), but uses user-supplied flags to determine
13440 * what data is appended to the header.
13441 */
13442proto_item *
13443proto_tree_add_bitmask_with_flags_ret_uint64(proto_tree *parent_tree, tvbuff_t *tvb, const unsigned offset,
13444 const int hf_hdr, const int ett, int * const *fields, const unsigned encoding, const int flags,
13445 uint64_t *retval)
13446{
13447 proto_item *item = NULL((void*)0);
13448 header_field_info *hf;
13449 unsigned len;
13450 uint64_t value;
13451
13452 PROTO_REGISTRAR_GET_NTH(hf_hdr,hf)if((hf_hdr == 0 || (unsigned)hf_hdr > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 13452, __func__, "Unregistered hf! index=%d"
, hf_hdr); ((void) ((hf_hdr > 0 && (unsigned)hf_hdr
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 13452
, "hf_hdr > 0 && (unsigned)hf_hdr < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hf_hdr] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13452, "gpa_hfinfo.hfi[hf_hdr] != ((void*)0)"
, "Unregistered hf.")))) ; hf = gpa_hfinfo.hfi[hf_hdr];
;
13453 DISSECTOR_ASSERT_FIELD_TYPE_IS_INTEGRAL(hf)((void) (((((((hf)->type) == FT_INT8 || ((hf)->type) ==
FT_INT16 || ((hf)->type) == FT_INT24 || ((hf)->type) ==
FT_INT32) || (((hf)->type) == FT_INT40 || ((hf)->type)
== FT_INT48 || ((hf)->type) == FT_INT56 || ((hf)->type
) == FT_INT64)) || ((((hf)->type) == FT_CHAR || ((hf)->
type) == FT_UINT8 || ((hf)->type) == FT_UINT16 || ((hf)->
type) == FT_UINT24 || ((hf)->type) == FT_UINT32 || ((hf)->
type) == FT_FRAMENUM) || (((hf)->type) == FT_UINT40 || ((hf
)->type) == FT_UINT48 || ((hf)->type) == FT_UINT56 || (
(hf)->type) == FT_UINT64)))) ? (void)0 : proto_report_dissector_bug
("%s:%u: field %s is not of type FT_CHAR or an FT_{U}INTn type"
, "epan/proto.c", 13453, (hf)->abbrev)))
;
13454 len = ftype_wire_size(hf->type);
13455 value = get_uint64_value(parent_tree, tvb, offset, len, encoding);
13456
13457 if (parent_tree) {
13458 item = proto_tree_add_item(parent_tree, hf_hdr, tvb, offset, len, encoding);
13459 proto_item_add_bitmask_tree(item, tvb, offset, len, ett, fields,
13460 flags, false0, false0, NULL((void*)0), value);
13461 }
13462
13463 *retval = value;
13464 if (hf->bitmask) {
13465 /* Mask out irrelevant portions */
13466 *retval &= hf->bitmask;
13467 /* Shift bits */
13468 *retval >>= hfinfo_bitshift(hf);
13469 }
13470
13471 return item;
13472}
13473
13474/* The same as proto_tree_add_bitmask_ret_uint64(), but uses user-supplied flags to determine
13475 * what data is appended to the header.
13476 */
13477proto_item *
13478proto_tree_add_bitmask_with_flags(proto_tree *parent_tree, tvbuff_t *tvb, const unsigned offset,
13479 const int hf_hdr, const int ett, int * const *fields, const unsigned encoding, const int flags)
13480{
13481 proto_item *item = NULL((void*)0);
13482 header_field_info *hf;
13483 unsigned len;
13484 uint64_t value;
13485
13486 PROTO_REGISTRAR_GET_NTH(hf_hdr,hf)if((hf_hdr == 0 || (unsigned)hf_hdr > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 13486, __func__, "Unregistered hf! index=%d"
, hf_hdr); ((void) ((hf_hdr > 0 && (unsigned)hf_hdr
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 13486
, "hf_hdr > 0 && (unsigned)hf_hdr < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hf_hdr] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13486, "gpa_hfinfo.hfi[hf_hdr] != ((void*)0)"
, "Unregistered hf.")))) ; hf = gpa_hfinfo.hfi[hf_hdr];
;
13487 DISSECTOR_ASSERT_FIELD_TYPE_IS_INTEGRAL(hf)((void) (((((((hf)->type) == FT_INT8 || ((hf)->type) ==
FT_INT16 || ((hf)->type) == FT_INT24 || ((hf)->type) ==
FT_INT32) || (((hf)->type) == FT_INT40 || ((hf)->type)
== FT_INT48 || ((hf)->type) == FT_INT56 || ((hf)->type
) == FT_INT64)) || ((((hf)->type) == FT_CHAR || ((hf)->
type) == FT_UINT8 || ((hf)->type) == FT_UINT16 || ((hf)->
type) == FT_UINT24 || ((hf)->type) == FT_UINT32 || ((hf)->
type) == FT_FRAMENUM) || (((hf)->type) == FT_UINT40 || ((hf
)->type) == FT_UINT48 || ((hf)->type) == FT_UINT56 || (
(hf)->type) == FT_UINT64)))) ? (void)0 : proto_report_dissector_bug
("%s:%u: field %s is not of type FT_CHAR or an FT_{U}INTn type"
, "epan/proto.c", 13487, (hf)->abbrev)))
;
13488
13489 if (parent_tree) {
13490 len = ftype_wire_size(hf->type);
13491 item = proto_tree_add_item(parent_tree, hf_hdr, tvb, offset, len, encoding);
13492 value = get_uint64_value(parent_tree, tvb, offset, len, encoding);
13493 proto_item_add_bitmask_tree(item, tvb, offset, len, ett, fields,
13494 flags, false0, false0, NULL((void*)0), value);
13495 }
13496
13497 return item;
13498}
13499
13500/* Similar to proto_tree_add_bitmask(), but with a passed in value (presumably because it
13501 can't be retrieved directly from tvb) */
13502proto_item *
13503proto_tree_add_bitmask_value(proto_tree *parent_tree, tvbuff_t *tvb, const unsigned offset,
13504 const int hf_hdr, const int ett, int * const *fields, const uint64_t value)
13505{
13506 return proto_tree_add_bitmask_value_with_flags(parent_tree, tvb, offset,
13507 hf_hdr, ett, fields, value, BMT_NO_INT0x02|BMT_NO_TFS0x08);
13508}
13509
13510/* Similar to proto_tree_add_bitmask_value(), but with control of flag values */
13511WS_DLL_PUBLIC__attribute__ ((visibility ("default"))) extern proto_item *
13512proto_tree_add_bitmask_value_with_flags(proto_tree *parent_tree, tvbuff_t *tvb, const unsigned offset,
13513 const int hf_hdr, const int ett, int * const *fields, const uint64_t value, const int flags)
13514{
13515 proto_item *item = NULL((void*)0);
13516 header_field_info *hf;
13517 unsigned len;
13518
13519 PROTO_REGISTRAR_GET_NTH(hf_hdr,hf)if((hf_hdr == 0 || (unsigned)hf_hdr > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 13519, __func__, "Unregistered hf! index=%d"
, hf_hdr); ((void) ((hf_hdr > 0 && (unsigned)hf_hdr
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 13519
, "hf_hdr > 0 && (unsigned)hf_hdr < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hf_hdr] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13519, "gpa_hfinfo.hfi[hf_hdr] != ((void*)0)"
, "Unregistered hf.")))) ; hf = gpa_hfinfo.hfi[hf_hdr];
;
13520 DISSECTOR_ASSERT_FIELD_TYPE_IS_INTEGRAL(hf)((void) (((((((hf)->type) == FT_INT8 || ((hf)->type) ==
FT_INT16 || ((hf)->type) == FT_INT24 || ((hf)->type) ==
FT_INT32) || (((hf)->type) == FT_INT40 || ((hf)->type)
== FT_INT48 || ((hf)->type) == FT_INT56 || ((hf)->type
) == FT_INT64)) || ((((hf)->type) == FT_CHAR || ((hf)->
type) == FT_UINT8 || ((hf)->type) == FT_UINT16 || ((hf)->
type) == FT_UINT24 || ((hf)->type) == FT_UINT32 || ((hf)->
type) == FT_FRAMENUM) || (((hf)->type) == FT_UINT40 || ((hf
)->type) == FT_UINT48 || ((hf)->type) == FT_UINT56 || (
(hf)->type) == FT_UINT64)))) ? (void)0 : proto_report_dissector_bug
("%s:%u: field %s is not of type FT_CHAR or an FT_{U}INTn type"
, "epan/proto.c", 13520, (hf)->abbrev)))
;
13521 /* the proto_tree_add_uint/_uint64() calls below
13522 will fail if tvb==NULL and len!=0 */
13523 len = tvb ? ftype_wire_size(hf->type) : 0;
13524
13525 if (parent_tree) {
13526 if (len <= 4)
13527 item = proto_tree_add_uint(parent_tree, hf_hdr, tvb, offset, len, (uint32_t)value);
13528 else
13529 item = proto_tree_add_uint64(parent_tree, hf_hdr, tvb, offset, len, value);
13530
13531 proto_item_add_bitmask_tree(item, tvb, offset, len, ett, fields,
13532 flags, false0, false0, NULL((void*)0), value);
13533 }
13534
13535 return item;
13536}
13537
13538/* Similar to proto_tree_add_bitmask(), but with no "header" item to group all of the fields */
13539void
13540proto_tree_add_bitmask_list(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
13541 const unsigned len, int * const *fields, const unsigned encoding)
13542{
13543 uint64_t value;
13544
13545 if (tree) {
13546 value = get_uint64_value(tree, tvb, offset, len, encoding);
13547 proto_item_add_bitmask_tree(NULL((void*)0), tvb, offset, len, -1, fields,
13548 BMT_NO_APPEND0x01, false0, true1, tree, value);
13549 }
13550}
13551
13552WS_DLL_PUBLIC__attribute__ ((visibility ("default"))) extern void
13553proto_tree_add_bitmask_list_ret_uint64(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
13554 const unsigned len, int * const *fields, const unsigned encoding, uint64_t *retval)
13555{
13556 uint64_t value;
13557
13558 value = get_uint64_value(tree, tvb, offset, len, encoding);
13559 if (tree) {
13560 proto_item_add_bitmask_tree(NULL((void*)0), tvb, offset, len, -1, fields,
13561 BMT_NO_APPEND0x01, false0, true1, tree, value);
13562 }
13563 if (retval) {
13564 *retval = value;
13565 }
13566}
13567
13568WS_DLL_PUBLIC__attribute__ ((visibility ("default"))) extern void
13569proto_tree_add_bitmask_list_value(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
13570 const unsigned len, int * const *fields, const uint64_t value)
13571{
13572 if (tree) {
13573 proto_item_add_bitmask_tree(NULL((void*)0), tvb, offset, len, -1, fields,
13574 BMT_NO_APPEND0x01, false0, true1, tree, value);
13575 }
13576}
13577
13578
13579/* The same as proto_tree_add_bitmask(), but using a caller-supplied length.
13580 * This is intended to support bitmask fields whose lengths can vary, perhaps
13581 * as the underlying standard evolves over time.
13582 * With this API there is the possibility of being called to display more or
13583 * less data than the dissector was coded to support.
13584 * In such cases, it is assumed that bitmasks are extended on the MSb end.
13585 * Thus when presented with "too much" or "too little" data, MSbits will be
13586 * ignored or MSfields sacrificed.
13587 *
13588 * Only fields for which all defined bits are available are displayed.
13589 */
13590proto_item *
13591proto_tree_add_bitmask_len(proto_tree *parent_tree, tvbuff_t *tvb,
13592 const unsigned offset, const unsigned len, const int hf_hdr,
13593 const int ett, int * const *fields, struct expert_field* exp,
13594 const unsigned encoding)
13595{
13596 proto_item *item = NULL((void*)0);
13597 header_field_info *hf;
13598 unsigned decodable_len;
13599 unsigned decodable_offset;
13600 uint32_t decodable_value;
13601 uint64_t value;
13602
13603 PROTO_REGISTRAR_GET_NTH(hf_hdr, hf)if((hf_hdr == 0 || (unsigned)hf_hdr > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 13603, __func__, "Unregistered hf! index=%d"
, hf_hdr); ((void) ((hf_hdr > 0 && (unsigned)hf_hdr
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 13603
, "hf_hdr > 0 && (unsigned)hf_hdr < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hf_hdr] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13603, "gpa_hfinfo.hfi[hf_hdr] != ((void*)0)"
, "Unregistered hf.")))) ; hf = gpa_hfinfo.hfi[hf_hdr];
;
13604 DISSECTOR_ASSERT_FIELD_TYPE_IS_INTEGRAL(hf)((void) (((((((hf)->type) == FT_INT8 || ((hf)->type) ==
FT_INT16 || ((hf)->type) == FT_INT24 || ((hf)->type) ==
FT_INT32) || (((hf)->type) == FT_INT40 || ((hf)->type)
== FT_INT48 || ((hf)->type) == FT_INT56 || ((hf)->type
) == FT_INT64)) || ((((hf)->type) == FT_CHAR || ((hf)->
type) == FT_UINT8 || ((hf)->type) == FT_UINT16 || ((hf)->
type) == FT_UINT24 || ((hf)->type) == FT_UINT32 || ((hf)->
type) == FT_FRAMENUM) || (((hf)->type) == FT_UINT40 || ((hf
)->type) == FT_UINT48 || ((hf)->type) == FT_UINT56 || (
(hf)->type) == FT_UINT64)))) ? (void)0 : proto_report_dissector_bug
("%s:%u: field %s is not of type FT_CHAR or an FT_{U}INTn type"
, "epan/proto.c", 13604, (hf)->abbrev)))
;
13605
13606 decodable_offset = offset;
13607 decodable_len = MIN(len, (unsigned) ftype_wire_size(hf->type))(((len) < ((unsigned) ftype_wire_size(hf->type))) ? (len
) : ((unsigned) ftype_wire_size(hf->type)))
;
13608
13609 /* If we are ftype_wire_size-limited,
13610 * make sure we decode as many LSBs as possible.
13611 */
13612 if (encoding == ENC_BIG_ENDIAN0x00000000) {
13613 decodable_offset += (len - decodable_len);
13614 }
13615
13616 if (parent_tree) {
13617 decodable_value = get_uint_value(parent_tree, tvb, decodable_offset,
13618 decodable_len, encoding);
13619
13620 /* The root item covers all the bytes even if we can't decode them all */
13621 item = proto_tree_add_uint(parent_tree, hf_hdr, tvb, offset, len,
13622 decodable_value);
13623 }
13624
13625 if (decodable_len < len) {
13626 /* Dissector likely requires updating for new protocol revision */
13627 expert_add_info_format(NULL((void*)0), item, exp,
13628 "Only least-significant %d of %d bytes decoded",
13629 decodable_len, len);
13630 }
13631
13632 if (item) {
13633 value = get_uint64_value(parent_tree, tvb, decodable_offset, decodable_len, encoding);
13634 proto_item_add_bitmask_tree(item, tvb, decodable_offset, decodable_len,
13635 ett, fields, BMT_NO_INT0x02|BMT_NO_TFS0x08, false0, false0, NULL((void*)0), value);
13636 }
13637
13638 return item;
13639}
13640
13641/* The same as proto_tree_add_bitmask(), but using an arbitrary text as a top-level item */
13642proto_item *
13643proto_tree_add_bitmask_text(proto_tree *parent_tree, tvbuff_t *tvb,
13644 const unsigned offset, const unsigned len,
13645 const char *name, const char *fallback,
13646 const int ett, int * const *fields,
13647 const unsigned encoding, const int flags)
13648{
13649 proto_item *item = NULL((void*)0);
13650 uint64_t value;
13651
13652 if (parent_tree) {
13653 item = proto_tree_add_text_internal(parent_tree, tvb, offset, len, "%s", name ? name : "");
13654 value = get_uint64_value(parent_tree, tvb, offset, len, encoding);
13655 if (proto_item_add_bitmask_tree(item, tvb, offset, len, ett, fields,
13656 flags, true1, false0, NULL((void*)0), value) && fallback) {
13657 /* Still at first item - append 'fallback' text if any */
13658 proto_item_append_text(item, "%s", fallback);
13659 }
13660 }
13661
13662 return item;
13663}
13664
13665proto_item *
13666proto_tree_add_bits_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
13667 const unsigned bit_offset, const int no_of_bits,
13668 const unsigned encoding)
13669{
13670 header_field_info *hfinfo;
13671 int octet_length;
13672 unsigned octet_offset;
13673
13674 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 13674, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 13674
, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13674, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
13675
13676 if (no_of_bits < 0) {
13677 THROW(ReportedBoundsError)except_throw(1, (3), ((void*)0));
13678 }
13679 octet_length = (no_of_bits + 7) >> 3;
13680 octet_offset = bit_offset >> 3;
13681 test_length(hfinfo, tvb, octet_offset, octet_length, encoding);
13682
13683 /* Yes, we try to fake this item again in proto_tree_add_bits_ret_val()
13684 * but only after doing a bunch more work (which we can, in the common
13685 * case, shortcut here).
13686 */
13687 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
13688 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 13688
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13688, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13688, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 13688, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
13689
13690 return proto_tree_add_bits_ret_val(tree, hfindex, tvb, bit_offset, no_of_bits, NULL((void*)0), encoding);
13691}
13692
13693/*
13694 * This function will dissect a sequence of bits that does not need to be byte aligned; the bits
13695 * set will be shown in the tree as ..10 10.. and the integer value returned if return_value is set.
13696 * Offset should be given in bits from the start of the tvb.
13697 */
13698
13699static proto_item *
13700_proto_tree_add_bits_ret_val(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
13701 const unsigned bit_offset, const int no_of_bits,
13702 uint64_t *return_value, const unsigned encoding)
13703{
13704 unsigned offset;
13705 unsigned length;
13706 uint8_t tot_no_bits;
13707 char *bf_str;
13708 char lbl_str[ITEM_LABEL_LENGTH240];
13709 uint64_t value = 0;
13710 uint8_t *bytes = NULL((void*)0);
13711 size_t bytes_length = 0;
13712
13713 proto_item *pi;
13714 header_field_info *hf_field;
13715
13716 /* We can't fake it just yet. We have to fill in the 'return_value' parameter */
13717 PROTO_REGISTRAR_GET_NTH(hfindex, hf_field)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 13717, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 13717
, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13717, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hf_field = gpa_hfinfo.hfi[hfindex]
;
;
13718
13719 if (hf_field->bitmask != 0) {
13720 REPORT_DISSECTOR_BUG("Incompatible use of proto_tree_add_bits_ret_val"proto_report_dissector_bug("Incompatible use of proto_tree_add_bits_ret_val"
" with field '%s' (%s) with bitmask != 0", hf_field->abbrev
, hf_field->name)
13721 " with field '%s' (%s) with bitmask != 0",proto_report_dissector_bug("Incompatible use of proto_tree_add_bits_ret_val"
" with field '%s' (%s) with bitmask != 0", hf_field->abbrev
, hf_field->name)
13722 hf_field->abbrev, hf_field->name)proto_report_dissector_bug("Incompatible use of proto_tree_add_bits_ret_val"
" with field '%s' (%s) with bitmask != 0", hf_field->abbrev
, hf_field->name)
;
13723 }
13724
13725 if (no_of_bits < 0) {
13726 THROW(ReportedBoundsError)except_throw(1, (3), ((void*)0));
13727 } else if (no_of_bits == 0) {
13728 REPORT_DISSECTOR_BUG("field %s passed to proto_tree_add_bits_ret_val() has a bit width of 0",proto_report_dissector_bug("field %s passed to proto_tree_add_bits_ret_val() has a bit width of 0"
, hf_field->abbrev)
13729 hf_field->abbrev)proto_report_dissector_bug("field %s passed to proto_tree_add_bits_ret_val() has a bit width of 0"
, hf_field->abbrev)
;
13730 }
13731
13732 /* Byte align offset */
13733 offset = bit_offset>>3;
13734
13735 /*
13736 * Calculate the number of octets used to hold the bits
13737 */
13738 tot_no_bits = ((bit_offset&0x7) + no_of_bits);
13739 length = (tot_no_bits + 7) >> 3;
13740
13741 if (no_of_bits < 65) {
13742 value = tvb_get_bits64(tvb, bit_offset, no_of_bits, encoding);
13743 } else if (hf_field->type != FT_BYTES) {
13744 REPORT_DISSECTOR_BUG("field %s passed to proto_tree_add_bits_ret_val() has a bit width of %u > 64",proto_report_dissector_bug("field %s passed to proto_tree_add_bits_ret_val() has a bit width of %u > 64"
, hf_field->abbrev, no_of_bits)
13745 hf_field->abbrev, no_of_bits)proto_report_dissector_bug("field %s passed to proto_tree_add_bits_ret_val() has a bit width of %u > 64"
, hf_field->abbrev, no_of_bits)
;
13746 return NULL((void*)0);
13747 }
13748
13749 /* Sign extend for signed types */
13750 switch (hf_field->type) {
13751 case FT_INT8:
13752 case FT_INT16:
13753 case FT_INT24:
13754 case FT_INT32:
13755 case FT_INT40:
13756 case FT_INT48:
13757 case FT_INT56:
13758 case FT_INT64:
13759 value = ws_sign_ext64(value, no_of_bits);
13760 break;
13761
13762 default:
13763 break;
13764 }
13765
13766 if (return_value) {
13767 *return_value = value;
13768 }
13769
13770 /* Coast clear. Try and fake it */
13771 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
13772 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hf_field)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 13772
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13772, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13772, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hf_field = gpa_hfinfo.hfi[hfindex]
;; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 13772, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items); ((tree)->
tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items))); } if (!((
(tree)->tree_data)->visible)) { if (proto_item_is_hidden
((tree))) { if ((hf_field->ref_type != HF_REF_TYPE_DIRECT)
&& (hf_field->ref_type != HF_REF_TYPE_PRINT) &&
(hf_field->type != FT_PROTOCOL || ((tree)->tree_data)->
fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(tree, hf_field); } } }
;
13773
13774 bf_str = decode_bits_in_field(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool), bit_offset, no_of_bits, value, encoding);
13775
13776 switch (hf_field->type) {
13777 case FT_BOOLEAN:
13778 /* Boolean field */
13779 return proto_tree_add_boolean_format(tree, hfindex, tvb, offset, length, value,
13780 "%s = %s: %s",
13781 bf_str, hf_field->name, tfs_get_string(!!value, hf_field->strings));
13782 break;
13783
13784 case FT_CHAR:
13785 pi = proto_tree_add_uint(tree, hfindex, tvb, offset, length, (uint32_t)value);
13786 fill_label_char(PITEM_FINFO(pi)((pi)->finfo), lbl_str, NULL((void*)0));
13787 break;
13788
13789 case FT_UINT8:
13790 case FT_UINT16:
13791 case FT_UINT24:
13792 case FT_UINT32:
13793 pi = proto_tree_add_uint(tree, hfindex, tvb, offset, length, (uint32_t)value);
13794 fill_label_number(PITEM_FINFO(pi)((pi)->finfo), lbl_str, NULL((void*)0), false0);
13795 break;
13796
13797 case FT_INT8:
13798 case FT_INT16:
13799 case FT_INT24:
13800 case FT_INT32:
13801 pi = proto_tree_add_int(tree, hfindex, tvb, offset, length, (int32_t)value);
13802 fill_label_number(PITEM_FINFO(pi)((pi)->finfo), lbl_str, NULL((void*)0), true1);
13803 break;
13804
13805 case FT_UINT40:
13806 case FT_UINT48:
13807 case FT_UINT56:
13808 case FT_UINT64:
13809 pi = proto_tree_add_uint64(tree, hfindex, tvb, offset, length, value);
13810 fill_label_number64(PITEM_FINFO(pi)((pi)->finfo), lbl_str, NULL((void*)0), false0);
13811 break;
13812
13813 case FT_INT40:
13814 case FT_INT48:
13815 case FT_INT56:
13816 case FT_INT64:
13817 pi = proto_tree_add_int64(tree, hfindex, tvb, offset, length, (int64_t)value);
13818 fill_label_number64(PITEM_FINFO(pi)((pi)->finfo), lbl_str, NULL((void*)0), true1);
13819 break;
13820
13821 case FT_BYTES:
13822 bytes = tvb_get_bits_array(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool), tvb, bit_offset, no_of_bits, &bytes_length, encoding);
13823 pi = proto_tree_add_bytes_with_length(tree, hfindex, tvb, offset, length, bytes, (int) bytes_length);
13824 proto_item_fill_label(PITEM_FINFO(pi)((pi)->finfo), lbl_str, NULL((void*)0));
13825 proto_item_set_text(pi, "%s", lbl_str);
13826 return pi;
13827
13828 /* TODO: should handle FT_UINT_BYTES ? */
13829
13830 default:
13831 REPORT_DISSECTOR_BUG("field %s has type %d (%s) not handled in proto_tree_add_bits_ret_val()",proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_tree_add_bits_ret_val()"
, hf_field->abbrev, hf_field->type, ftype_name(hf_field
->type))
13832 hf_field->abbrev,proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_tree_add_bits_ret_val()"
, hf_field->abbrev, hf_field->type, ftype_name(hf_field
->type))
13833 hf_field->type,proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_tree_add_bits_ret_val()"
, hf_field->abbrev, hf_field->type, ftype_name(hf_field
->type))
13834 ftype_name(hf_field->type))proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_tree_add_bits_ret_val()"
, hf_field->abbrev, hf_field->type, ftype_name(hf_field
->type))
;
13835 return NULL((void*)0);
13836 }
13837
13838 proto_item_set_text(pi, "%s = %s", bf_str, lbl_str);
13839 return pi;
13840}
13841
13842proto_item *
13843proto_tree_add_split_bits_item_ret_val(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
13844 const unsigned bit_offset, const crumb_spec_t *crumb_spec,
13845 uint64_t *return_value)
13846{
13847 proto_item *pi;
13848 int no_of_bits;
13849 unsigned octet_offset;
13850 unsigned mask_initial_bit_offset;
13851 unsigned mask_greatest_bit_offset;
13852 unsigned octet_length;
13853 uint8_t i;
13854 char bf_str[256];
13855 char lbl_str[ITEM_LABEL_LENGTH240];
13856 uint64_t value;
13857 uint64_t composite_bitmask;
13858 uint64_t composite_bitmap;
13859
13860 header_field_info *hf_field;
13861
13862 /* We can't fake it just yet. We have to fill in the 'return_value' parameter */
13863 PROTO_REGISTRAR_GET_NTH(hfindex, hf_field)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 13863, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 13863
, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13863, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hf_field = gpa_hfinfo.hfi[hfindex]
;
;
13864
13865 if (hf_field->bitmask != 0) {
13866 REPORT_DISSECTOR_BUG("Incompatible use of proto_tree_add_split_bits_item_ret_val"proto_report_dissector_bug("Incompatible use of proto_tree_add_split_bits_item_ret_val"
" with field '%s' (%s) with bitmask != 0", hf_field->abbrev
, hf_field->name)
13867 " with field '%s' (%s) with bitmask != 0",proto_report_dissector_bug("Incompatible use of proto_tree_add_split_bits_item_ret_val"
" with field '%s' (%s) with bitmask != 0", hf_field->abbrev
, hf_field->name)
13868 hf_field->abbrev, hf_field->name)proto_report_dissector_bug("Incompatible use of proto_tree_add_split_bits_item_ret_val"
" with field '%s' (%s) with bitmask != 0", hf_field->abbrev
, hf_field->name)
;
13869 }
13870
13871 mask_initial_bit_offset = bit_offset % 8;
13872
13873 no_of_bits = 0;
13874 value = 0;
13875 i = 0;
13876 mask_greatest_bit_offset = 0;
13877 composite_bitmask = 0;
13878 composite_bitmap = 0;
13879
13880 while (crumb_spec[i].crumb_bit_length != 0) {
13881 uint64_t crumb_mask, crumb_value;
13882 uint8_t crumb_end_bit_offset;
13883
13884 crumb_value = tvb_get_bits64(tvb,
13885 bit_offset + crumb_spec[i].crumb_bit_offset,
13886 crumb_spec[i].crumb_bit_length,
13887 ENC_BIG_ENDIAN0x00000000);
13888 value += crumb_value;
13889 no_of_bits += crumb_spec[i].crumb_bit_length;
13890 DISSECTOR_ASSERT_HINT(no_of_bits <= 64, "a value larger than 64 bits cannot be represented")((void) ((no_of_bits <= 64) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 13890
, "no_of_bits <= 64", "a value larger than 64 bits cannot be represented"
))))
;
13891
13892 /* The bitmask is 64 bit, left-aligned, starting at the first bit of the
13893 octet containing the initial offset.
13894 If the mask is beyond 32 bits, then give up on bit map display.
13895 This could be improved in future, probably showing a table
13896 of 32 or 64 bits per row */
13897 if (mask_greatest_bit_offset < 32) {
13898 crumb_end_bit_offset = mask_initial_bit_offset
13899 + crumb_spec[i].crumb_bit_offset
13900 + crumb_spec[i].crumb_bit_length;
13901 crumb_mask = (UINT64_C(1)1UL << crumb_spec[i].crumb_bit_length) - 1;
13902
13903 if (crumb_end_bit_offset > mask_greatest_bit_offset) {
13904 mask_greatest_bit_offset = crumb_end_bit_offset;
13905 }
13906 /* Currently the bitmap of the crumbs are only shown if
13907 * smaller than 32 bits. Do not bother calculating the
13908 * mask if it is larger than that. */
13909 if (crumb_end_bit_offset <= 32) {
13910 composite_bitmask |= (crumb_mask << (64 - crumb_end_bit_offset));
13911 composite_bitmap |= (crumb_value << (64 - crumb_end_bit_offset));
13912 }
13913 }
13914 /* Shift left for the next segment */
13915 value <<= crumb_spec[++i].crumb_bit_length;
13916 }
13917
13918 /* Sign extend for signed types */
13919 switch (hf_field->type) {
13920 case FT_INT8:
13921 case FT_INT16:
13922 case FT_INT24:
13923 case FT_INT32:
13924 case FT_INT40:
13925 case FT_INT48:
13926 case FT_INT56:
13927 case FT_INT64:
13928 value = ws_sign_ext64(value, no_of_bits);
13929 break;
13930 default:
13931 break;
13932 }
13933
13934 if (return_value) {
13935 *return_value = value;
13936 }
13937
13938 /* Coast clear. Try and fake it */
13939 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
13940 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hf_field)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 13940
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13940, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 13940, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hf_field = gpa_hfinfo.hfi[hfindex]
;; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 13940, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items); ((tree)->
tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items))); } if (!((
(tree)->tree_data)->visible)) { if (proto_item_is_hidden
((tree))) { if ((hf_field->ref_type != HF_REF_TYPE_DIRECT)
&& (hf_field->ref_type != HF_REF_TYPE_PRINT) &&
(hf_field->type != FT_PROTOCOL || ((tree)->tree_data)->
fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(tree, hf_field); } } }
;
13941
13942 /* initialise the format string */
13943 bf_str[0] = '\0';
13944
13945 octet_offset = bit_offset >> 3;
13946
13947 /* Round up mask length to nearest octet */
13948 octet_length = ((mask_greatest_bit_offset + 7) >> 3);
13949 mask_greatest_bit_offset = octet_length << 3;
13950
13951 /* As noted above, we currently only produce a bitmap if the crumbs span less than 4 octets of the tvb.
13952 It would be a useful enhancement to eliminate this restriction. */
13953 if (mask_greatest_bit_offset > 0 && mask_greatest_bit_offset <= 32) {
13954 other_decode_bitfield_value(bf_str,
13955 (uint32_t)(composite_bitmap >> (64 - mask_greatest_bit_offset)),
13956 (uint32_t)(composite_bitmask >> (64 - mask_greatest_bit_offset)),
13957 mask_greatest_bit_offset);
13958 } else {
13959 /* If the bitmask is too large, try to describe its contents. */
13960 snprintf(bf_str, sizeof(bf_str), "%d bits", no_of_bits);
13961 }
13962
13963 switch (hf_field->type) {
13964 case FT_BOOLEAN: /* it is a bit odd to have a boolean encoded as split-bits, but possible, I suppose? */
13965 /* Boolean field */
13966 return proto_tree_add_boolean_format(tree, hfindex,
13967 tvb, octet_offset, octet_length, value,
13968 "%s = %s: %s",
13969 bf_str, hf_field->name, tfs_get_string(!!value, hf_field->strings));
13970 break;
13971
13972 case FT_CHAR:
13973 pi = proto_tree_add_uint(tree, hfindex, tvb, octet_offset, octet_length, (uint32_t)value);
13974 fill_label_char(PITEM_FINFO(pi)((pi)->finfo), lbl_str, NULL((void*)0));
13975 break;
13976
13977 case FT_UINT8:
13978 case FT_UINT16:
13979 case FT_UINT24:
13980 case FT_UINT32:
13981 pi = proto_tree_add_uint(tree, hfindex, tvb, octet_offset, octet_length, (uint32_t)value);
13982 fill_label_number(PITEM_FINFO(pi)((pi)->finfo), lbl_str, NULL((void*)0), false0);
13983 break;
13984
13985 case FT_INT8:
13986 case FT_INT16:
13987 case FT_INT24:
13988 case FT_INT32:
13989 pi = proto_tree_add_int(tree, hfindex, tvb, octet_offset, octet_length, (int32_t)value);
13990 fill_label_number(PITEM_FINFO(pi)((pi)->finfo), lbl_str, NULL((void*)0), true1);
13991 break;
13992
13993 case FT_UINT40:
13994 case FT_UINT48:
13995 case FT_UINT56:
13996 case FT_UINT64:
13997 pi = proto_tree_add_uint64(tree, hfindex, tvb, octet_offset, octet_length, value);
13998 fill_label_number64(PITEM_FINFO(pi)((pi)->finfo), lbl_str, NULL((void*)0), false0);
13999 break;
14000
14001 case FT_INT40:
14002 case FT_INT48:
14003 case FT_INT56:
14004 case FT_INT64:
14005 pi = proto_tree_add_int64(tree, hfindex, tvb, octet_offset, octet_length, (int64_t)value);
14006 fill_label_number64(PITEM_FINFO(pi)((pi)->finfo), lbl_str, NULL((void*)0), true1);
14007 break;
14008
14009 default:
14010 REPORT_DISSECTOR_BUG("field %s has type %d (%s) not handled in proto_tree_add_split_bits_item_ret_val()",proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_tree_add_split_bits_item_ret_val()"
, hf_field->abbrev, hf_field->type, ftype_name(hf_field
->type))
14011 hf_field->abbrev,proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_tree_add_split_bits_item_ret_val()"
, hf_field->abbrev, hf_field->type, ftype_name(hf_field
->type))
14012 hf_field->type,proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_tree_add_split_bits_item_ret_val()"
, hf_field->abbrev, hf_field->type, ftype_name(hf_field
->type))
14013 ftype_name(hf_field->type))proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_tree_add_split_bits_item_ret_val()"
, hf_field->abbrev, hf_field->type, ftype_name(hf_field
->type))
;
14014 return NULL((void*)0);
14015 }
14016 proto_item_set_text(pi, "%s = %s", bf_str, lbl_str);
14017 return pi;
14018}
14019
14020void
14021proto_tree_add_split_bits_crumb(proto_tree *tree, const int hfindex, tvbuff_t *tvb, const unsigned bit_offset,
14022 const crumb_spec_t *crumb_spec, uint16_t crumb_index)
14023{
14024 header_field_info *hfinfo;
14025 unsigned start = bit_offset >> 3;
14026 unsigned length = ((bit_offset + crumb_spec[crumb_index].crumb_bit_length - 1) >> 3) - (bit_offset >> 3) + 1;
14027
14028 /* We have to duplicate this length check from proto_tree_add_text_internal in order to check for a null tree
14029 * so that we can use the tree's memory scope in calculating the string */
14030 tvb_ensure_bytes_exist(tvb, start, length);
14031 if (!tree) return;
14032
14033 PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo)if((hfindex == 0 || (unsigned)hfindex > gpa_hfinfo.len) &&
wireshark_abort_on_dissector_bug) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 14033, __func__, "Unregistered hf! index=%d"
, hfindex); ((void) ((hfindex > 0 && (unsigned)hfindex
< gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 14033
, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14033, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];
;
14034 proto_tree_add_text_internal(tree, tvb, start, length,
14035 "%s crumb %d of %s (decoded above)",
14036 decode_bits_in_field(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool), bit_offset, crumb_spec[crumb_index].crumb_bit_length,
14037 tvb_get_bits32(tvb,
14038 bit_offset,
14039 crumb_spec[crumb_index].crumb_bit_length,
14040 ENC_BIG_ENDIAN0x00000000),
14041 ENC_BIG_ENDIAN0x00000000),
14042 crumb_index,
14043 hfinfo->name);
14044}
14045
14046proto_item *
14047proto_tree_add_bits_ret_val(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
14048 const unsigned bit_offset, const int no_of_bits,
14049 uint64_t *return_value, const unsigned encoding)
14050{
14051 proto_item *item;
14052
14053 if ((item = _proto_tree_add_bits_ret_val(tree, hfindex, tvb,
14054 bit_offset, no_of_bits,
14055 return_value, encoding))) {
14056 FI_SET_FLAG(PNODE_FINFO(item), FI_BITS_OFFSET(bit_offset&0x7))do { if (((item)->finfo)) (((item)->finfo))->flags =
(((item)->finfo))->flags | ((((bit_offset&0x7) &
63) << 5)); } while(0)
;
14057 FI_SET_FLAG(PNODE_FINFO(item), FI_BITS_SIZE(no_of_bits))do { if (((item)->finfo)) (((item)->finfo))->flags =
(((item)->finfo))->flags | ((((no_of_bits) & 63) <<
12)); } while(0)
;
14058 }
14059 return item;
14060}
14061
14062static proto_item *
14063_proto_tree_add_bits_format_value(proto_tree *tree, const int hfindex,
14064 tvbuff_t *tvb, const unsigned bit_offset,
14065 const int no_of_bits, void *value_ptr,
14066 const unsigned encoding, char *value_str)
14067{
14068 unsigned offset;
14069 unsigned length;
14070 uint8_t tot_no_bits;
14071 char *str;
14072 uint64_t value = 0;
14073 header_field_info *hf_field;
14074
14075 /* We do not have to return a value, try to fake it as soon as possible */
14076 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
14077 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hf_field)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14077
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14077, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14077, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hf_field = gpa_hfinfo.hfi[hfindex]
;; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14077, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items); ((tree)->
tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items))); } if (!((
(tree)->tree_data)->visible)) { if (proto_item_is_hidden
((tree))) { if ((hf_field->ref_type != HF_REF_TYPE_DIRECT)
&& (hf_field->ref_type != HF_REF_TYPE_PRINT) &&
(hf_field->type != FT_PROTOCOL || ((tree)->tree_data)->
fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(tree, hf_field); } } }
;
14078
14079 if (hf_field->bitmask != 0) {
14080 REPORT_DISSECTOR_BUG("Incompatible use of proto_tree_add_bits_format_value"proto_report_dissector_bug("Incompatible use of proto_tree_add_bits_format_value"
" with field '%s' (%s) with bitmask != 0", hf_field->abbrev
, hf_field->name)
14081 " with field '%s' (%s) with bitmask != 0",proto_report_dissector_bug("Incompatible use of proto_tree_add_bits_format_value"
" with field '%s' (%s) with bitmask != 0", hf_field->abbrev
, hf_field->name)
14082 hf_field->abbrev, hf_field->name)proto_report_dissector_bug("Incompatible use of proto_tree_add_bits_format_value"
" with field '%s' (%s) with bitmask != 0", hf_field->abbrev
, hf_field->name)
;
14083 }
14084
14085 if (no_of_bits < 0) {
14086 THROW(ReportedBoundsError)except_throw(1, (3), ((void*)0));
14087 } else if (no_of_bits == 0) {
14088 REPORT_DISSECTOR_BUG("field %s passed to proto_tree_add_bits_format_value() has a bit width of 0",proto_report_dissector_bug("field %s passed to proto_tree_add_bits_format_value() has a bit width of 0"
, hf_field->abbrev)
14089 hf_field->abbrev)proto_report_dissector_bug("field %s passed to proto_tree_add_bits_format_value() has a bit width of 0"
, hf_field->abbrev)
;
14090 }
14091
14092 /* Byte align offset */
14093 offset = bit_offset>>3;
14094
14095 /*
14096 * Calculate the number of octets used to hold the bits
14097 */
14098 tot_no_bits = ((bit_offset&0x7) + no_of_bits);
14099 length = tot_no_bits>>3;
14100 /* If we are using part of the next octet, increase length by 1 */
14101 if (tot_no_bits & 0x07)
14102 length++;
14103
14104 if (no_of_bits < 65) {
14105 value = tvb_get_bits64(tvb, bit_offset, no_of_bits, encoding);
14106 } else {
14107 REPORT_DISSECTOR_BUG("field %s passed to proto_tree_add_bits_format_value() has a bit width of %u > 65",proto_report_dissector_bug("field %s passed to proto_tree_add_bits_format_value() has a bit width of %u > 65"
, hf_field->abbrev, no_of_bits)
14108 hf_field->abbrev, no_of_bits)proto_report_dissector_bug("field %s passed to proto_tree_add_bits_format_value() has a bit width of %u > 65"
, hf_field->abbrev, no_of_bits)
;
14109 return NULL((void*)0);
14110 }
14111
14112 str = decode_bits_in_field(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool), bit_offset, no_of_bits, value, encoding);
14113
14114 (void) g_strlcat(str, " = ", 256+64);
14115 (void) g_strlcat(str, hf_field->name, 256+64);
14116
14117 /*
14118 * This function does not receive an actual value but a dimensionless pointer to that value.
14119 * For this reason, the type of the header field is examined in order to determine
14120 * what kind of value we should read from this address.
14121 * The caller of this function must make sure that for the specific header field type the address of
14122 * a compatible value is provided.
14123 */
14124 switch (hf_field->type) {
14125 case FT_BOOLEAN:
14126 return proto_tree_add_boolean_format(tree, hfindex, tvb, offset, length, *(uint64_t *)value_ptr,
14127 "%s: %s", str, value_str);
14128 break;
14129
14130 case FT_CHAR:
14131 case FT_UINT8:
14132 case FT_UINT16:
14133 case FT_UINT24:
14134 case FT_UINT32:
14135 return proto_tree_add_uint_format(tree, hfindex, tvb, offset, length, *(uint32_t *)value_ptr,
14136 "%s: %s", str, value_str);
14137 break;
14138
14139 case FT_UINT40:
14140 case FT_UINT48:
14141 case FT_UINT56:
14142 case FT_UINT64:
14143 return proto_tree_add_uint64_format(tree, hfindex, tvb, offset, length, *(uint64_t *)value_ptr,
14144 "%s: %s", str, value_str);
14145 break;
14146
14147 case FT_INT8:
14148 case FT_INT16:
14149 case FT_INT24:
14150 case FT_INT32:
14151 return proto_tree_add_int_format(tree, hfindex, tvb, offset, length, *(int32_t *)value_ptr,
14152 "%s: %s", str, value_str);
14153 break;
14154
14155 case FT_INT40:
14156 case FT_INT48:
14157 case FT_INT56:
14158 case FT_INT64:
14159 return proto_tree_add_int64_format(tree, hfindex, tvb, offset, length, *(int64_t *)value_ptr,
14160 "%s: %s", str, value_str);
14161 break;
14162
14163 case FT_FLOAT:
14164 return proto_tree_add_float_format(tree, hfindex, tvb, offset, length, *(float *)value_ptr,
14165 "%s: %s", str, value_str);
14166 break;
14167
14168 default:
14169 REPORT_DISSECTOR_BUG("field %s has type %d (%s) not handled in proto_tree_add_bits_format_value()",proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_tree_add_bits_format_value()"
, hf_field->abbrev, hf_field->type, ftype_name(hf_field
->type))
14170 hf_field->abbrev,proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_tree_add_bits_format_value()"
, hf_field->abbrev, hf_field->type, ftype_name(hf_field
->type))
14171 hf_field->type,proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_tree_add_bits_format_value()"
, hf_field->abbrev, hf_field->type, ftype_name(hf_field
->type))
14172 ftype_name(hf_field->type))proto_report_dissector_bug("field %s has type %d (%s) not handled in proto_tree_add_bits_format_value()"
, hf_field->abbrev, hf_field->type, ftype_name(hf_field
->type))
;
14173 return NULL((void*)0);
14174 }
14175}
14176
14177static proto_item *
14178proto_tree_add_bits_format_value(proto_tree *tree, const int hfindex,
14179 tvbuff_t *tvb, const unsigned bit_offset,
14180 const int no_of_bits, void *value_ptr,
14181 const unsigned encoding, char *value_str)
14182{
14183 proto_item *item;
14184
14185 if ((item = _proto_tree_add_bits_format_value(tree, hfindex,
14186 tvb, bit_offset, no_of_bits,
14187 value_ptr, encoding, value_str))) {
14188 FI_SET_FLAG(PNODE_FINFO(item), FI_BITS_OFFSET(bit_offset&0x7))do { if (((item)->finfo)) (((item)->finfo))->flags =
(((item)->finfo))->flags | ((((bit_offset&0x7) &
63) << 5)); } while(0)
;
14189 FI_SET_FLAG(PNODE_FINFO(item), FI_BITS_SIZE(no_of_bits))do { if (((item)->finfo)) (((item)->finfo))->flags =
(((item)->finfo))->flags | ((((no_of_bits) & 63) <<
12)); } while(0)
;
14190 }
14191 return item;
14192}
14193
14194#define CREATE_VALUE_STRING(tree,dst,format,ap)__builtin_va_start(ap, format); dst = wmem_strdup_vprintf(((tree
)->tree_data->pinfo->pool), format, ap); __builtin_va_end
(ap);
\
14195 va_start(ap, format)__builtin_va_start(ap, format); \
14196 dst = wmem_strdup_vprintf(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool), format, ap); \
14197 va_end(ap)__builtin_va_end(ap);
14198
14199proto_item *
14200proto_tree_add_uint_bits_format_value(proto_tree *tree, const int hfindex,
14201 tvbuff_t *tvb, const unsigned bit_offset,
14202 const int no_of_bits, uint32_t value,
14203 const unsigned encoding,
14204 const char *format, ...)
14205{
14206 va_list ap;
14207 char *dst;
14208 header_field_info *hf_field;
14209
14210 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
14211
14212 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hf_field)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14212
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14212, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14212, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hf_field = gpa_hfinfo.hfi[hfindex]
;; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14212, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items); ((tree)->
tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items))); } if (!((
(tree)->tree_data)->visible)) { if (proto_item_is_hidden
((tree))) { if ((hf_field->ref_type != HF_REF_TYPE_DIRECT)
&& (hf_field->ref_type != HF_REF_TYPE_PRINT) &&
(hf_field->type != FT_PROTOCOL || ((tree)->tree_data)->
fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(tree, hf_field); } } }
;
14213
14214 switch (hf_field->type) {
14215 case FT_UINT8:
14216 case FT_UINT16:
14217 case FT_UINT24:
14218 case FT_UINT32:
14219 break;
14220
14221 default:
14222 REPORT_DISSECTOR_BUG("field %s is not of type FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32",proto_report_dissector_bug("field %s is not of type FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32"
, hf_field->abbrev)
14223 hf_field->abbrev)proto_report_dissector_bug("field %s is not of type FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32"
, hf_field->abbrev)
;
14224 return NULL((void*)0);
14225 }
14226
14227 CREATE_VALUE_STRING(tree, dst, format, ap)__builtin_va_start(ap, format); dst = wmem_strdup_vprintf(((tree
)->tree_data->pinfo->pool), format, ap); __builtin_va_end
(ap);
;
14228
14229 return proto_tree_add_bits_format_value(tree, hfindex, tvb, bit_offset, no_of_bits, &value, encoding, dst);
14230}
14231
14232proto_item *
14233proto_tree_add_uint64_bits_format_value(proto_tree *tree, const int hfindex,
14234 tvbuff_t *tvb, const unsigned bit_offset,
14235 const int no_of_bits, uint64_t value,
14236 const unsigned encoding,
14237 const char *format, ...)
14238{
14239 va_list ap;
14240 char *dst;
14241 header_field_info *hf_field;
14242
14243 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
14244
14245 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hf_field)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14245
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14245, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14245, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hf_field = gpa_hfinfo.hfi[hfindex]
;; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14245, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items); ((tree)->
tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items))); } if (!((
(tree)->tree_data)->visible)) { if (proto_item_is_hidden
((tree))) { if ((hf_field->ref_type != HF_REF_TYPE_DIRECT)
&& (hf_field->ref_type != HF_REF_TYPE_PRINT) &&
(hf_field->type != FT_PROTOCOL || ((tree)->tree_data)->
fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(tree, hf_field); } } }
;
14246
14247 switch (hf_field->type) {
14248 case FT_UINT40:
14249 case FT_UINT48:
14250 case FT_UINT56:
14251 case FT_UINT64:
14252 break;
14253
14254 default:
14255 REPORT_DISSECTOR_BUG("field %s is not of type FT_UINT40, FT_UINT48, FT_UINT56, or FT_UINT64",proto_report_dissector_bug("field %s is not of type FT_UINT40, FT_UINT48, FT_UINT56, or FT_UINT64"
, hf_field->abbrev)
14256 hf_field->abbrev)proto_report_dissector_bug("field %s is not of type FT_UINT40, FT_UINT48, FT_UINT56, or FT_UINT64"
, hf_field->abbrev)
;
14257 return NULL((void*)0);
14258 }
14259
14260 CREATE_VALUE_STRING(tree, dst, format, ap)__builtin_va_start(ap, format); dst = wmem_strdup_vprintf(((tree
)->tree_data->pinfo->pool), format, ap); __builtin_va_end
(ap);
;
14261
14262 return proto_tree_add_bits_format_value(tree, hfindex, tvb, bit_offset, no_of_bits, &value, encoding, dst);
14263}
14264
14265proto_item *
14266proto_tree_add_float_bits_format_value(proto_tree *tree, const int hfindex,
14267 tvbuff_t *tvb, const unsigned bit_offset,
14268 const int no_of_bits, float value,
14269 const unsigned encoding,
14270 const char *format, ...)
14271{
14272 va_list ap;
14273 char *dst;
14274 header_field_info *hf_field;
14275
14276 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
14277
14278 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hf_field)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14278
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14278, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14278, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hf_field = gpa_hfinfo.hfi[hfindex]
;; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14278, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items); ((tree)->
tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items))); } if (!((
(tree)->tree_data)->visible)) { if (proto_item_is_hidden
((tree))) { if ((hf_field->ref_type != HF_REF_TYPE_DIRECT)
&& (hf_field->ref_type != HF_REF_TYPE_PRINT) &&
(hf_field->type != FT_PROTOCOL || ((tree)->tree_data)->
fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(tree, hf_field); } } }
;
14279
14280 DISSECTOR_ASSERT_FIELD_TYPE(hf_field, FT_FLOAT)((void) (((hf_field)->type == FT_FLOAT) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_FLOAT", "epan/proto.c",
14280, ((hf_field))->abbrev))))
;
14281
14282 CREATE_VALUE_STRING(tree, dst, format, ap)__builtin_va_start(ap, format); dst = wmem_strdup_vprintf(((tree
)->tree_data->pinfo->pool), format, ap); __builtin_va_end
(ap);
;
14283
14284 return proto_tree_add_bits_format_value(tree, hfindex, tvb, bit_offset, no_of_bits, &value, encoding, dst);
14285}
14286
14287proto_item *
14288proto_tree_add_int_bits_format_value(proto_tree *tree, const int hfindex,
14289 tvbuff_t *tvb, const unsigned bit_offset,
14290 const int no_of_bits, int32_t value,
14291 const unsigned encoding,
14292 const char *format, ...)
14293{
14294 va_list ap;
14295 char *dst;
14296 header_field_info *hf_field;
14297
14298 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
14299
14300 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hf_field)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14300
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14300, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14300, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hf_field = gpa_hfinfo.hfi[hfindex]
;; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14300, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items); ((tree)->
tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items))); } if (!((
(tree)->tree_data)->visible)) { if (proto_item_is_hidden
((tree))) { if ((hf_field->ref_type != HF_REF_TYPE_DIRECT)
&& (hf_field->ref_type != HF_REF_TYPE_PRINT) &&
(hf_field->type != FT_PROTOCOL || ((tree)->tree_data)->
fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(tree, hf_field); } } }
;
14301
14302 switch (hf_field->type) {
14303 case FT_INT8:
14304 case FT_INT16:
14305 case FT_INT24:
14306 case FT_INT32:
14307 break;
14308
14309 default:
14310 REPORT_DISSECTOR_BUG("field %s is not of type FT_INT8, FT_INT16, FT_INT24, or FT_INT32",proto_report_dissector_bug("field %s is not of type FT_INT8, FT_INT16, FT_INT24, or FT_INT32"
, hf_field->abbrev)
14311 hf_field->abbrev)proto_report_dissector_bug("field %s is not of type FT_INT8, FT_INT16, FT_INT24, or FT_INT32"
, hf_field->abbrev)
;
14312 return NULL((void*)0);
14313 }
14314
14315 CREATE_VALUE_STRING(tree, dst, format, ap)__builtin_va_start(ap, format); dst = wmem_strdup_vprintf(((tree
)->tree_data->pinfo->pool), format, ap); __builtin_va_end
(ap);
;
14316
14317 return proto_tree_add_bits_format_value(tree, hfindex, tvb, bit_offset, no_of_bits, &value, encoding, dst);
14318}
14319
14320proto_item *
14321proto_tree_add_int64_bits_format_value(proto_tree *tree, const int hfindex,
14322 tvbuff_t *tvb, const unsigned bit_offset,
14323 const int no_of_bits, int64_t value,
14324 const unsigned encoding,
14325 const char *format, ...)
14326{
14327 va_list ap;
14328 char *dst;
14329 header_field_info *hf_field;
14330
14331 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
14332
14333 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hf_field)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14333
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14333, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14333, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hf_field = gpa_hfinfo.hfi[hfindex]
;; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14333, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items); ((tree)->
tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items))); } if (!((
(tree)->tree_data)->visible)) { if (proto_item_is_hidden
((tree))) { if ((hf_field->ref_type != HF_REF_TYPE_DIRECT)
&& (hf_field->ref_type != HF_REF_TYPE_PRINT) &&
(hf_field->type != FT_PROTOCOL || ((tree)->tree_data)->
fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(tree, hf_field); } } }
;
14334
14335 switch (hf_field->type) {
14336 case FT_INT40:
14337 case FT_INT48:
14338 case FT_INT56:
14339 case FT_INT64:
14340 break;
14341
14342 default:
14343 REPORT_DISSECTOR_BUG("field %s is not of type FT_INT40, FT_INT48, FT_INT56, or FT_INT64",proto_report_dissector_bug("field %s is not of type FT_INT40, FT_INT48, FT_INT56, or FT_INT64"
, hf_field->abbrev)
14344 hf_field->abbrev)proto_report_dissector_bug("field %s is not of type FT_INT40, FT_INT48, FT_INT56, or FT_INT64"
, hf_field->abbrev)
;
14345 return NULL((void*)0);
14346 }
14347
14348 CREATE_VALUE_STRING(tree, dst, format, ap)__builtin_va_start(ap, format); dst = wmem_strdup_vprintf(((tree
)->tree_data->pinfo->pool), format, ap); __builtin_va_end
(ap);
;
14349
14350 return proto_tree_add_bits_format_value(tree, hfindex, tvb, bit_offset, no_of_bits, &value, encoding, dst);
14351}
14352
14353proto_item *
14354proto_tree_add_boolean_bits_format_value(proto_tree *tree, const int hfindex,
14355 tvbuff_t *tvb, const unsigned bit_offset,
14356 const int no_of_bits, uint64_t value,
14357 const unsigned encoding,
14358 const char *format, ...)
14359{
14360 va_list ap;
14361 char *dst;
14362 header_field_info *hf_field;
14363
14364 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
14365
14366 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hf_field)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14366
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14366, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14366, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hf_field = gpa_hfinfo.hfi[hfindex]
;; if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14366, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items); ((tree)->
tree_data)->count = 0; except_throw(1, (6), (wmem_strdup_printf
(((tree)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hf_field->abbrev, prefs.gui_max_tree_items))); } if (!((
(tree)->tree_data)->visible)) { if (proto_item_is_hidden
((tree))) { if ((hf_field->ref_type != HF_REF_TYPE_DIRECT)
&& (hf_field->ref_type != HF_REF_TYPE_PRINT) &&
(hf_field->type != FT_PROTOCOL || ((tree)->tree_data)->
fake_protocols)) { ((void)0); return proto_tree_add_fake_node
(tree, hf_field); } } }
;
14367
14368 DISSECTOR_ASSERT_FIELD_TYPE(hf_field, FT_BOOLEAN)((void) (((hf_field)->type == FT_BOOLEAN) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_BOOLEAN", "epan/proto.c"
, 14368, ((hf_field))->abbrev))))
;
14369
14370 CREATE_VALUE_STRING(tree, dst, format, ap)__builtin_va_start(ap, format); dst = wmem_strdup_vprintf(((tree
)->tree_data->pinfo->pool), format, ap); __builtin_va_end
(ap);
;
14371
14372 return proto_tree_add_bits_format_value(tree, hfindex, tvb, bit_offset, no_of_bits, &value, encoding, dst);
14373}
14374
14375proto_item *
14376proto_tree_add_ts_23_038_7bits_packed_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
14377 const unsigned bit_offset, const int no_of_chars)
14378{
14379 proto_item *pi;
14380 header_field_info *hfinfo;
14381 int byte_length;
14382 unsigned byte_offset;
14383 char *string;
14384
14385 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
14386
14387 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14387
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14387, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14387, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14387, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
14388
14389 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_STRING)((void) (((hfinfo)->type == FT_STRING) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_STRING", "epan/proto.c"
, 14389, ((hfinfo))->abbrev))))
;
14390
14391 byte_length = (int)(((((int64_t)no_of_chars + 1) * 7) + (bit_offset & 0x07)) >> 3);
14392 byte_offset = bit_offset >> 3;
14393
14394 string = tvb_get_ts_23_038_7bits_string_packed(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool), tvb, bit_offset, no_of_chars);
14395
14396 pi = proto_tree_add_pi(tree, hfinfo, tvb, byte_offset, &byte_length);
14397 DISSECTOR_ASSERT(byte_length >= 0)((void) ((byte_length >= 0) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 14397, "byte_length >= 0"
))))
;
14398 proto_tree_set_string(PNODE_FINFO(pi)((pi)->finfo), string);
14399
14400 return pi;
14401}
14402
14403proto_item *
14404proto_tree_add_ascii_7bits_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
14405 const unsigned bit_offset, const int no_of_chars)
14406{
14407 proto_item *pi;
14408 header_field_info *hfinfo;
14409 int byte_length;
14410 unsigned byte_offset;
14411 char *string;
14412
14413 CHECK_FOR_NULL_TREE(tree)if (!tree) { ((void)0); return ((void*)0); };
14414
14415 TRY_TO_FAKE_THIS_ITEM(tree, hfindex, hfinfo)((tree)->tree_data)->count++; if((hfindex == 0 || (unsigned
)hfindex > gpa_hfinfo.len) && wireshark_abort_on_dissector_bug
) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14415
, __func__, "Unregistered hf! index=%d", hfindex); ((void) ((
hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len
) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14415, "hfindex > 0 && (unsigned)hfindex < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hfindex] !=
((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14415, "gpa_hfinfo.hfi[hfindex] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hfindex];;
if (((tree)->tree_data)->count > prefs.gui_max_tree_items
) { ((void)0); if (wireshark_abort_on_too_many_items) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14415, __func__, "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items); ((tree)->tree_data
)->count = 0; except_throw(1, (6), (wmem_strdup_printf(((tree
)->tree_data->pinfo->pool), "Adding %s would put more than %d items in the tree -- possible infinite loop (max number of items can be increased in advanced preferences)"
, hfinfo->abbrev, prefs.gui_max_tree_items))); } if (!(((tree
)->tree_data)->visible)) { if (proto_item_is_hidden((tree
))) { if ((hfinfo->ref_type != HF_REF_TYPE_DIRECT) &&
(hfinfo->ref_type != HF_REF_TYPE_PRINT) && (hfinfo
->type != FT_PROTOCOL || ((tree)->tree_data)->fake_protocols
)) { ((void)0); return proto_tree_add_fake_node(tree, hfinfo)
; } } }
;
14416
14417 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_STRING)((void) (((hfinfo)->type == FT_STRING) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_STRING", "epan/proto.c"
, 14417, ((hfinfo))->abbrev))))
;
14418
14419 byte_length = (int)(((((int64_t)no_of_chars + 1) * 7) + (bit_offset & 0x07)) >> 3);
14420 byte_offset = bit_offset >> 3;
14421
14422 string = tvb_get_ascii_7bits_string(PNODE_POOL(tree)((tree)->tree_data->pinfo->pool), tvb, bit_offset, no_of_chars);
14423
14424 pi = proto_tree_add_pi(tree, hfinfo, tvb, byte_offset, &byte_length);
14425 DISSECTOR_ASSERT(byte_length >= 0)((void) ((byte_length >= 0) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/proto.c", 14425, "byte_length >= 0"
))))
;
14426 proto_tree_set_string(PNODE_FINFO(pi)((pi)->finfo), string);
14427
14428 return pi;
14429}
14430
14431const value_string proto_checksum_vals[] = {
14432 { PROTO_CHECKSUM_E_BAD, "Bad" },
14433 { PROTO_CHECKSUM_E_GOOD, "Good" },
14434 { PROTO_CHECKSUM_E_UNVERIFIED, "Unverified" },
14435 { PROTO_CHECKSUM_E_NOT_PRESENT, "Not present" },
14436 { PROTO_CHECKSUM_E_ILLEGAL, "Illegal" },
14437
14438 { 0, NULL((void*)0) }
14439};
14440
14441#define PROTO_CHECKSUM_COMPUTED_USED(0x01|0x02|0x10) (PROTO_CHECKSUM_VERIFY0x01|PROTO_CHECKSUM_GENERATED0x02|PROTO_CHECKSUM_NOT_PRESENT0x10)
14442
14443proto_item *
14444proto_tree_add_checksum(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
14445 const int hf_checksum, const int hf_checksum_status, struct expert_field* bad_checksum_expert,
14446 packet_info *pinfo, uint32_t computed_checksum, const unsigned encoding, const unsigned flags)
14447{
14448 header_field_info *hfinfo;
14449 uint32_t checksum;
14450 uint32_t len;
14451 proto_item* ti = NULL((void*)0);
14452 proto_item* ti2;
14453 bool_Bool incorrect_checksum = true1;
14454
14455 PROTO_REGISTRAR_GET_NTH(hf_checksum, hfinfo)if((hf_checksum == 0 || (unsigned)hf_checksum > gpa_hfinfo
.len) && wireshark_abort_on_dissector_bug) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14455, __func__, "Unregistered hf! index=%d"
, hf_checksum); ((void) ((hf_checksum > 0 && (unsigned
)hf_checksum < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 14455
, "hf_checksum > 0 && (unsigned)hf_checksum < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hf_checksum
] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14455, "gpa_hfinfo.hfi[hf_checksum] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hf_checksum
];
;
14456
14457 switch (hfinfo->type) {
14458 case FT_UINT8:
14459 len = 1;
14460 break;
14461 case FT_UINT16:
14462 len = 2;
14463 break;
14464 case FT_UINT24:
14465 len = 3;
14466 break;
14467 case FT_UINT32:
14468 len = 4;
14469 break;
14470 default:
14471 REPORT_DISSECTOR_BUG("field %s is not of type FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32",proto_report_dissector_bug("field %s is not of type FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32"
, hfinfo->abbrev)
14472 hfinfo->abbrev)proto_report_dissector_bug("field %s is not of type FT_UINT8, FT_UINT16, FT_UINT24, or FT_UINT32"
, hfinfo->abbrev)
;
14473 }
14474
14475 if (flags & PROTO_CHECKSUM_NOT_PRESENT0x10) {
14476 ti = proto_tree_add_uint_format_value(tree, hf_checksum, tvb, offset, len, 0, "[missing]");
14477 proto_item_set_generated(ti);
14478 // Backward compatible with use of -1
14479 if (hf_checksum_status > 0) {
14480 ti2 = proto_tree_add_uint(tree, hf_checksum_status, tvb, offset, len, PROTO_CHECKSUM_E_NOT_PRESENT);
14481 proto_item_set_generated(ti2);
14482 }
14483 return ti;
14484 }
14485
14486 if (flags & PROTO_CHECKSUM_GENERATED0x02) {
14487 ti = proto_tree_add_uint(tree, hf_checksum, tvb, offset, len, computed_checksum);
14488 proto_item_set_generated(ti);
14489 } else {
14490 ti = proto_tree_add_item_ret_uint(tree, hf_checksum, tvb, offset, len, encoding, &checksum);
14491 if (flags & PROTO_CHECKSUM_VERIFY0x01) {
14492 if (flags & (PROTO_CHECKSUM_IN_CKSUM0x04|PROTO_CHECKSUM_ZERO0x08)) {
14493 if (computed_checksum == 0) {
14494 proto_item_append_text(ti, " [correct]");
14495 // Backward compatible with use of -1
14496 if (hf_checksum_status > 0) {
14497 ti2 = proto_tree_add_uint(tree, hf_checksum_status, tvb, offset, 0, PROTO_CHECKSUM_E_GOOD);
14498 proto_item_set_generated(ti2);
14499 }
14500 incorrect_checksum = false0;
14501 } else if (flags & PROTO_CHECKSUM_IN_CKSUM0x04) {
14502 computed_checksum = in_cksum_shouldbe(checksum, computed_checksum);
14503 /* XXX - This can't distinguish between "shouldbe"
14504 * 0x0000 and 0xFFFF unless we know whether there
14505 * were any nonzero bits (other than the checksum).
14506 * Protocols should not use this path if they might
14507 * have an all zero packet.
14508 * Some implementations put the wrong zero; maybe
14509 * we should have a special expert info for that?
14510 */
14511 }
14512 } else {
14513 if (checksum == computed_checksum) {
14514 proto_item_append_text(ti, " [correct]");
14515 // Backward compatible with use of -1
14516 if (hf_checksum_status > 0) {
14517 ti2 = proto_tree_add_uint(tree, hf_checksum_status, tvb, offset, 0, PROTO_CHECKSUM_E_GOOD);
14518 proto_item_set_generated(ti2);
14519 }
14520 incorrect_checksum = false0;
14521 }
14522 }
14523
14524 if (incorrect_checksum) {
14525 // Backward compatible with use of -1
14526 if (hf_checksum_status > 0) {
14527 ti2 = proto_tree_add_uint(tree, hf_checksum_status, tvb, offset, 0, PROTO_CHECKSUM_E_BAD);
14528 proto_item_set_generated(ti2);
14529 }
14530 if (flags & PROTO_CHECKSUM_ZERO0x08) {
14531 proto_item_append_text(ti, " [incorrect]");
14532 if (bad_checksum_expert != NULL((void*)0))
14533 expert_add_info_format(pinfo, ti, bad_checksum_expert, "%s", expert_get_summary(bad_checksum_expert));
14534 } else {
14535 proto_item_append_text(ti, " incorrect, should be 0x%0*x", len*2, computed_checksum);
14536 if (bad_checksum_expert != NULL((void*)0))
14537 expert_add_info_format(pinfo, ti, bad_checksum_expert, "%s [should be 0x%0*x]", expert_get_summary(bad_checksum_expert), len * 2, computed_checksum);
14538 }
14539 }
14540 } else {
14541 // Backward compatible with use of -1
14542 if (hf_checksum_status > 0) {
14543 proto_item_append_text(ti, " [unverified]");
14544 ti2 = proto_tree_add_uint(tree, hf_checksum_status, tvb, offset, 0, PROTO_CHECKSUM_E_UNVERIFIED);
14545 proto_item_set_generated(ti2);
14546 }
14547 }
14548 }
14549
14550 return ti;
14551}
14552
14553proto_item *
14554proto_tree_add_checksum_bytes(proto_tree *tree, tvbuff_t *tvb, const unsigned offset,
14555 const int hf_checksum, const int hf_checksum_status, struct expert_field* bad_checksum_expert,
14556 packet_info *pinfo, const uint8_t *computed_checksum, size_t checksum_len, const unsigned flags)
14557{
14558 header_field_info *hfinfo;
14559 uint8_t *checksum = NULL((void*)0);
14560 proto_item* ti = NULL((void*)0);
14561 proto_item* ti2;
14562 bool_Bool incorrect_checksum = true1;
14563
14564 PROTO_REGISTRAR_GET_NTH(hf_checksum, hfinfo)if((hf_checksum == 0 || (unsigned)hf_checksum > gpa_hfinfo
.len) && wireshark_abort_on_dissector_bug) ws_log_fatal_full
("Epan", LOG_LEVEL_ERROR, "epan/proto.c", 14564, __func__, "Unregistered hf! index=%d"
, hf_checksum); ((void) ((hf_checksum > 0 && (unsigned
)hf_checksum < gpa_hfinfo.len) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\" (%s)", "epan/proto.c", 14564
, "hf_checksum > 0 && (unsigned)hf_checksum < gpa_hfinfo.len"
, "Unregistered hf.")))) ; ((void) ((gpa_hfinfo.hfi[hf_checksum
] != ((void*)0)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/proto.c", 14564, "gpa_hfinfo.hfi[hf_checksum] != ((void*)0)"
, "Unregistered hf.")))) ; hfinfo = gpa_hfinfo.hfi[hf_checksum
];
;
14565
14566 DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_BYTES)((void) (((hfinfo)->type == FT_BYTES) ? (void)0 : (proto_report_dissector_bug
("%s:%u: field %s is not of type ""FT_BYTES", "epan/proto.c",
14566, ((hfinfo))->abbrev))))
;
14567
14568 /* Make sure a NULL computed_checksum isn't dereferenced.
14569 * If checksum_len is 0 it probably won't crash, but in the VERIFY
14570 * case memcmp(NULL, checksum, 0) is UB until C2y, and in the other
14571 * cases the behavior is unexpected and still a programmer error;
14572 * proto_tree_add_bytes retrieves it from the tvb, thus neither
14573 * _NOT_PRESENT nor _GENERATED is correct.
14574 */
14575 DISSECTOR_ASSERT(computed_checksum || ((flags & PROTO_CHECKSUM_COMPUTED_USED) == PROTO_CHECKSUM_NO_FLAGS))((void) ((computed_checksum || ((flags & (0x01|0x02|0x10)
) == 0x00)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/proto.c", 14575, "computed_checksum || ((flags & (0x01|0x02|0x10)) == 0x00)"
))))
;
14576
14577 if (flags & PROTO_CHECKSUM_NOT_PRESENT0x10) {
14578 ti = proto_tree_add_bytes_format_value(tree, hf_checksum, tvb, offset, (int)checksum_len, 0, "[missing]");
14579 proto_item_set_generated(ti);
14580 // Backward compatible with use of -1
14581 if (hf_checksum_status > 0) {
14582 ti2 = proto_tree_add_uint(tree, hf_checksum_status, tvb, offset, (int)checksum_len, PROTO_CHECKSUM_E_NOT_PRESENT);
14583 proto_item_set_generated(ti2);
14584 }
14585 return ti;
14586 }
14587
14588 if (flags & PROTO_CHECKSUM_GENERATED0x02) {
14589 ti = proto_tree_add_bytes(tree, hf_checksum, tvb, offset, (int)checksum_len, computed_checksum);
14590 proto_item_set_generated(ti);
14591 return ti;
14592 }
14593
14594 checksum = tvb_memdup(pinfo->pool, tvb, offset, checksum_len);
14595 ti = proto_tree_add_bytes(tree, hf_checksum, tvb, offset, (int)checksum_len, checksum);
14596 if (flags & PROTO_CHECKSUM_VERIFY0x01) {
14597 if (flags & (PROTO_CHECKSUM_IN_CKSUM0x04|PROTO_CHECKSUM_ZERO0x08)) {
14598 bool_Bool non_zero_flag = false0;
14599 for (size_t index = 0; index < checksum_len; index++) {
14600 if (computed_checksum[index]) {
14601 non_zero_flag = true1;
14602 break;
14603 }
14604 }
14605 if (!non_zero_flag) {
14606 proto_item_append_text(ti, " [correct]");
14607 // Backward compatible with use of -1
14608 if (hf_checksum_status > 0) {
14609 ti2 = proto_tree_add_uint(tree, hf_checksum_status, tvb, offset, 0, PROTO_CHECKSUM_E_GOOD);
14610 proto_item_set_generated(ti2);
14611 }
14612 incorrect_checksum = false0;
14613 }
14614 } else {
14615 if (memcmp(computed_checksum, checksum, checksum_len) == 0) {
14616 proto_item_append_text(ti, " [correct]");
14617 // Backward compatible with use of -1
14618 if (hf_checksum_status > 0) {
14619 ti2 = proto_tree_add_uint(tree, hf_checksum_status, tvb, offset, 0, PROTO_CHECKSUM_E_GOOD);
14620 proto_item_set_generated(ti2);
14621 }
14622 incorrect_checksum = false0;
14623 }
14624 }
14625
14626 if (incorrect_checksum) {
14627 // Backward compatible with use of -1
14628 if (hf_checksum_status > 0) {
14629 ti2 = proto_tree_add_uint(tree, hf_checksum_status, tvb, offset, 0, PROTO_CHECKSUM_E_BAD);
14630 proto_item_set_generated(ti2);
14631 }
14632 if (flags & PROTO_CHECKSUM_ZERO0x08) {
14633 proto_item_append_text(ti, " [incorrect]");
14634 if (bad_checksum_expert != NULL((void*)0))
14635 expert_add_info_format(pinfo, ti, bad_checksum_expert, "%s", expert_get_summary(bad_checksum_expert));
14636 } else {
14637 char *computed_checksum_str = bytes_to_str_maxlen(pinfo->pool, computed_checksum, checksum_len, 0);
14638 proto_item_append_text(ti, " incorrect, should be 0x%s", computed_checksum_str);
14639 if (bad_checksum_expert != NULL((void*)0))
14640 expert_add_info_format(pinfo, ti, bad_checksum_expert, "%s [should be 0x%s]", expert_get_summary(bad_checksum_expert), computed_checksum_str);
14641 }
14642 }
14643 } else {
14644 // Backward compatible with use of -1
14645 if (hf_checksum_status > 0) {
14646 proto_item_append_text(ti, " [unverified]");
14647 ti2 = proto_tree_add_uint(tree, hf_checksum_status, tvb, offset, 0, PROTO_CHECKSUM_E_UNVERIFIED);
14648 proto_item_set_generated(ti2);
14649 }
14650 }
14651
14652 return ti;
14653}
14654
14655unsigned char
14656proto_check_field_name(const char *field_name)
14657{
14658 return module_check_valid_name(field_name, false0);
14659}
14660
14661unsigned char
14662proto_check_field_name_lower(const char *field_name)
14663{
14664 return module_check_valid_name(field_name, true1);
14665}
14666
14667bool_Bool
14668tree_expanded(int tree_type)
14669{
14670 if (tree_type <= 0) {
14671 return false0;
14672 }
14673 ws_assert(tree_type >= 0 && tree_type < num_tree_types)do { if ((1) && !(tree_type >= 0 && tree_type
< num_tree_types)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 14673, __func__, "assertion failed: %s", "tree_type >= 0 && tree_type < num_tree_types"
); } while (0)
;
14674 return tree_is_expanded[tree_type >> 5] & (1U << (tree_type & 31));
14675}
14676
14677void
14678tree_expanded_set(int tree_type, bool_Bool value)
14679{
14680 ws_assert(tree_type >= 0 && tree_type < num_tree_types)do { if ((1) && !(tree_type >= 0 && tree_type
< num_tree_types)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR
, "epan/proto.c", 14680, __func__, "assertion failed: %s", "tree_type >= 0 && tree_type < num_tree_types"
); } while (0)
;
14681
14682 if (value)
14683 tree_is_expanded[tree_type >> 5] |= (1U << (tree_type & 31));
14684 else
14685 tree_is_expanded[tree_type >> 5] &= ~(1U << (tree_type & 31));
14686}
14687
14688/*
14689 * Editor modelines - https://www.wireshark.org/tools/modelines.html
14690 *
14691 * Local variables:
14692 * c-basic-offset: 8
14693 * tab-width: 8
14694 * indent-tabs-mode: t
14695 * End:
14696 *
14697 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
14698 * :indentSize=8:tabSize=8:noTabs=false:
14699 */