From a0ccca53d9f9e21370334f0aba9eddb29b9df4d9 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 21 Feb 2012 08:27:41 +0000 Subject: Once we've read a valid SHB, we've concluded the file is a pcap-NG file, so if we later get a short read, we have to return -1 and set *err to WTAP_ERR_SHORT_READ. Otherwise, we'll try other file types and, if none of them match, we'll try to close the wtap structure, which crashes. svn path=/trunk/; revision=41102 --- wiretap/pcapng.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/wiretap/pcapng.c b/wiretap/pcapng.c index bbc1b8009c..702484a6cf 100644 --- a/wiretap/pcapng.c +++ b/wiretap/pcapng.c @@ -1600,6 +1600,12 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) } pn.shb_read = TRUE; + /* + * At this point, we've decided this is a pcap-NG file, not + * some other type of file, so we can't return 0, as that + * means "this isn't a pcap-NG file, try some other file + * type". + */ wth->shb_hdr.opt_comment = wblock.data.section.opt_comment; wth->shb_hdr.shb_hardware = wblock.data.section.shb_hardware; wth->shb_hdr.shb_os = wblock.data.section.shb_os; @@ -1628,9 +1634,9 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) if (bytes_read <= 0) { pcapng_debug0("pcapng_open: couldn't read IDB"); *err = file_error(wth->fh, err_info); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } int_data.wtap_encap = wblock.data.if_descr.wtap_encap; @@ -1671,9 +1677,9 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) if (bytes_read != sizeof bh) { *err = file_error(wth->fh, err_info); pcapng_debug3("pcapng_open: Check for more IDB:s, file_read() returned %d instead of %u, err = %d.", bytes_read, (unsigned int)sizeof bh, *err); - if (*err != 0) - return -1; - return 0; + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; } /* go back to whwre we where */ @@ -1686,7 +1692,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info) pcapng_debug1("pcapng_open: Check for more IDB:s block_type 0x%x", bh.block_type); if (bh.block_type != BLOCK_TYPE_IDB){ - break; /* No more IDB:s */ + break; /* No more IDB:s */ } } -- cgit v1.2.3