aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2017-10-11 21:55:55 -0400
committerMichael Mann <mmann78@netscape.net>2017-11-19 05:14:27 +0000
commit752d0ef753983b45142e76a71dcdf3ab3c082439 (patch)
treeb79c569f8b488dfd90147624f0ede3a35cbdb41f /epan
parentce8f8719004045497f95d1729f33053da43f69f8 (diff)
dissect_uleb128 -> tvb_get_varint/proto_tree_add_item_ret_length
Also update ENC_VARINT_PROTOBUF documentation while we're at it Change-Id: I72e1f9175adc0c6a8bb03ceddba04ffd4844a12e Reviewed-on: https://code.wireshark.org/review/24485 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan')
-rw-r--r--epan/dissectors/file-elf.c21
-rw-r--r--epan/dissectors/packet-mqtt.c16
-rw-r--r--epan/dissectors/packet-netsync.c37
-rw-r--r--epan/dwarf.c20
-rw-r--r--epan/dwarf.h1
-rw-r--r--epan/proto.h3
6 files changed, 30 insertions, 68 deletions
diff --git a/epan/dissectors/file-elf.c b/epan/dissectors/file-elf.c
index c85f1e360f..3452524b86 100644
--- a/epan/dissectors/file-elf.c
+++ b/epan/dissectors/file-elf.c
@@ -887,7 +887,7 @@ dissect_eh_frame_hdr(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *segment_
if (efp_length == LENGTH_ULEB128) {
guint64 value;
- efp_length = dissect_uleb128(tvb, offset, &value);
+ efp_length = tvb_get_varint(tvb, offset, FT_VARINT_MAX_LEN, &value);
} else if (efp_length == LENGTH_LEB128) {
gint64 value;
@@ -899,7 +899,7 @@ dissect_eh_frame_hdr(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *segment_
if (fde_count_length == LENGTH_ULEB128) {
- fde_count_length = dissect_uleb128(tvb, offset, &fde_count);
+ fde_count_length = tvb_get_varint(tvb, offset, FT_VARINT_MAX_LEN, &fde_count);
} else if (fde_count_length == LENGTH_LEB128) {
gint64 value;
@@ -932,7 +932,7 @@ dissect_eh_frame_hdr(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *segment_
if (table_entry_length == LENGTH_ULEB128) {
guint64 value;
- table_entry_length = dissect_uleb128(tvb, offset, &value);
+ table_entry_length = tvb_get_varint(tvb, offset, FT_VARINT_MAX_LEN, &value);
} else if (table_entry_length == LENGTH_LEB128) {
gint64 value;
@@ -1064,9 +1064,7 @@ dissect_eh_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *segment_tree,
tvb, offset, size, machine_encoding);
offset += size;
- size = dissect_uleb128(tvb, offset, &unsigned_value);
- proto_tree_add_uint64(entry_tree, hf_elf_eh_frame_code_alignment_factor,
- tvb, offset, size, unsigned_value);
+ proto_tree_add_item_ret_length(entry_tree, hf_elf_eh_frame_code_alignment_factor, tvb, offset, -1, ENC_LITTLE_ENDIAN|ENC_VARINT_PROTOBUF, &size);
offset += size;
size = dissect_leb128(tvb, offset, &signed_value);
@@ -1075,9 +1073,7 @@ dissect_eh_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *segment_tree,
offset += size;
/* according to DWARF v4 this is uLEB128 */
- size = dissect_uleb128(tvb, offset, &unsigned_value);
- proto_tree_add_uint64(entry_tree, hf_elf_eh_frame_return_address_register,
- tvb, offset, size, unsigned_value);
+ proto_tree_add_item_ret_length(entry_tree, hf_elf_eh_frame_return_address_register, tvb, offset, -1, ENC_LITTLE_ENDIAN|ENC_VARINT_PROTOBUF, &size);
offset += size;
} else {
proto_tree_add_item(entry_tree, hf_elf_eh_frame_fde_pc_begin, tvb,
@@ -1092,11 +1088,8 @@ dissect_eh_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *segment_tree,
/* "A 'z' may be present as the first character of the string. If
* present, the Augmentation Data field shall be present." (LSB 4.1) */
if (augmentation_string[0] == 'z') {
- size = dissect_uleb128(tvb, offset, &unsigned_value);
- proto_tree_add_uint64(entry_tree, is_cie ?
- hf_elf_eh_frame_augmentation_length :
- hf_elf_eh_frame_fde_augmentation_length,
- tvb, offset, size, unsigned_value);
+ proto_tree_add_item_ret_varint(entry_tree, is_cie ? hf_elf_eh_frame_augmentation_length : hf_elf_eh_frame_fde_augmentation_length,
+ tvb, offset, -1, ENC_LITTLE_ENDIAN|ENC_VARINT_PROTOBUF, &unsigned_value, &size);
offset += size;
proto_tree_add_item(entry_tree, is_cie ?
diff --git a/epan/dissectors/packet-mqtt.c b/epan/dissectors/packet-mqtt.c
index fee3bf962e..c7a9a98683 100644
--- a/epan/dissectors/packet-mqtt.c
+++ b/epan/dissectors/packet-mqtt.c
@@ -368,18 +368,16 @@ static gint ett_mqtt_subscription_flags = -1;
/* Reassemble SMPP TCP segments */
static gboolean reassemble_mqtt_over_tcp = TRUE;
-#define GET_MQTT_PDU_LEN(msg_len, len_offset) (msg_len + len_offset + MQTT_HDR_SIZE_BEFORE_LEN)
-
static guint get_mqtt_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb,
int offset, void *data _U_)
{
guint64 msg_len;
guint len_offset;
- len_offset = dissect_uleb128(tvb, (offset + MQTT_HDR_SIZE_BEFORE_LEN), &msg_len);
+ len_offset = tvb_get_varint(tvb, (offset + MQTT_HDR_SIZE_BEFORE_LEN), FT_VARINT_MAX_LEN, &msg_len);
/* Explicitly downcast the value, because the length can never be more than 4 bytes */
- return (guint)(GET_MQTT_PDU_LEN(msg_len, len_offset));
+ return (guint)(msg_len + len_offset + MQTT_HDR_SIZE_BEFORE_LEN);
}
static void *mqtt_message_decode_copy_cb(void *dest, const void *orig, size_t len _U_)
@@ -509,7 +507,7 @@ static guint dissect_mqtt_properties(tvbuff_t *tvb, proto_tree *mqtt_tree, guint
proto_item *ti;
guint64 vbi;
- const guint mqtt_prop_offset = dissect_uleb128(tvb, offset, &vbi);
+ const guint mqtt_prop_offset = tvb_get_varint(tvb, offset, FT_VARINT_MAX_LEN, &vbi);
/* Property Length field can be stored in uint32 */
const guint mqtt_prop_len = (gint)vbi;
@@ -563,9 +561,9 @@ static guint dissect_mqtt_properties(tvbuff_t *tvb, proto_tree *mqtt_tree, guint
case PROP_SUBSCRIPTION_IDENTIFIER:
{
- guint8 vbi_offset = dissect_uleb128(tvb, offset, &vbi);
- proto_tree_add_uint(mqtt_prop_tree, hf_mqtt_prop_num, tvb, offset, vbi_offset, (guint32)vbi);
- offset += vbi_offset;
+ gint vbi_len;
+ proto_tree_add_item_ret_length(mqtt_prop_tree, hf_mqtt_prop_num, tvb, offset, -1, ENC_LITTLE_ENDIAN|ENC_VARINT_PROTOBUF, &vbi_len);
+ offset += vbi_len;
break;
}
@@ -681,7 +679,7 @@ static int dissect_mqtt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi
conversation_add_proto_data(conv, proto_mqtt, mqtt);
}
- mqtt_len_offset = dissect_uleb128(tvb, (offset + MQTT_HDR_SIZE_BEFORE_LEN), &msg_len);
+ mqtt_len_offset = tvb_get_varint(tvb, (offset + MQTT_HDR_SIZE_BEFORE_LEN), FT_VARINT_MAX_LEN, &msg_len);
/* Explicit downcast, typically maximum length of message could be 4 bytes */
mqtt_msg_len = (gint) msg_len;
diff --git a/epan/dissectors/packet-netsync.c b/epan/dissectors/packet-netsync.c
index 33dc93256f..39374424d8 100644
--- a/epan/dissectors/packet-netsync.c
+++ b/epan/dissectors/packet-netsync.c
@@ -158,7 +158,7 @@ static gint dissect_netsync_cmd_error( tvbuff_t *tvb, gint offset, proto_tree *
{
guint64 len = 0;
- offset += dissect_uleb128( tvb, offset, &len );
+ offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len );
proto_tree_add_item(tree, hf_netsync_cmd_error_msg, tvb,
offset, (gint)len, ENC_ASCII|ENC_NA );
@@ -177,15 +177,13 @@ static gint dissect_netsync_cmd_hello(tvbuff_t *tvb, gint offset, proto_tree *t
{
guint64 len = 0;
- offset += dissect_uleb128( tvb, offset, &len );
-
+ offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len );
proto_tree_add_item(tree, hf_netsync_cmd_hello_keyname, tvb,
offset, (gint)len, ENC_ASCII|ENC_NA );
offset += (gint)len;
- offset += dissect_uleb128( tvb, offset, &len );
-
+ offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len );
proto_tree_add_item(tree, hf_netsync_cmd_hello_key, tvb,
offset, (gint)len, ENC_NA );
offset += (gint)len;
@@ -206,8 +204,7 @@ static gint dissect_netsync_cmd_anonymous(tvbuff_t *tvb, gint offset, proto_tre
offset, 1, ENC_BIG_ENDIAN );
offset += 1;
- offset += dissect_uleb128( tvb, offset, &len );
-
+ offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len );
proto_tree_add_item(tree, hf_netsync_cmd_anonymous_collection, tvb,
offset, (gint)len, ENC_ASCII|ENC_NA );
offset += (gint)len;
@@ -229,8 +226,7 @@ static gint dissect_netsync_cmd_auth(tvbuff_t *tvb, gint offset, proto_tree *tr
offset += 1;
- offset += dissect_uleb128( tvb, offset, &len );
-
+ offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len );
proto_tree_add_item(tree, hf_netsync_cmd_auth_collection, tvb,
offset, (gint)len, ENC_ASCII|ENC_NA );
offset += (gint)len;
@@ -251,8 +247,7 @@ static gint dissect_netsync_cmd_auth(tvbuff_t *tvb, gint offset, proto_tree *tr
offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
offset += NETSNYC_MERKLE_HASH_LENGTH;
- offset += dissect_uleb128( tvb, offset, &len );
-
+ offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len );
proto_tree_add_item(tree, hf_netsync_cmd_auth_sig, tvb,
offset, (gint)len, ENC_NA );
offset += (gint)len;
@@ -265,8 +260,7 @@ static gint dissect_netsync_cmd_confirm(tvbuff_t *tvb, gint offset, proto_tree
{
guint64 len = 0;
- offset += dissect_uleb128( tvb, offset, &len );
-
+ offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len );
proto_tree_add_item(tree, hf_netsync_cmd_confirm_sig, tvb,
offset, (gint)len, ENC_NA );
offset += (gint)len;
@@ -288,13 +282,10 @@ static gint dissect_netsync_cmd_refine(tvbuff_t *tvb, gint offset, proto_tree *
static gint dissect_netsync_cmd_done(tvbuff_t *tvb, gint offset, proto_tree *tree, guint size _U_)
{
- guint64 len = 0;
- guint bytes = 0;
-
- bytes = dissect_uleb128( tvb, offset, &len );
+ gint bytes = 0;
- proto_tree_add_uint(tree, hf_netsync_cmd_done_level, tvb,
- offset, bytes, (guint32)len );
+ proto_tree_add_item_ret_length(tree, hf_netsync_cmd_done_level, tvb,
+ offset, -1, ENC_LITTLE_ENDIAN|ENC_VARINT_PROTOBUF, &bytes);
offset += bytes;
proto_tree_add_item(tree, hf_netsync_cmd_done_type, tvb,
@@ -354,8 +345,7 @@ static gint dissect_netsync_cmd_data(tvbuff_t *tvb, gint offset, proto_tree *tr
offset, 1, ENC_BIG_ENDIAN );
offset += 1;
- offset += dissect_uleb128( tvb, offset, &len );
-
+ offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len );
proto_tree_add_item(tree, hf_netsync_cmd_data_payload, tvb,
offset, (gint)len, ENC_NA );
offset += (gint)len;
@@ -384,8 +374,7 @@ static gint dissect_netsync_cmd_delta(tvbuff_t *tvb, gint offset, proto_tree *t
offset, 1, ENC_BIG_ENDIAN );
offset += 1;
- offset += dissect_uleb128( tvb, offset, &len );
-
+ offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len );
proto_tree_add_item(tree, hf_netsync_cmd_delta_payload, tvb,
offset, (gint)len, ENC_NA );
offset += (gint)len;
@@ -416,7 +405,7 @@ get_netsync_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *dat
/* skip version and command */
offset += 2;
- size_bytes = dissect_uleb128( tvb, offset, &size );
+ size_bytes = tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &size );
/* the calculated size if for the data only, this doesn't
* include the version (1 byte), command (1 byte),
diff --git a/epan/dwarf.c b/epan/dwarf.c
index 86d95e7eb8..8c7a145e9b 100644
--- a/epan/dwarf.c
+++ b/epan/dwarf.c
@@ -27,26 +27,6 @@
#include "dwarf.h"
gint
-dissect_uleb128(tvbuff_t *tvb, gint offset, guint64 *value)
-{
- guint start_offset = offset;
- guint shift = 0;
- guint8 byte;
-
- *value = 0;
-
- do {
- byte = tvb_get_guint8(tvb, offset);
- offset += 1;
-
- *value |= ((guint64)(byte & 0x7F) << shift);
- shift += 7;
- } while ((byte & 0x80) && (shift < 64));
-
- return offset - start_offset;
-}
-
-gint
dissect_leb128(tvbuff_t *tvb, gint offset, gint64 *value)
{
guint start_offset = offset;
diff --git a/epan/dwarf.h b/epan/dwarf.h
index c948c5b315..211aca5713 100644
--- a/epan/dwarf.h
+++ b/epan/dwarf.h
@@ -25,7 +25,6 @@
#include <glib.h>
-gint dissect_uleb128(tvbuff_t *tvb, gint offset, guint64 *value);
gint dissect_leb128(tvbuff_t *tvb, gint offset, gint64 *value);
#endif /* __DWARF_H__ */
diff --git a/epan/proto.h b/epan/proto.h
index cf42174486..2ef8cc7f89 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -525,6 +525,9 @@ WS_DLL_PUBLIC WS_NORETURN void proto_report_dissector_bug(const char *message);
/* this can't collide with ENC_SEP_* because they can be used simultaneously */
#define ENC_NUM_PREF 0x00200000
+/* Use varint format as described in Protobuf protocol
+ * https://developers.google.cn/protocol-buffers/docs/encoding
+ */
#define ENC_VARINT_PROTOBUF 0x00000002
/* For cases where a string encoding contains hex, bit-or one or more