From 16ec12371aa3a0cdb3701f7526adf6f41705806b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Wed, 3 Nov 2010 18:23:27 -0400 Subject: [PATCH] pcapparse: Fail on unknown version or linktype The element only knows about major version 2 and only decodes linktype ethernet --- gst/pcapparse/gstpcapparse.c | 39 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/gst/pcapparse/gstpcapparse.c b/gst/pcapparse/gstpcapparse.c index 401e20f83e..925551fd00 100644 --- a/gst/pcapparse/gstpcapparse.c +++ b/gst/pcapparse/gstpcapparse.c @@ -468,7 +468,9 @@ gst_pcap_parse_chain (GstPad * pad, GstBuffer * buffer) self->cur_packet_size = incl_len; } } else { - guint magic; + guint32 magic; + guint32 linktype; + guint16 major_version; if (avail < 24) break; @@ -476,24 +478,43 @@ gst_pcap_parse_chain (GstPad * pad, GstBuffer * buffer) data = gst_adapter_peek (self->adapter, 24); magic = *((guint32 *) data); + major_version = *((guint16 *) (data + 4)); - gst_adapter_flush (self->adapter, 24); - - if (magic == 0xa1b2c3d4) + if (magic == 0xa1b2c3d4) { self->swap_endian = FALSE; - else if (magic == 0xd4c3b2a1) + } else if (magic == 0xd4c3b2a1) { self->swap_endian = TRUE; - else { + major_version = major_version << 8 | major_version >> 8; + } else { GST_ELEMENT_ERROR (self, STREAM, WRONG_TYPE, (NULL), - ("File is not a libpcap file version 2, magic is %X", magic)); + ("File is not a libpcap file, magic is %X", magic)); ret = GST_FLOW_ERROR; + goto out; } - if (ret == GST_FLOW_OK) - self->initialized = TRUE; + if (major_version != 2) { + GST_ELEMENT_ERROR (self, STREAM, WRONG_TYPE, (NULL), + ("File is not a libpcap major version 2, but %u", major_version)); + ret = GST_FLOW_ERROR; + goto out; + } + + linktype = gst_pcap_parse_read_uint32 (self, data + 20); + + if (linktype != 1) { + GST_ELEMENT_ERROR (self, STREAM, WRONG_TYPE, (NULL), + ("Only Ethernet packets of type 1 understood," + " type %d unknown", linktype)); + ret = GST_FLOW_ERROR; + goto out; + } + + gst_adapter_flush (self->adapter, 24); + self->initialized = TRUE; } } +out: if (ret != GST_FLOW_OK) gst_pcap_parse_reset (self);