aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-02-21 08:27:41 +0000
committerGuy Harris <guy@alum.mit.edu>2012-02-21 08:27:41 +0000
commita0ccca53d9f9e21370334f0aba9eddb29b9df4d9 (patch)
treebfde92b3f2fd53462632e6423ac51ab1bf4e8273
parentb15cea5c186c5868a6fff3bdc53090721fe0261f (diff)
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
-rw-r--r--wiretap/pcapng.c20
1 files 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 */
}
}