From a86c5f7cae7ec9a3398300555a0b644689d946a1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 19 Sep 2024 06:14:53 +0200 Subject: Merging upstream version 4.4.0. Signed-off-by: Daniel Baumann --- epan/dissectors/packet-blip.c | 182 ++++++++++++++++++++++-------------------- 1 file changed, 94 insertions(+), 88 deletions(-) (limited to 'epan/dissectors/packet-blip.c') diff --git a/epan/dissectors/packet-blip.c b/epan/dissectors/packet-blip.c index 6159abb4..8154a340 100644 --- a/epan/dissectors/packet-blip.c +++ b/epan/dissectors/packet-blip.c @@ -23,10 +23,17 @@ #include #include "proto_data.h" -#ifdef HAVE_ZLIB +#if defined(HAVE_ZLIB) && !defined(HAVE_ZLIBNG) +#define ZLIB_PREFIX(x) x #include -#endif +typedef z_stream zlib_stream; +#endif /* HAVE_ZLIB */ +#ifdef HAVE_ZLIBNG +#define ZLIB_PREFIX(x) zng_ ## x +#include +typedef zng_stream zlib_stream; +#endif /* HAVE_ZLIBNG */ void proto_reg_handoff_blip(void); void proto_register_blip(void); @@ -44,13 +51,13 @@ typedef struct { // ... and going to port 4984 for message type = MSG occurred in wireshark packet #12" wmem_map_t *blip_requests; -#ifdef HAVE_ZLIB +#if defined(HAVE_ZLIB) || defined(HAVE_ZLIBNG) // The streams used to decode a particular connection. These are per direction and per connection. wmem_map_t *decompress_streams; #endif } blip_conversation_entry_t; -#ifdef HAVE_ZLIB +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) typedef enum { no_error = 0, @@ -69,18 +76,18 @@ typedef struct // File level variables static dissector_handle_t blip_handle; -static int proto_blip = -1; -static int hf_blip_message_number = -1; -static int hf_blip_frame_flags = -1; -static int hf_blip_properties_length = -1; -static int hf_blip_properties = -1; -static int hf_blip_message_body = -1; -static int hf_blip_ack_size = -1; -static int hf_blip_checksum = -1; +static int proto_blip; +static int hf_blip_message_number; +static int hf_blip_frame_flags; +static int hf_blip_properties_length; +static int hf_blip_properties; +static int hf_blip_message_body; +static int hf_blip_ack_size; +static int hf_blip_checksum; -static gint ett_blip = -1; +static int ett_blip; -static expert_field ei_blip_decompress_buffer_error = EI_INIT; +static expert_field ei_blip_decompress_buffer_error; // Compressed = 0x08 // Urgent = 0x10 @@ -120,8 +127,8 @@ static const val64_string msg_types[] = { }; // Preferences -#ifdef HAVE_ZLIB -static guint max_uncompressed_size = 64; // Max uncompressed body size in Kb +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) +static unsigned max_uncompressed_size = 64; // Max uncompressed body size in Kb #endif // MSG = 0x00 @@ -129,59 +136,59 @@ static guint max_uncompressed_size = 64; // Max uncompressed body size in Kb // ERR = 0x02 // ACKMSG = 0x04 // ACKRPY = 0x05 -static const gchar* -get_message_type(guint64 value_frame_flags) +static const char* +get_message_type(uint64_t value_frame_flags) { // Mask out the least significant bits: 0000 0111 - guint64 type_mask_val = (0x07ll & value_frame_flags); + uint64_t type_mask_val = (0x07ll & value_frame_flags); return val64_to_str_const(type_mask_val, msg_types, "???"); } -static gboolean -is_ack_message(guint64 value_frame_flags) { +static bool +is_ack_message(uint64_t value_frame_flags) { // Note, even though this is a 64-bit int, only the least significant byte has meaningful information, // since frame flags all fit into one byte at the time this code was written. // Mask out the least significant bits: 0000 0111 - guint64 type_mask_val = (0x07ll & value_frame_flags); + uint64_t type_mask_val = (0x07ll & value_frame_flags); // ACKMSG if (type_mask_val == 0x04ll) { - return TRUE; + return true; } // ACKRPY if (type_mask_val == 0x05ll) { - return TRUE; + return true; } - return FALSE; + return false; } -static gboolean -is_compressed(guint64 value_frame_flags) +static bool +is_compressed(uint64_t value_frame_flags) { // Note, even though this is a 64-bit int, only the least significant byte has meaningful information, // since frame flags all fit into one byte at the time this code was written. if ((0x08ll & value_frame_flags) == 0x08ll) { - return TRUE; + return true; } - return FALSE; + return false; } -static gchar* +static char* message_hash_key_convo(packet_info *pinfo, - guint64 value_frame_flags, - guint64 value_message_num) + uint64_t value_frame_flags, + uint64_t value_message_num) { // Derive the hash key to use // msgtype:srcport:destport:messagenum - const gchar *msg_type = get_message_type(value_frame_flags); - gchar *hash_key = wmem_strdup_printf(pinfo->pool, "%s:%u:%u:%" PRIu64, + const char *msg_type = get_message_type(value_frame_flags); + char *hash_key = wmem_strdup_printf(pinfo->pool, "%s:%u:%u:%" PRIu64, msg_type, pinfo->srcport, pinfo->destport, value_message_num); return hash_key; @@ -189,24 +196,24 @@ message_hash_key_convo(packet_info *pinfo, // Finds out whether this is the first blip frame in the blip message (which can consist of a series of frames). // If it is, updates the conversation_entry_ptr->blip_requests hash to record the pinfo->num (wireshark packet number) -static gboolean +static bool is_first_frame_in_msg(blip_conversation_entry_t *conversation_entry_ptr, packet_info *pinfo, - guint64 value_frame_flags, guint64 value_message_num) { + uint64_t value_frame_flags, uint64_t value_message_num) { - gboolean first_frame_in_msg = TRUE; + bool first_frame_in_msg = true; // Temporary pool for the lookup hash_key. Will get duplicated on the file_scope() pool if needed to be // stored in the hashtable. - gchar *hash_key = message_hash_key_convo(pinfo, value_frame_flags, value_message_num); - guint* first_frame_number_for_msg = (guint*)wmem_map_lookup(conversation_entry_ptr->blip_requests, (void *) hash_key); + char *hash_key = message_hash_key_convo(pinfo, value_frame_flags, value_message_num); + unsigned* first_frame_number_for_msg = (unsigned*)wmem_map_lookup(conversation_entry_ptr->blip_requests, (void *) hash_key); if (first_frame_number_for_msg != NULL) { if (GPOINTER_TO_UINT(first_frame_number_for_msg) != pinfo->num) { - first_frame_in_msg = FALSE; + first_frame_in_msg = false; } } else { // If storing the key in the hashmap, re-allocate it with the file_scope() allocator - gchar *hash_key_copy = wmem_strdup(wmem_file_scope(), hash_key); + char *hash_key_copy = wmem_strdup(wmem_file_scope(), hash_key); wmem_map_insert(conversation_entry_ptr->blip_requests, (void *) hash_key_copy, GUINT_TO_POINTER(pinfo->num)); } @@ -215,12 +222,12 @@ is_first_frame_in_msg(blip_conversation_entry_t *conversation_entry_ptr, packet_ } static int -handle_ack_message(tvbuff_t *tvb, _U_ packet_info *pinfo, proto_tree *blip_tree, gint offset, _U_ guint64 value_frame_flags) +handle_ack_message(tvbuff_t *tvb, _U_ packet_info *pinfo, proto_tree *blip_tree, int offset, _U_ uint64_t value_frame_flags) { // This gets the number of ack bytes received as a var int in order to find out how much to bump // the offset for the next proto_tree item - guint64 value_ack_size; - guint varint_ack_size_length = tvb_get_varint( + uint64_t value_ack_size; + unsigned varint_ack_size_length = tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, @@ -247,7 +254,7 @@ get_blip_conversation(packet_info* pinfo) // create a new hash map and save a reference in blip_conversation_entry_t conversation_entry_ptr->blip_requests = wmem_map_new(wmem_file_scope(), g_str_hash, g_str_equal); -#ifdef HAVE_ZLIB +#if defined(HAVE_ZLIB) || defined(HAVE_ZLIBNG) conversation_entry_ptr->decompress_streams = wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal); #endif conversation_add_proto_data(conversation, proto_blip, conversation_entry_ptr); @@ -256,29 +263,28 @@ get_blip_conversation(packet_info* pinfo) return conversation_entry_ptr; } -#ifdef HAVE_ZLIB - +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) static bool z_stream_destroy_cb(wmem_allocator_t *allocator _U_, wmem_cb_event_t event _U_, void *user_data) { - z_stream *decompress_stream = (z_stream *)user_data; - inflateEnd(decompress_stream); - return FALSE; + zlib_stream*decompress_stream = (zlib_stream*)user_data; + ZLIB_PREFIX(inflateEnd)(decompress_stream); + return false; } -static z_stream* +static zlib_stream* get_decompress_stream(packet_info* pinfo) { const blip_conversation_entry_t* blip_convo = get_blip_conversation(pinfo); // Store compression state per srcport/destport. - guint32 hash_key = (pinfo->srcport << 16) | pinfo->destport; - z_stream* decompress_stream = (z_stream *)wmem_map_lookup(blip_convo->decompress_streams, GUINT_TO_POINTER(hash_key)); + uint32_t hash_key = (pinfo->srcport << 16) | pinfo->destport; + zlib_stream* decompress_stream = (zlib_stream*)wmem_map_lookup(blip_convo->decompress_streams, GUINT_TO_POINTER(hash_key)); if(decompress_stream) { return decompress_stream; } - decompress_stream = wmem_new0(wmem_file_scope(), z_stream); + decompress_stream = wmem_new0(wmem_file_scope(), zlib_stream); wmem_map_insert(blip_convo->decompress_streams, GUINT_TO_POINTER(hash_key), decompress_stream); wmem_register_callback(wmem_file_scope(), z_stream_destroy_cb, decompress_stream); @@ -286,7 +292,7 @@ get_decompress_stream(packet_info* pinfo) } static tvbuff_t* -decompress(packet_info* pinfo, proto_tree* tree, tvbuff_t* tvb, gint offset, gint length) +decompress(packet_info* pinfo, proto_tree* tree, tvbuff_t* tvb, int offset, int length) { if(PINFO_FD_VISITED(pinfo)) { const decompress_result_t* saved_data = (decompress_result_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_blip, 0); @@ -305,22 +311,22 @@ decompress(packet_info* pinfo, proto_tree* tree, tvbuff_t* tvb, gint offset, gin return NULL; } else { - tvbuff_t* decompressedChild = tvb_new_child_real_data(tvb, (guint8 *)saved_data->buf, - (gint)saved_data->size, (gint)saved_data->size); + tvbuff_t* decompressedChild = tvb_new_child_real_data(tvb, (uint8_t *)saved_data->buf, + (int)saved_data->size, (int)saved_data->size); add_new_data_source(pinfo, decompressedChild, "Decompressed Payload"); return decompressedChild; } } - static gboolean size_overflow = FALSE; - const guint8* buf = tvb_get_ptr(tvb, offset, length); - z_stream* decompress_stream = get_decompress_stream(pinfo); + static bool size_overflow = false; + const uint8_t* buf = tvb_get_ptr(tvb, offset, length); + zlib_stream* decompress_stream = get_decompress_stream(pinfo); static Byte trailer[4] = { 0x00, 0x00, 0xff, 0xff }; if(!decompress_stream->next_out) { decompress_stream->zalloc = 0; decompress_stream->zfree = 0; decompress_stream->opaque = 0; - int err = inflateInit2(decompress_stream, -MAX_WBITS); + int err = ZLIB_PREFIX(inflateInit2)(decompress_stream, -MAX_WBITS); if(err != Z_OK) { decompress_stream->next_out = 0; REPORT_DISSECTOR_BUG("Unable to create INFLATE context to decompress messages"); @@ -337,7 +343,7 @@ decompress(packet_info* pinfo, proto_tree* tree, tvbuff_t* tvb, gint offset, gin decompress_stream->next_out = decompress_buffer; decompress_stream->avail_out = buffer_size; uLong start = decompress_stream->total_out; - int err = inflate(decompress_stream, Z_NO_FLUSH); + int err = ZLIB_PREFIX(inflate)(decompress_stream, Z_NO_FLUSH); if(err != Z_OK) { proto_item* field = proto_tree_add_string(tree, hf_blip_message_body, tvb, offset, tvb_reported_length_remaining(tvb, offset), ""); decompress_result_t* data_to_save = wmem_new0(wmem_file_scope(), decompress_result_t); @@ -356,13 +362,13 @@ decompress(packet_info* pinfo, proto_tree* tree, tvbuff_t* tvb, gint offset, gin decompress_stream->next_in = trailer; decompress_stream->avail_in = 4; - err = inflate(decompress_stream, Z_SYNC_FLUSH); + err = ZLIB_PREFIX(inflate)(decompress_stream, Z_SYNC_FLUSH); if(err != Z_OK) { proto_item* field = proto_tree_add_string(tree, hf_blip_message_body, tvb, offset, tvb_reported_length_remaining(tvb, offset), ""); decompress_result_t* data_to_save = wmem_new0(wmem_file_scope(), decompress_result_t); if(err == Z_BUF_ERROR) { data_to_save->domain = overflow_error; - size_overflow = TRUE; + size_overflow = true; expert_add_info_format(pinfo, field, &ei_blip_decompress_buffer_error, "Unable to decompress message, buffer too small (%u Kb). Please adjust in settings.", max_uncompressed_size); } else { data_to_save->domain = zlib_error; @@ -379,7 +385,7 @@ decompress(packet_info* pinfo, proto_tree* tree, tvbuff_t* tvb, gint offset, gin uLong bodyLength = decompress_stream->total_out - start; Bytef* shortened_buffer = (Bytef *)wmem_memdup(wmem_file_scope(), decompress_buffer, bodyLength); - tvbuff_t* decompressedChild = tvb_new_child_real_data(tvb, shortened_buffer, (guint)bodyLength, (gint)bodyLength); + tvbuff_t* decompressedChild = tvb_new_child_real_data(tvb, shortened_buffer, (unsigned)bodyLength, (int)bodyLength); add_new_data_source(pinfo, decompressedChild, "Decompressed Payload"); decompress_result_t* data_to_save = wmem_new0(wmem_file_scope(), decompress_result_t); data_to_save->size = (size_t)bodyLength; @@ -395,9 +401,9 @@ dissect_blip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, _U_ void *data { proto_tree *blip_tree; - gint offset = 0; + int offset = 0; - /* Set the protcol column to say BLIP */ + /* Set the protocol column to say BLIP */ col_set_str(pinfo->cinfo, COL_PROTOCOL, "BLIP"); /* Clear out stuff in the info column */ col_clear(pinfo->cinfo,COL_INFO); @@ -415,8 +421,8 @@ dissect_blip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, _U_ void *data // This gets the message number as a var int in order to find out how much to bump // the offset for the next proto_tree item - guint64 value_message_num; - guint varint_message_num_length = tvb_get_varint( + uint64_t value_message_num; + unsigned varint_message_num_length = tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, @@ -431,26 +437,26 @@ dissect_blip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, _U_ void *data // This gets the message number as a var int in order to find out how much to bump // the offset for the next proto_tree item - guint64 value_frame_flags; - guint varint_frame_flags_length = tvb_get_varint( + uint64_t value_frame_flags; + unsigned varint_frame_flags_length = tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &value_frame_flags, ENC_VARINT_PROTOBUF); - guint64 masked = value_frame_flags & ~0x07; - proto_tree_add_uint(blip_tree, hf_blip_frame_flags, tvb, offset, varint_frame_flags_length, (guint8)masked); + uint64_t masked = value_frame_flags & ~0x07; + proto_tree_add_uint(blip_tree, hf_blip_frame_flags, tvb, offset, varint_frame_flags_length, (uint8_t)masked); offset += varint_frame_flags_length; - const gchar* msg_type = get_message_type(value_frame_flags); - gchar* msg_num = wmem_strdup_printf(pinfo->pool, "#%" PRIu64, value_message_num); - gchar* col_info = wmem_strconcat(pinfo->pool, msg_type, msg_num, NULL); + const char* msg_type = get_message_type(value_frame_flags); + char* msg_num = wmem_strdup_printf(pinfo->pool, "#%" PRIu64, value_message_num); + char* col_info = wmem_strconcat(pinfo->pool, msg_type, msg_num, NULL); col_add_str(pinfo->cinfo, COL_INFO, col_info); // If it's an ACK message, handle that separately, since there are no properties etc. - if (is_ack_message(value_frame_flags) == TRUE) { + if (is_ack_message(value_frame_flags) == true) { return handle_ack_message(tvb, pinfo, blip_tree, offset, value_frame_flags); } @@ -460,7 +466,7 @@ dissect_blip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, _U_ void *data blip_conversation_entry_t *conversation_entry_ptr = get_blip_conversation(pinfo); // Is this the first frame in a blip message with multiple frames? - gboolean first_frame_in_msg = is_first_frame_in_msg( + bool first_frame_in_msg = is_first_frame_in_msg( conversation_entry_ptr, pinfo, value_frame_flags, @@ -468,10 +474,10 @@ dissect_blip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, _U_ void *data ); tvbuff_t* tvb_to_use = tvb; - gboolean compressed = is_compressed(value_frame_flags); + bool compressed = is_compressed(value_frame_flags); if(compressed) { -#ifdef HAVE_ZLIB +#if defined (HAVE_ZLIB) || defined (HAVE_ZLIBNG) tvb_to_use = decompress(pinfo, blip_tree, tvb, offset, tvb_reported_length_remaining(tvb, offset) - BLIP_BODY_CHECKSUM_SIZE); if(!tvb_to_use) { return tvb_reported_length(tvb); @@ -484,15 +490,15 @@ dissect_blip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, _U_ void *data } // Is this the first frame in a message? - if (first_frame_in_msg == TRUE) { + if (first_frame_in_msg == true) { // ------------------------ BLIP Frame Header: Properties Length VarInt -------------------------------------------------- // WARNING: this only works because this code assumes that ALL MESSAGES FIT INTO ONE FRAME, which is absolutely not true. // In other words, as soon as there is a message that spans two frames, this code will break. - guint64 value_properties_length; - guint value_properties_length_varint_length = tvb_get_varint( + uint64_t value_properties_length; + unsigned value_properties_length_varint_length = tvb_get_varint( tvb_to_use, offset, FT_VARINT_MAX_LEN, @@ -510,7 +516,7 @@ dissect_blip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, _U_ void *data // At this point, the length of the properties is known and is stored in value_properties_length. // This reads the entire properties out of the tvb and into a buffer (buf). - guint8* buf = tvb_get_string_enc(pinfo->pool, tvb_to_use, offset, (gint) value_properties_length, ENC_UTF_8); + uint8_t* buf = tvb_get_string_enc(pinfo->pool, tvb_to_use, offset, (int) value_properties_length, ENC_UTF_8); // "Profile\0subChanges\0continuous\0true\0foo\0bar" -> "Profile:subChanges:continuous:true:foo:bar" // Iterate over buf and change all the \0 null characters to ':', since otherwise trying to set a header @@ -529,13 +535,13 @@ dissect_blip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, _U_ void *data } // Bump the offset by the length of the properties - offset += (gint)value_properties_length; + offset += (int)value_properties_length; } // ------------------------ BLIP Frame: Message Body -------------------------------------------------- - // WS_DLL_PUBLIC gint tvb_reported_length_remaining(const tvbuff_t *tvb, const gint offset); - gint reported_length_remaining = tvb_reported_length_remaining(tvb_to_use, offset); + // WS_DLL_PUBLIC int tvb_reported_length_remaining(const tvbuff_t *tvb, const int offset); + int reported_length_remaining = tvb_reported_length_remaining(tvb_to_use, offset); // Don't read in the trailing checksum at the end if (!compressed && reported_length_remaining >= BLIP_BODY_CHECKSUM_SIZE) { @@ -588,7 +594,7 @@ proto_register_blip(void) }; /* Setup protocol subtree array */ - static gint *ett[] = { + static int *ett[] = { &ett_blip }; -- cgit v1.2.3