From 6d15429a847f17b4302053b621673e8d3df00e82 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 2 Sep 2019 15:13:17 -0700 Subject: 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 Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris --- wiretap/i4btrace.c | 74 +++++++++++++++++++++++++++--------------------------- 1 file 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; + } } } -- cgit v1.2.3