diff options
author | Nicolas Cavallari <nicolas.cavallari@green-communications.fr> | 2015-11-20 14:45:24 +0100 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2015-11-24 02:02:27 +0000 |
commit | bfd49879dd6d0eed66c266572d6fa467cf2e9ea6 (patch) | |
tree | d5c956965dabc0fb565c1a89a88a85bd860f67e0 /epan/dissectors/packet-dbus.c | |
parent | ed0cc4319cdfa48d65ef504b5be0a6eb0b41d1a7 (diff) |
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 <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/dissectors/packet-dbus.c')
-rw-r--r-- | epan/dissectors/packet-dbus.c | 33 |
1 files changed, 31 insertions, 2 deletions
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 @@ -202,10 +202,39 @@ dbus_validate_signature(const char *sig _U_) } 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); |