aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/camins.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2020-04-11 20:43:09 -0700
committerGuy Harris <gharris@sonic.net>2020-04-12 04:13:25 +0000
commitd8615d27b4ff168bc438576ca94fd41192579256 (patch)
tree0329e4b53981eaa7069a1275b9962c8daed33186 /wiretap/camins.c
parentedf694393b7034530e2b5b7b5cd2da3322d10b6b (diff)
Fix the heuristic for checking whether it's a CAM Inspector file.
wtap_read_bytes() returns TRUE on *success*, so if we're in the loop, the last read succeeded, and no error code was supplied. When we *exit* the loop, the read didn't succeed; check for the status then. If we got a short read, we ran out of file data, so check the heuristics (even if it's not an integral number of 2-byte blocks, treat it as a CAM Inspector file - it might have gotten cut short); if we got a real read error, report that to our caller. Bug: 16458 Change-Id: Ia1e838006744dadbc2883459aec16d0d11b732e1 Reviewed-on: https://code.wireshark.org/review/36795 Petri-Dish: Guy Harris <gharris@sonic.net> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <gharris@sonic.net>
Diffstat (limited to 'wiretap/camins.c')
-rw-r--r--wiretap/camins.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/wiretap/camins.c b/wiretap/camins.c
index ec25d80469..f9595b9e05 100644
--- a/wiretap/camins.c
+++ b/wiretap/camins.c
@@ -113,7 +113,7 @@ typedef enum {
A file may have errors that affect the size blocks. Therefore, we
read the entire file and require that we have much more valid pairs
than errors. */
-static gboolean detect_camins_file(FILE_T fh)
+static wtap_open_return_val detect_camins_file(FILE_T fh)
{
int err;
gchar *err_info;
@@ -123,9 +123,6 @@ static gboolean detect_camins_file(FILE_T fh)
guint32 valid_pairs = 0, invalid_pairs = 0;
while (wtap_read_bytes(fh, block, sizeof(block), &err, &err_info)) {
- if (err == WTAP_ERR_SHORT_READ)
- break;
-
if (search_block != 0) {
/* We're searching for a matching block to complete the pair. */
@@ -168,12 +165,17 @@ static gboolean detect_camins_file(FILE_T fh)
}
}
+ if (err != WTAP_ERR_SHORT_READ) {
+ /* A real read error. */
+ return WTAP_OPEN_ERROR;
+ }
+
/* For valid_pairs == invalid_pairs == 0, this isn't a camins file.
Don't change > into >= */
if (valid_pairs > 10 * invalid_pairs)
- return TRUE;
+ return WTAP_OPEN_MINE;
- return FALSE;
+ return WTAP_OPEN_NOT_MINE;
}
@@ -408,8 +410,13 @@ camins_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf,
wtap_open_return_val camins_open(wtap *wth, int *err, gchar **err_info _U_)
{
- if (!detect_camins_file(wth->fh))
- return WTAP_OPEN_NOT_MINE; /* no CAM Inspector file */
+ wtap_open_return_val status;
+
+ status = detect_camins_file(wth->fh);
+ if (status != WTAP_OPEN_MINE) {
+ /* A read error or a failed heuristic. */
+ return status;
+ }
/* rewind the fh so we re-read from the beginning */
if (-1 == file_seek(wth->fh, 0, SEEK_SET, err))