From bfd49879dd6d0eed66c266572d6fa467cf2e9ea6 Mon Sep 17 00:00:00 2001 From: Nicolas Cavallari Date: Fri, 20 Nov 2015 14:45:24 +0100 Subject: dbus dissector: Handle alignments of basic types. The D-Bus Specifications states that all basic types have alignment constraints. Padding must be added before the value and not after. Bug: 11758 Change-Id: I3c56689f47e1e385880dcea04506fe33b60670d3 Reviewed-on: https://code.wireshark.org/review/11994 Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- epan/dissectors/packet-dbus.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'epan/dissectors/packet-dbus.c') diff --git a/epan/dissectors/packet-dbus.c b/epan/dissectors/packet-dbus.c index fc124ae978..efc665e9c0 100644 --- a/epan/dissectors/packet-dbus.c +++ b/epan/dissectors/packet-dbus.c @@ -201,11 +201,40 @@ dbus_validate_signature(const char *sig _U_) return TRUE; } +static int +dbus_type_alignment(char sig) +{ + switch (sig) { + case 'y': + case 'g': + return 1; + case 'n': + case 'q': + return 2; + case 'i': + case 'u': + case 'b': + case 'o': + case 'a': + case 's': + return 4; + case 'x': + case 't': + case 'd': + return 8; + /* ... */ + default: + return 1; + } +} + static int dissect_dbus_sig(tvbuff_t *tvb, dbus_info_t *dinfo, proto_tree *tree, int offset, char sig, dbus_val_t *ret) { - const int org_offset = offset; proto_item *ti; + const int align = dbus_type_alignment(sig); + const int org_offset = (offset + align - 1) / align * align; + offset = org_offset; switch (sig) { case 'y': /* BYTE */ @@ -310,7 +339,7 @@ dissect_dbus_sig(tvbuff_t *tvb, dbus_info_t *dinfo, proto_tree *tree, int offset offset += 4; val = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, len, ENC_ASCII); - offset += (len + 1 /* NUL-byte */ + 3) & ~3; + offset += (len + 1 /* NUL-byte */); if (sig == 's') { ti = proto_tree_add_string_format(tree, hfi_dbus_value_str.id, tvb, org_offset, offset - org_offset, val, "STRING: %s", val); -- cgit v1.2.3