diff options
author | Ahmad Fatoum <ahmad@a3f.at> | 2017-06-02 11:34:55 +0200 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2017-06-02 15:05:53 +0000 |
commit | 197e48bceecf7a37a28fc9d5a9bf8565f099af8b (patch) | |
tree | fb3a01f455167dca9e5053cc34d806afbc5ed676 | |
parent | c5ef5c1f053beb664bad47e3374505f40b412169 (diff) | |
download | wireshark-197e48bceecf7a37a28fc9d5a9bf8565f099af8b.tar.gz |
packet-epl.c: Make dissector oss-fuzz friendly
oss-fuzz invokes the dissector without IP layer, so we can't assume
the IP address to be available when dissecting POWERLINK/UDP packets.
Same goes for the "Exported PDU" functionality.
Bug: 13756
Change-Id: I038f0445ada3f764dcc72f7bce1d02cfa49791fb
Reviewed-on: https://code.wireshark.org/review/21894
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r-- | epan/dissectors/packet-epl.c | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/epan/dissectors/packet-epl.c b/epan/dissectors/packet-epl.c index d93fabdb3c..ac9d69806b 100644 --- a/epan/dissectors/packet-epl.c +++ b/epan/dissectors/packet-epl.c @@ -2149,20 +2149,26 @@ epl_get_convo(packet_info *pinfo, int opts) struct epl_convo *convo; conversation_t * epan_convo; guint32 node_port; - address *node_addr; - address *node_dl_addr; + address *node_addr = &epl_placeholder_mac; + address *node_dl_addr = &epl_placeholder_mac; if (opts & CONVO_FOR_REQUEST) { node_port = pinfo->destport; - node_addr = &pinfo->dst; - node_dl_addr = &pinfo->dl_dst; + + if (pinfo->dst.type == AT_IPv4 || pinfo->dst.type == AT_ETHER) + node_addr = &pinfo->dst; + if (pinfo->dl_dst.type == AT_ETHER) + node_dl_addr = &pinfo->dl_dst; } else { node_port = pinfo->srcport; - node_addr = &pinfo->src; - node_dl_addr = &pinfo->dl_src; + + if (pinfo->src.type == AT_IPv4 || pinfo->src.type == AT_ETHER) + node_addr = &pinfo->src; + if (pinfo->dl_src.type == AT_ETHER) + node_dl_addr = &pinfo->dl_src; } /* It'd be better to consult the Ethernet or IP address when matching conversations, * but an ASnd request is targeted at a Multicast MAC address, so we'll use @@ -2504,15 +2510,26 @@ dissect_eplpdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean udp pinfo->ptype = PT_NONE; - /* Get Destination */ - pinfo->destport = !udpencap ? tvb_get_guint8(tvb, EPL_DEST_OFFSET) - : ((guint8*)pinfo->net_dst.data)[3]; + /* Get Destination and Source */ + if (udpencap) + { + /* The dissector may be invoked without an IP layer, + * so we need to check we can actually index into the buffer + */ + if (pinfo->net_dst.type == AT_IPv4) + pinfo->destport = ((guint8*)pinfo->net_dst.data)[3]; + if (pinfo->net_src.type == AT_IPv4) + pinfo->srcport = ((guint8*)pinfo->net_src.data)[3]; + } + else + { + pinfo->destport = tvb_get_guint8(tvb, EPL_DEST_OFFSET); + pinfo->srcport = tvb_get_guint8(tvb, EPL_SRC_OFFSET); + } + epl_segmentation.dest = pinfo->destport; dest_str = decode_epl_address(pinfo->destport); - /* Get Source */ - pinfo->srcport = !udpencap ? tvb_get_guint8(tvb, EPL_SRC_OFFSET) - : ((guint8*)pinfo->net_src.data)[3]; epl_segmentation.src = pinfo->srcport; src_str = decode_epl_address(pinfo->srcport); |