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>
This commit is contained in:
parent
edf694393b
commit
d8615d27b4
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue