aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2019-09-02 15:13:17 -0700
committerGuy Harris <guy@alum.mit.edu>2019-09-02 22:27:37 +0000
commit6d15429a847f17b4302053b621673e8d3df00e82 (patch)
tree3f3c2e83ae88e12c2173cc07eece4b04b0f88dde
parentcdb942944aa91202fe85372c8f13c70db0ce3141 (diff)
If we get a short read on the first packet in the open, don't check any more.
There's no point in trying to read more packets to check the file type. Change-Id: Ic2c5a7692b60fab8a0022503338a40befe00d358 Ping-Bug: 16031 Reviewed-on: https://code.wireshark.org/review/34433 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--wiretap/i4btrace.c74
1 files changed, 37 insertions, 37 deletions
diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c
index 69de8859bd..b0d1b1e1bd 100644
--- a/wiretap/i4btrace.c
+++ b/wiretap/i4btrace.c
@@ -101,51 +101,51 @@ wtap_open_return_val i4btrace_open(wtap *wth, int *err, gchar **err_info)
err, err_info)) {
if (*err != WTAP_ERR_SHORT_READ)
return WTAP_OPEN_ERROR;
- }
-
- /*
- * Now try reading a few more packets.
- */
- for (int i = 1; i < PACKETS_TO_CHECK; i++) {
+ } else {
/*
- * Read and check the file header; we've already
- * decided whether this would be a byte-swapped file
- * or not, so we swap iff we decided it was.
+ * Now try reading a few more packets.
*/
- if (!wtap_read_bytes_or_eof(wth->fh, &hdr, sizeof(hdr), err,
- err_info)) {
- if (*err == 0) {
- /* EOF; no more packets to try. */
- break;
- }
- if (*err != WTAP_ERR_SHORT_READ)
- return WTAP_OPEN_ERROR;
- return WTAP_OPEN_NOT_MINE;
- }
-
- if (byte_swapped)
- I4B_BYTESWAP_HEADER(hdr);
- if (!I4B_HDR_IS_OK(hdr)) {
+ for (int i = 1; i < PACKETS_TO_CHECK; i++) {
/*
- * It doesn't look valid in either byte order.
+ * Read and check the file header; we've already
+ * decided whether this would be a byte-swapped file
+ * or not, so we swap iff we decided it was.
*/
- return WTAP_OPEN_NOT_MINE;
- }
+ if (!wtap_read_bytes_or_eof(wth->fh, &hdr, sizeof(hdr), err,
+ err_info)) {
+ if (*err == 0) {
+ /* EOF; no more packets to try. */
+ break;
+ }
+ if (*err != WTAP_ERR_SHORT_READ)
+ return WTAP_OPEN_ERROR;
+ return WTAP_OPEN_NOT_MINE;
+ }
- /*
- * Now try to read past the packet bytes; if that fails with
- * a short read, we don't fail, so that we can report
- * the file as a truncated I4B file.
- */
- if (!wtap_read_bytes(wth->fh, NULL, hdr.length - (guint32)sizeof(hdr),
- err, err_info)) {
- if (*err != WTAP_ERR_SHORT_READ)
- return WTAP_OPEN_ERROR;
+ if (byte_swapped)
+ I4B_BYTESWAP_HEADER(hdr);
+ if (!I4B_HDR_IS_OK(hdr)) {
+ /*
+ * It doesn't look valid.
+ */
+ return WTAP_OPEN_NOT_MINE;
+ }
/*
- * Probably a truncated file, so just quit.
+ * Now try to read past the packet bytes; if that
+ * fails with a short read, we don't fail, so that
+ * we can report the file as a truncated I4B file.
*/
- break;
+ if (!wtap_read_bytes(wth->fh, NULL,
+ hdr.length - (guint32)sizeof(hdr), err, err_info)) {
+ if (*err != WTAP_ERR_SHORT_READ)
+ return WTAP_OPEN_ERROR;
+
+ /*
+ * Probably a truncated file, so just quit.
+ */
+ break;
+ }
}
}