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/ngsniffer.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/ngsniffer.c')
-rw-r--r-- | wiretap/ngsniffer.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index 5c9d28a37a..829ba74526 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -536,7 +536,7 @@ static gboolean ng_read_bytes(wtap *wth, void *buffer, unsigned int nbytes, gboolean is_random, int *err, gchar **err_info); static gboolean read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err, gchar **err_info); -static gboolean ng_file_skip_seq(wtap *wth, gint64 delta, int *err, +static gboolean ng_skip_bytes_seq(wtap *wth, unsigned int count, int *err, gchar **err_info); static gboolean ng_file_seek_rand(wtap *wth, gint64 offset, int *err, gchar **err_info); @@ -1056,7 +1056,7 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) * Skip any extra data in the record. */ if (padding != 0) { - if (!ng_file_skip_seq(wth, padding, err, + if (!ng_skip_bytes_seq(wth, padding, err, err_info)) return FALSE; } @@ -1077,7 +1077,7 @@ ngsniffer_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset) * and keep looping. */ if (padding != 0) { - if (!ng_file_skip_seq(wth, padding, err, + if (!ng_skip_bytes_seq(wth, padding, err, err_info)) return FALSE; } @@ -2588,7 +2588,7 @@ read_blob(FILE_T infile, ngsniffer_comp_stream_t *comp_stream, int *err, /* Skip some number of bytes forward in the sequential stream. */ static gboolean -ng_file_skip_seq(wtap *wth, gint64 delta, int *err, gchar **err_info) +ng_skip_bytes_seq(wtap *wth, unsigned int count, int *err, gchar **err_info) { ngsniffer_t *ngsniffer; char *buf; @@ -2597,26 +2597,24 @@ ng_file_skip_seq(wtap *wth, gint64 delta, int *err, gchar **err_info) ngsniffer = (ngsniffer_t *)wth->priv; if (wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_NGSNIFFER_UNCOMPRESSED) { - ngsniffer->seq.uncomp_offset += delta; - return file_skip(wth->fh, delta, err); + ngsniffer->seq.uncomp_offset += count; + return wtap_read_bytes(wth->fh, NULL, count, err, err_info); } - g_assert(delta >= 0); - - /* Ok, now read and discard "delta" bytes. */ + /* Ok, now read and discard "count" bytes. */ buf = (char *)g_malloc(INBUF_SIZE); - while (delta != 0) { - if (delta > INBUF_SIZE) + while (count != 0) { + if (count > INBUF_SIZE) amount_to_read = INBUF_SIZE; else - amount_to_read = (unsigned int) delta; + amount_to_read = count; if (!ng_read_bytes(wth, buf, amount_to_read, FALSE, err, err_info)) { g_free(buf); return FALSE; /* error */ } - delta -= amount_to_read; + count -= amount_to_read; } g_free(buf); |