diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-09-28 16:45:23 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-09-28 23:45:58 +0000 |
commit | 48a66835ee4f319ba7806a542bb2cf1f16a2ac06 (patch) | |
tree | f4b86d49b651fc55047f16d98b1c2401238e03ec /wiretap/erf.c | |
parent | a3ce2336b2a0e684a94d1e0046556bc0b42748f2 (diff) | |
download | wireshark-48a66835ee4f319ba7806a542bb2cf1f16a2ac06.tar.gz |
Use wtap_read_bytes() to skip over bytes when reading a record.
Allow file_read() to take a null pointer as a buffer argument; a null
argument means "do everything except copy the bytes from the file to the
user buffer". That means that wtap_read_bytes() and
wtap_read_bytes_or_eof() also support a null pointer as a buffer
argument.
Use wtap_read_bytes() with a null buffer argument rather than
file_skip() to skip forward over data.
This fixes some places where files were mis-identified as ERF files, as
the ERF open heuristics now get a short "read" error if they try to skip
over more bytes than exist in the file.
Change-Id: I4f73499d877c1f582e2bcf9b045034880cb09622
Reviewed-on: https://code.wireshark.org/review/17974
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap/erf.c')
-rw-r--r-- | wiretap/erf.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/wiretap/erf.c b/wiretap/erf.c index 62e5f40b77..a48e666827 100644 --- a/wiretap/erf.c +++ b/wiretap/erf.c @@ -231,8 +231,6 @@ extern wtap_open_return_val erf_open(wtap *wth, int *err, gchar **err_info) guint16 rlen; guint64 erf_ext_header; guint8 type; - gboolean r; - gchar * buffer; memset(&prevts, 0, sizeof(prevts)); @@ -290,8 +288,16 @@ extern wtap_open_return_val erf_open(wtap *wth, int *err, gchar **err_info) /* Skip PAD records, timestamps may not be set */ if ((header.type & 0x7F) == ERF_TYPE_PAD) { - if (file_seek(wth->fh, packet_size, SEEK_CUR, err) == -1) { - return WTAP_OPEN_ERROR; + if (!wtap_read_bytes(wth->fh, NULL, packet_size, err, err_info)) { + if (*err != WTAP_ERR_SHORT_READ) { + /* A real error */ + return WTAP_OPEN_ERROR; + } + /* ERF record too short, accept the file, + only if the very first records have been successfully checked */ + if (i < MIN_RECORDS_FOR_ERF_CHECK) { + return WTAP_OPEN_NOT_MINE; + } } continue; } @@ -367,8 +373,6 @@ extern wtap_open_return_val erf_open(wtap *wth, int *err, gchar **err_info) break; } - /* The file_seek function do not return an error if the end of file - is reached whereas the record is truncated */ if (packet_size > WTAP_MAX_PACKET_SIZE) { /* * Probably a corrupt capture file or a file that's not an ERF file @@ -376,11 +380,7 @@ extern wtap_open_return_val erf_open(wtap *wth, int *err, gchar **err_info) */ return WTAP_OPEN_NOT_MINE; } - buffer=(gchar *)g_malloc(packet_size); - r = wtap_read_bytes(wth->fh, buffer, packet_size, err, err_info); - g_free(buffer); - - if (!r) { + if (!wtap_read_bytes(wth->fh, NULL, packet_size, err, err_info)) { if (*err != WTAP_ERR_SHORT_READ) { /* A real error */ return WTAP_OPEN_ERROR; |