From fed0e7c2d09be11bd0c65aa5f8f420d61d2f773b Mon Sep 17 00:00:00 2001 From: Pascal Quantin Date: Mon, 13 May 2019 22:55:46 +0200 Subject: PROFINET DCP: fix dissection of an empty DHCP option Bug: 15774 Change-Id: Ief2588e5d6f43da708ef071a4490f5f881268820 Reviewed-on: https://code.wireshark.org/review/33186 Petri-Dish: Pascal Quantin Tested-by: Petri Dish Buildbot Reviewed-by: Mehmet Oguz Sakaoglu Reviewed-by: Pascal Quantin --- plugins/epan/profinet/packet-pn-dcp.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'plugins/epan') diff --git a/plugins/epan/profinet/packet-pn-dcp.c b/plugins/epan/profinet/packet-pn-dcp.c index c4c18091b0..41746ac901 100644 --- a/plugins/epan/profinet/packet-pn-dcp.c +++ b/plugins/epan/profinet/packet-pn-dcp.c @@ -908,24 +908,25 @@ dissect_PNDCP_Suboption_DHCP(tvbuff_t *tvb, int offset, packet_info *pinfo, } offset += 1;//SuboptionDHCP offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_dhcp_parameter_length, &dhcpparameterlength); - offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_dhcp_parameter_data, &dhcpparameterdata); - - if (dhcpparameterlength == 1) { - if (dhcpparameterdata == 1) { - proto_item_append_text(block_item, ", Client-ID: MAC Address"); + if (dhcpparameterlength > 0) { + offset = dissect_pn_uint8(tvb, offset, pinfo, tree, hf_pn_dcp_suboption_dhcp_parameter_data, &dhcpparameterdata); + if (dhcpparameterlength == 1) { + if (dhcpparameterdata == 1) { + proto_item_append_text(block_item, ", Client-ID: MAC Address"); + } + else { + proto_item_append_text(block_item, ", Client-ID: Name of Station"); + } } else { - proto_item_append_text(block_item, ", Client-ID: Name of Station"); + proto_item_append_text(block_item, ", Client-ID: Arbitrary"); + arbitraryclientID = (char *)wmem_alloc(wmem_packet_scope(), dhcpparameterlength); + tvb_memcpy(tvb, (guint8 *)arbitraryclientID, offset, dhcpparameterlength - 1); + arbitraryclientID[dhcpparameterlength - 1] = '\0'; + proto_tree_add_string(tree, hf_pn_dcp_suboption_dhcp_arbitrary_client_id, tvb, offset, dhcpparameterlength - 1, arbitraryclientID); + offset += dhcpparameterlength; } } - else { - proto_item_append_text(block_item, ", Client-ID: Arbitrary"); - arbitraryclientID = (char *)wmem_alloc(wmem_packet_scope(), dhcpparameterlength); - tvb_memcpy(tvb, (guint8 *)arbitraryclientID, offset, 5); - arbitraryclientID[dhcpparameterlength - 1] = '\0'; - proto_tree_add_string(tree, hf_pn_dcp_suboption_dhcp_arbitrary_client_id, tvb, offset, dhcpparameterlength - 1, arbitraryclientID); - offset += dhcpparameterlength; - } break; case PNDCP_SUBOPTION_DHCP_CONTROL_FOR_ADDRESS_RES: pn_append_info(pinfo, dcp_item, ", Control DHCP for address resolution"); -- cgit v1.2.3