From 90d7c5f59b574e254bc1bb70aaaf12372fe97cc3 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Wed, 22 Jan 2014 00:26:36 +0000 Subject: Don't write out packets that have a "captured length" bigger than we're willing to read or that's bigger than will fit in the file format; instead, report an error. For the "I can't write a packet of that type in that file type" error, report the file type in question. svn path=/trunk/; revision=54882 --- wiretap/netmon.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'wiretap/netmon.c') diff --git a/wiretap/netmon.c b/wiretap/netmon.c index ad1aacb8f6..717992a738 100644 --- a/wiretap/netmon.c +++ b/wiretap/netmon.c @@ -1027,6 +1027,34 @@ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, gint64 secs; gint32 nsecs; + switch (wdh->file_type_subtype) { + + case WTAP_FILE_TYPE_SUBTYPE_NETMON_1_x: + /* + * The length fields are 16-bit, so there's a hard limit + * of 65535. + */ + if (phdr->caplen > 65535) { + *err = WTAP_ERR_PACKET_TOO_LARGE; + return FALSE; + } + break; + + case WTAP_FILE_TYPE_SUBTYPE_NETMON_2_x: + /* Don't write anything we're not willing to read. */ + if (phdr->caplen > WTAP_MAX_PACKET_SIZE) { + *err = WTAP_ERR_PACKET_TOO_LARGE; + return FALSE; + } + break; + + default: + /* We should never get here - our open routine + should only get called for the types above. */ + *err = WTAP_ERR_UNSUPPORTED_FILE_TYPE; + return FALSE; + } + if (wdh->encap == WTAP_ENCAP_PER_PACKET) { /* * Is this network type supported? -- cgit v1.2.3