PTP: Check for enough bytes

Make sure we have enough bytes for Length and Type fields before we read
from tvb.
Using existing msg_len for the checks.

Closes: wireshark/wireshark#17355


(cherry picked from commit fd14396972)
This commit is contained in:
Uli Heilmeier 2021-04-20 22:47:43 +02:00
parent aa169ab224
commit ab13858b7f
1 changed files with 1 additions and 3 deletions

View File

@ -2562,7 +2562,6 @@ dissect_ptp_v2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean ptp
col_add_str(pinfo->cinfo, COL_INFO, val_to_str_ext(ptp_v2_messageid, &ptp_v2_messageid_vals_ext, "Unknown PTP Message (%u)"));
if (ptp_v2_messageid == PTP_V2_SIGNALLING_MESSAGE)
{
guint proto_len;
guint32 tlv_offset;
guint16 tlv_type;
guint32 org_id;
@ -2570,10 +2569,9 @@ dissect_ptp_v2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean ptp
guint16 tlv_length;
guint16 wr_messageId;
proto_len = tvb_reported_length(tvb);
tlv_offset = PTP_V2_SIG_TLV_START;
while (tlv_offset < proto_len)
while (tlv_offset + PTP_V2_SIG_TLV_LENGTH_LEN + PTP_V2_SIG_TLV_TYPE_LEN <= msg_len)
{
tlv_length = tvb_get_ntohs(tvb, tlv_offset + PTP_V2_SIG_TLV_LENGTH_OFFSET);
tlv_type = tvb_get_ntohs(tvb, tlv_offset + PTP_V2_SIG_TLV_TYPE_OFFSET);