From e300f4db52ddfcdfbf8a53d69d88e037365cb7a3 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 5 Mar 2002 05:58:41 +0000 Subject: [PATCH] Have "wtap_seek_read()" return 0 on success and -1 on failure, and take an "err" argument that points to an "int" into which to put an error code if it fails. Check for errors in one call to it, and note that we should do so in other places. In the "wtap_seek_read()" call in the TCP graphing code, don't overwrite "cfile.pseudo_header", and make the buffer into which we read the data WTAP_MAX_PACKET_SIZE bytes, as it should be. In some of the file readers for text files, check for errors from the "parse the record header" and "parse the hex dump" routines when reading sequentially. In "csids_seek_read()", fix some calls to "file_error()" to check the error on the random stream (that being what we're reading). svn path=/trunk/; revision=4874 --- file.c | 27 +++++++++++++++++------ gtk/main.c | 6 ++++-- gtk/tcp_graph.c | 11 ++++++---- proto_hier_stats.c | 9 ++++---- wiretap/ascend.c | 17 ++++++++++----- wiretap/csids.c | 34 ++++++++++++++++------------- wiretap/dbs-etherwatch.c | 31 ++++++++++++++++----------- wiretap/file.c | 20 +++++++++++++---- wiretap/i4btrace.c | 22 ++++++++++++------- wiretap/iptrace.c | 46 +++++++++++++++++++++++++++------------- wiretap/netmon.c | 16 ++++++++------ wiretap/nettl.c | 24 ++++++++++++++------- wiretap/ngsniffer.c | 28 ++++++++++++++---------- wiretap/pppdump.c | 18 ++++++++++------ wiretap/radcom.c | 23 +++++++++++++------- wiretap/snoop.c | 16 ++++++++------ wiretap/toshiba.c | 35 ++++++++++++++++++------------ wiretap/visual.c | 24 +++++++++++++++------ wiretap/vms.c | 29 ++++++++++++++----------- wiretap/wtap-int.h | 5 ++--- wiretap/wtap.c | 10 +++++---- wiretap/wtap.h | 6 +++--- 22 files changed, 292 insertions(+), 165 deletions(-) diff --git a/file.c b/file.c index c2155ce9a7..4576514b39 100644 --- a/file.c +++ b/file.c @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.264 2002/02/27 08:57:14 guy Exp $ + * $Id: file.c,v 1.265 2002/03/05 05:58:27 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -898,6 +898,7 @@ rescan_packets(capture_file *cf, const char *action, gboolean refilter, guint32 progbar_quantum; guint32 progbar_nextstep; unsigned int count; + int err; frame_data *selected_frame; int selected_row; int row; @@ -1000,8 +1001,9 @@ rescan_packets(capture_file *cf, const char *action, gboolean refilter, free_data_sources(fdata); /* release data source list */ } + /* XXX - do something with "err" */ wtap_seek_read (cf->wth, fdata->file_off, &cf->pseudo_header, - cf->pd, fdata->cap_len); + cf->pd, fdata->cap_len, &err); row = add_packet_to_packet_list(fdata, cf, &cf->pseudo_header, cf->pd, refilter); @@ -1058,6 +1060,7 @@ print_packets(capture_file *cf, print_args_t *print_args) guint32 progbar_quantum; guint32 progbar_nextstep; guint32 count; + int err; gint *col_widths = NULL; gint data_width; gboolean print_separator; @@ -1172,8 +1175,9 @@ print_packets(capture_file *cf, print_args_t *print_args) */ if (((print_args->suppress_unmarked && fdata->flags.marked ) || !(print_args->suppress_unmarked)) && fdata->flags.passed_dfilter) { + /* XXX - do something with "err" */ wtap_seek_read (cf->wth, fdata->file_off, &cf->pseudo_header, - cf->pd, fdata->cap_len); + cf->pd, fdata->cap_len, &err); if (print_args->print_summary) { /* Fill in the column information, but don't bother creating the logical protocol tree. */ @@ -1374,6 +1378,7 @@ find_packet(capture_file *cf, dfilter_t *sfcode) guint32 progbar_quantum; guint32 progbar_nextstep; unsigned int count; + int err; gboolean frame_matched; int row; epan_dissect_t *edt; @@ -1438,8 +1443,9 @@ find_packet(capture_file *cf, dfilter_t *sfcode) /* Is this packet in the display? */ if (fdata->flags.passed_dfilter) { /* Yes. Does it match the search filter? */ + /* XXX - do something with "err" */ wtap_seek_read(cf->wth, fdata->file_off, &cf->pseudo_header, - cf->pd, fdata->cap_len); + cf->pd, fdata->cap_len, &err); edt = epan_dissect_new(TRUE, FALSE); epan_dissect_prime_dfilter(edt, sfcode); epan_dissect_run(edt, &cf->pseudo_header, cf->pd, fdata, NULL); @@ -1503,6 +1509,7 @@ void select_packet(capture_file *cf, int row) { frame_data *fdata; + int err; /* Get the frame data struct pointer for this frame */ fdata = (frame_data *) gtk_clist_get_row_data(GTK_CLIST(packet_list), row); @@ -1542,8 +1549,9 @@ select_packet(capture_file *cf, int row) cf->current_frame = fdata; /* Get the data in that frame. */ + /* XXX - do something with "err" */ wtap_seek_read (cf->wth, fdata->file_off, &cf->pseudo_header, - cf->pd, fdata->cap_len); + cf->pd, fdata->cap_len, &err); /* Create the logical protocol tree. */ if (cf->edt != NULL) { @@ -1783,8 +1791,13 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered, gboolean sa hdr.caplen = fdata->cap_len; hdr.len = fdata->pkt_len; hdr.pkt_encap = fdata->lnk_t; - wtap_seek_read(cf->wth, fdata->file_off, &pseudo_header, - pd, fdata->cap_len); + if (wtap_seek_read(cf->wth, fdata->file_off, &pseudo_header, + pd, fdata->cap_len, &err) == -1) { + simple_dialog(ESD_TYPE_CRIT, NULL, + file_read_error_message(err), cf->filename); + wtap_dump_close(pdh, &err); + goto done; + } if (!wtap_dump(pdh, &hdr, &pseudo_header, pd, &err)) { simple_dialog(ESD_TYPE_CRIT, NULL, diff --git a/gtk/main.c b/gtk/main.c index 7af2696188..5438bc662b 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.237 2002/02/24 09:25:36 guy Exp $ + * $Id: main.c,v 1.238 2002/03/05 05:58:35 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -406,10 +406,12 @@ get_text_from_packet_list(gpointer data) epan_dissect_t *edt; gchar *buf=NULL; int len; + int err; if (fdata != NULL) { + /* XXX - do something with "err" */ wtap_seek_read(cfile.wth, fdata->file_off, &cfile.pseudo_header, - cfile.pd, fdata->cap_len); + cfile.pd, fdata->cap_len, &err); edt = epan_dissect_new(FALSE, FALSE); epan_dissect_run(edt, &cfile.pseudo_header, cfile.pd, fdata, diff --git a/gtk/tcp_graph.c b/gtk/tcp_graph.c index 0a74032d84..01077add8e 100644 --- a/gtk/tcp_graph.c +++ b/gtk/tcp_graph.c @@ -3,7 +3,7 @@ * By Pavel Mores * Win32 port: rwh@unifiedtech.com * - * $Id: tcp_graph.c,v 1.14 2002/01/30 23:08:27 guy Exp $ + * $Id: tcp_graph.c,v 1.15 2002/03/05 05:58:35 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -1737,10 +1737,12 @@ static void graph_destroy (struct graph *g) static void graph_segment_list_get (struct graph *g) { frame_data *ptr; - char pd[4096]; + union wtap_pseudo_header pseudo_header; + char pd[WTAP_MAX_PACKET_SIZE]; struct segment *segment=NULL, *last=NULL; struct segment current; int condition; + int err; debug(DBS_FENTRY) puts ("graph_segment_list_get()"); get_headers (cfile.current_frame, cfile.pd, ¤t); @@ -1750,8 +1752,9 @@ static void graph_segment_list_get (struct graph *g) condition = COMPARE_ANY_DIR; for (ptr=cfile.plist; ptr; ptr=ptr->next) { - wtap_seek_read (cfile.wth, ptr->file_off, &cfile.pseudo_header, - pd, 4096); + /* XXX - do something with "err" */ + wtap_seek_read (cfile.wth, ptr->file_off, &pseudo_header, + pd, ptr->cap_len, &err); if (!segment) segment = (struct segment * )malloc (sizeof (struct segment)); if (!segment) diff --git a/proto_hier_stats.c b/proto_hier_stats.c index 8493949d43..4153f884d8 100644 --- a/proto_hier_stats.c +++ b/proto_hier_stats.c @@ -1,7 +1,7 @@ /* proto_hier_stats.c * Routines for calculating statistics based on protocol. * - * $Id: proto_hier_stats.c,v 1.11 2002/01/21 07:36:48 guy Exp $ + * $Id: proto_hier_stats.c,v 1.12 2002/03/05 05:58:28 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -22,7 +22,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -127,14 +126,16 @@ process_frame(frame_data *frame, column_info *cinfo, ph_stats_t* ps) epan_dissect_t *edt; union wtap_pseudo_header phdr; guint8 pd[WTAP_MAX_PACKET_SIZE]; + int err; /* Load the frame from the capture file */ + /* XX - do something with "err" */ wtap_seek_read(cfile.wth, frame->file_off, &phdr, - pd, frame->cap_len); + pd, frame->cap_len, &err); /* Dissect the frame */ edt = epan_dissect_new(TRUE, FALSE); - epan_dissect_run(edt, &phdr, pd, frame, cinfo); + epan_dissect_run(edt, &phdr, pd, frame, cinfo); /* Get stats from this protocol tree */ process_tree(edt->tree, ps, frame->pkt_len); diff --git a/wiretap/ascend.c b/wiretap/ascend.c index 25e75546e8..1f93052025 100644 --- a/wiretap/ascend.c +++ b/wiretap/ascend.c @@ -1,6 +1,6 @@ /* ascend.c * - * $Id: ascend.c,v 1.27 2002/03/04 00:25:35 guy Exp $ + * $Id: ascend.c,v 1.28 2002/03/05 05:58:40 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -103,7 +103,7 @@ static const char ascend_w2magic[] = { 'W', 'D', '_', 'D', 'I', 'A', 'L', 'O', ' static gboolean ascend_read(wtap *wth, int *err, long *data_offset); static int ascend_seek_read (wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guint8 *pd, int len); + union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err); static void ascend_close(wtap *wth); /* Seeks to the beginning of the next packet, and returns the @@ -341,10 +341,17 @@ static gboolean ascend_read(wtap *wth, int *err, long *data_offset) } static int ascend_seek_read (wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guint8 *pd, int len) + union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err) { - file_seek(wth->random_fh, seek_off, SEEK_SET); - return parse_ascend(wth->random_fh, pd, &pseudo_header->ascend, NULL, len); + if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); + return -1; + } + if (! parse_ascend(wth->random_fh, pd, &pseudo_header->ascend, NULL, len)) { + *err = WTAP_ERR_BAD_RECORD; + return -1; + } + return 0; } static void ascend_close(wtap *wth) diff --git a/wiretap/csids.c b/wiretap/csids.c index 992998c36f..8fd03e4ed4 100644 --- a/wiretap/csids.c +++ b/wiretap/csids.c @@ -1,6 +1,6 @@ /* csids.c * - * $Id: csids.c,v 1.11 2002/03/04 00:25:35 guy Exp $ + * $Id: csids.c,v 1.12 2002/03/05 05:58:40 guy Exp $ * * Copyright (c) 2000 by Mike Hall * Copyright (c) 2000 by Cisco Systems @@ -46,7 +46,7 @@ static gboolean csids_read(wtap *wth, int *err, long *data_offset); static int csids_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guint8 *pd, int len); + union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err); static void csids_close(wtap *wth); struct csids_header { @@ -202,36 +202,40 @@ csids_seek_read (wtap *wth, long seek_off, union wtap_pseudo_header *pseudo_header _U_, guint8 *pd, - int len) + int len, + int *err) { - int err = 0; int bytesRead = 0; struct csids_header hdr; - file_seek(wth->random_fh, seek_off , SEEK_SET); + if( file_seek( wth->random_fh, seek_off, SEEK_SET ) == -1 ) { + *err = file_error( wth->random_fh ); + return -1; + } - bytesRead = file_read( &hdr, 1, sizeof( struct csids_header) , wth->random_fh ); + bytesRead = file_read( &hdr, 1, sizeof( struct csids_header), wth->random_fh ); if( bytesRead != sizeof( struct csids_header) ) { - err = file_error( wth->fh ); - if( err != 0 ) { - return -1; - } else { - return 0; + *err = file_error( wth->random_fh ); + if( *err == 0 ) { + *err = WTAP_ERR_SHORT_READ; } + return -1; } hdr.seconds = pntohl(&hdr.seconds); hdr.caplen = pntohs(&hdr.caplen); if( len != hdr.caplen ) { + *err = WTAP_ERR_BAD_RECORD; return -1; } bytesRead = file_read( pd, 1, hdr.caplen, wth->random_fh ); if( bytesRead != hdr.caplen ) { - err = file_error( wth->fh ); - if( err != 0 ) { - return -1; - } + *err = file_error( wth->random_fh ); + if( *err == 0 ) { + *err = WTAP_ERR_SHORT_READ; + } + return -1; } if( wth->capture.csids->byteswapped == TRUE ) { diff --git a/wiretap/dbs-etherwatch.c b/wiretap/dbs-etherwatch.c index bd69b78628..8c104df761 100644 --- a/wiretap/dbs-etherwatch.c +++ b/wiretap/dbs-etherwatch.c @@ -1,6 +1,6 @@ /* dbs-etherwatch.c * - * $Id: dbs-etherwatch.c,v 1.5 2002/03/04 00:25:35 guy Exp $ + * $Id: dbs-etherwatch.c,v 1.6 2002/03/05 05:58:40 guy Exp $ * * Wiretap Library * Copyright (c) 2001 by Marc Milgram @@ -77,12 +77,11 @@ static const char dbs_etherwatch_rec_magic[] = static gboolean dbs_etherwatch_read(wtap *wth, int *err, long *data_offset); static int dbs_etherwatch_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guint8 *pd, int len); + union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err); static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, long byte_offset); static int parse_dbs_etherwatch_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err); static int parse_dbs_etherwatch_rec_hdr(wtap *wth, FILE_T fh, int *err); - /* Seeks to the beginning of the next packet, and returns the byte offset. Returns -1 on failure, and sets "*err" to the error. */ static long dbs_etherwatch_seek_next_packet(wtap *wth, int *err) @@ -205,13 +204,16 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, long *data_offset) /* Parse the header */ pkt_len = parse_dbs_etherwatch_rec_hdr(wth, wth->fh, err); + if (pkt_len == -1) + return FALSE; /* Make sure we have enough room for the packet */ buffer_assure_space(wth->frame_buffer, DBS_ETHERWATCH_MAX_PACKET_LEN); buf = buffer_start_ptr(wth->frame_buffer); /* Convert the ASCII hex dump to binary data */ - parse_dbs_etherwatch_hex_dump(wth->fh, pkt_len, buf, err); + if (parse_dbs_etherwatch_hex_dump(wth->fh, pkt_len, buf, err) == -1) + return FALSE; wth->data_offset = offset; *data_offset = offset; @@ -222,20 +224,25 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, long *data_offset) static int dbs_etherwatch_seek_read (wtap *wth, long seek_off, union wtap_pseudo_header *pseudo_header _U_, - guint8 *pd, int len) + guint8 *pd, int len, int *err) { int pkt_len; - int err; - file_seek(wth->random_fh, seek_off - 1, SEEK_SET); - - pkt_len = parse_dbs_etherwatch_rec_hdr(NULL, wth->random_fh, &err); - - if (pkt_len != len) { + if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); return -1; } - parse_dbs_etherwatch_hex_dump(wth->random_fh, pkt_len, pd, &err); + pkt_len = parse_dbs_etherwatch_rec_hdr(NULL, wth->random_fh, err); + + if (pkt_len != len) { + if (pkt_len != -1) + *err = WTAP_ERR_BAD_RECORD; + return -1; + } + + if (parse_dbs_etherwatch_hex_dump(wth->random_fh, pkt_len, pd, err) == -1) + return -1; return 0; } diff --git a/wiretap/file.c b/wiretap/file.c index 1458ed4783..8dfa405eb8 100644 --- a/wiretap/file.c +++ b/wiretap/file.c @@ -1,6 +1,6 @@ /* file.c * - * $Id: file.c,v 1.83 2002/03/04 00:25:35 guy Exp $ + * $Id: file.c,v 1.84 2002/03/05 05:58:40 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -124,11 +124,23 @@ static int (*open_routines[])(wtap *, int *) = { int wtap_def_seek_read(wtap *wth, long seek_off, union wtap_pseudo_header *pseudo_header _U_, - guint8 *pd, int len) + guint8 *pd, int len, int *err) { - file_seek(wth->random_fh, seek_off, SEEK_SET); + int bytes_read; - return file_read(pd, sizeof(guint8), len, wth->random_fh); + if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); + return -1; + } + + bytes_read = file_read(pd, sizeof(guint8), len, wth->random_fh); + if (bytes_read != len) { + *err = file_error(wth->random_fh); + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; + return -1; + } + return 0; } /* diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c index 0d5dec1c50..0565cdae52 100644 --- a/wiretap/i4btrace.c +++ b/wiretap/i4btrace.c @@ -1,6 +1,6 @@ /* i4btrace.c * - * $Id: i4btrace.c,v 1.17 2002/03/04 00:25:35 guy Exp $ + * $Id: i4btrace.c,v 1.18 2002/03/05 05:58:40 guy Exp $ * * Wiretap Library * Copyright (c) 1999 by Bert Driehuis @@ -34,7 +34,7 @@ static gboolean i4btrace_read(wtap *wth, int *err, long *data_offset); static int i4btrace_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int length); + union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err); static int i4b_read_rec_header(FILE_T fh, i4b_trace_hdr_t *hdr, int *err); static void i4b_byte_swap_header(wtap *wth, i4b_trace_hdr_t *hdr); static int i4b_read_rec_data(FILE_T fh, u_char *pd, int length, int *err); @@ -225,19 +225,25 @@ static gboolean i4btrace_read(wtap *wth, int *err, long *data_offset) static int i4btrace_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int length) + union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err) { int ret; - int err; /* XXX - return this */ i4b_trace_hdr_t hdr; - file_seek(wth->random_fh, seek_off, SEEK_SET); + if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); + return -1; + } /* Read record header. */ - ret = i4b_read_rec_header(wth->random_fh, &hdr, &err); + ret = i4b_read_rec_header(wth->random_fh, &hdr, err); if (ret <= 0) { /* Read error or EOF */ - return ret; + if (ret == 0) { + /* EOF means "short read" in random-access mode */ + *err = WTAP_ERR_SHORT_READ; + } + return -1; } i4b_byte_swap_header(wth, &hdr); @@ -246,7 +252,7 @@ i4btrace_seek_read(wtap *wth, long seek_off, /* * Read the packet data. */ - return i4b_read_rec_data(wth->random_fh, pd, length, &err); + return i4b_read_rec_data(wth->random_fh, pd, length, err); } static int diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c index 9b57bb098e..e53442e2a6 100644 --- a/wiretap/iptrace.c +++ b/wiretap/iptrace.c @@ -1,6 +1,6 @@ /* iptrace.c * - * $Id: iptrace.c,v 1.36 2001/11/13 23:55:43 gram Exp $ + * $Id: iptrace.c,v 1.37 2002/03/05 05:58:40 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -33,11 +33,13 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, long *data_offset); static int iptrace_seek_read_1_0(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size); + union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size, + int *err); static gboolean iptrace_read_2_0(wtap *wth, int *err, long *data_offset); static int iptrace_seek_read_2_0(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size); + union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size, + int *err); static int iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len, int *err); @@ -162,19 +164,26 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, long *data_offset) } static int iptrace_seek_read_1_0(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size) + union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size, + int *err) { int ret; - int err; /* XXX - return this */ guint8 header[30]; - file_seek(wth->random_fh, seek_off, SEEK_SET); + if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); + return -1; + } /* Read the descriptor data */ - ret = iptrace_read_rec_header(wth->random_fh, header, 30, &err); + ret = iptrace_read_rec_header(wth->random_fh, header, 30, err); if (ret <= 0) { /* Read error or EOF */ - return ret; + if (ret == 0) { + /* EOF means "short read" in random-access mode */ + *err = WTAP_ERR_SHORT_READ; + } + return -1; } if ( wtap_encap_ift(header[28]) == WTAP_ENCAP_ATM_SNIFFER ) { @@ -182,7 +191,7 @@ static int iptrace_seek_read_1_0(wtap *wth, long seek_off, } /* Read the packet data */ - return iptrace_read_rec_data(wth->random_fh, pd, packet_size, &err); + return iptrace_read_rec_data(wth->random_fh, pd, packet_size, err); } /*********************************************************** @@ -274,19 +283,26 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, long *data_offset) } static int iptrace_seek_read_2_0(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size) + union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size, + int *err) { int ret; - int err; /* XXX - return this */ guint8 header[40]; - file_seek(wth->random_fh, seek_off, SEEK_SET); + if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); + return -1; + } /* Read the descriptor data */ - ret = iptrace_read_rec_header(wth->random_fh, header, 40, &err); + ret = iptrace_read_rec_header(wth->random_fh, header, 40, err); if (ret <= 0) { /* Read error or EOF */ - return ret; + if (ret == 0) { + /* EOF means "short read" in random-access mode */ + *err = WTAP_ERR_SHORT_READ; + } + return -1; } if ( wtap_encap_ift(header[28]) == WTAP_ENCAP_ATM_SNIFFER ) { @@ -294,7 +310,7 @@ static int iptrace_seek_read_2_0(wtap *wth, long seek_off, } /* Read the packet data */ - return iptrace_read_rec_data(wth->random_fh, pd, packet_size, &err); + return iptrace_read_rec_data(wth->random_fh, pd, packet_size, err); } static int diff --git a/wiretap/netmon.c b/wiretap/netmon.c index c2e7a30aca..5c7188b7fe 100644 --- a/wiretap/netmon.c +++ b/wiretap/netmon.c @@ -1,6 +1,6 @@ /* netmon.c * - * $Id: netmon.c,v 1.49 2002/03/04 00:25:35 guy Exp $ + * $Id: netmon.c,v 1.50 2002/03/05 05:58:40 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -108,7 +108,7 @@ struct netmon_atm_hdr { static gboolean netmon_read(wtap *wth, int *err, long *data_offset); static int netmon_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int length); + union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err); static int netmon_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err); static int netmon_read_rec_data(FILE_T fh, u_char *pd, int length, int *err); @@ -447,16 +447,18 @@ static gboolean netmon_read(wtap *wth, int *err, long *data_offset) static int netmon_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int length) + union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err) { int ret; - int err; /* XXX - return this */ - file_seek(wth->random_fh, seek_off, SEEK_SET); + if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); + return -1; + } if (wth->file_encap == WTAP_ENCAP_ATM_SNIFFER) { ret = netmon_read_atm_pseudoheader(wth->random_fh, pseudo_header, - &err); + err); if (ret < 0) { /* Read error */ return ret; @@ -466,7 +468,7 @@ netmon_seek_read(wtap *wth, long seek_off, /* * Read the packet data. */ - return netmon_read_rec_data(wth->random_fh, pd, length, &err); + return netmon_read_rec_data(wth->random_fh, pd, length, err); } static int diff --git a/wiretap/nettl.c b/wiretap/nettl.c index 1c4a843363..d6c812e607 100644 --- a/wiretap/nettl.c +++ b/wiretap/nettl.c @@ -1,6 +1,6 @@ /* nettl.c * - * $Id: nettl.c,v 1.23 2002/03/04 00:25:35 guy Exp $ + * $Id: nettl.c,v 1.24 2002/03/05 05:58:40 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -68,7 +68,8 @@ struct nettlrec_ns_ls_ip_hdr { static gboolean nettl_read(wtap *wth, int *err, long *data_offset); static int nettl_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int length); + union wtap_pseudo_header *pseudo_header, u_char *pd, + int length, int *err); static int nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, union wtap_pseudo_header *pseudo_header, int *err); @@ -157,26 +158,33 @@ static gboolean nettl_read(wtap *wth, int *err, long *data_offset) static int nettl_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int length) + union wtap_pseudo_header *pseudo_header, u_char *pd, + int length, int *err) { int ret; - int err; /* XXX - return this */ struct wtap_pkthdr phdr; - file_seek(wth->random_fh, seek_off, SEEK_SET); + if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); + return -1; + } /* Read record header. */ ret = nettl_read_rec_header(wth, wth->random_fh, &phdr, pseudo_header, - &err); + err); if (ret <= 0) { /* Read error or EOF */ - return ret; + if (ret == 0) { + /* EOF means "short read" in random-access mode */ + *err = WTAP_ERR_SHORT_READ; + } + return -1; } /* * Read the packet data. */ - return nettl_read_rec_data(wth->random_fh, pd, length, &err); + return nettl_read_rec_data(wth->random_fh, pd, length, err); } static int diff --git a/wiretap/ngsniffer.c b/wiretap/ngsniffer.c index 099058ac60..c0d1d9e6a6 100644 --- a/wiretap/ngsniffer.c +++ b/wiretap/ngsniffer.c @@ -1,6 +1,6 @@ /* ngsniffer.c * - * $Id: ngsniffer.c,v 1.74 2002/03/04 00:25:35 guy Exp $ + * $Id: ngsniffer.c,v 1.75 2002/03/05 05:58:40 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -286,7 +286,8 @@ static double Usec[] = { 15.0, 0.838096, 15.0, 0.5, 2.0, 1.0, 0.1 }; static int skip_header_records(wtap *wth, int *err, gint16 version); static gboolean ngsniffer_read(wtap *wth, int *err, long *data_offset); static int ngsniffer_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size); + union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size, + int *err); static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random, guint16 *typep, guint16 *lengthp, int *err); static int ngsniffer_read_frame2(wtap *wth, gboolean is_random, @@ -872,28 +873,33 @@ found: } static int ngsniffer_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size) + union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size, + int *err) { int ret; - int err; /* XXX - return this */ guint16 type, length; struct frame2_rec frame2; struct frame4_rec frame4; struct frame6_rec frame6; - ng_file_seek_rand(wth, seek_off, SEEK_SET, &err); + if (ng_file_seek_rand(wth, seek_off, SEEK_SET, err) == -1) + return -1; - ret = ngsniffer_read_rec_header(wth, TRUE, &type, &length, &err); + ret = ngsniffer_read_rec_header(wth, TRUE, &type, &length, err); if (ret <= 0) { /* Read error or EOF */ - return ret; + if (ret == 0) { + /* EOF means "short read" in random-access mode */ + *err = WTAP_ERR_SHORT_READ; + } + return -1; } switch (type) { case REC_FRAME2: /* Read the f_frame2_struct */ - ret = ngsniffer_read_frame2(wth, TRUE, &frame2, &err); + ret = ngsniffer_read_frame2(wth, TRUE, &frame2, err); if (ret < 0) { /* Read error */ return ret; @@ -906,7 +912,7 @@ static int ngsniffer_seek_read(wtap *wth, long seek_off, case REC_FRAME4: /* Read the f_frame4_struct */ - ret = ngsniffer_read_frame4(wth, TRUE, &frame4, &err); + ret = ngsniffer_read_frame4(wth, TRUE, &frame4, err); length -= sizeof frame4; /* we already read that much */ @@ -915,7 +921,7 @@ static int ngsniffer_seek_read(wtap *wth, long seek_off, case REC_FRAME6: /* Read the f_frame6_struct */ - ret = ngsniffer_read_frame6(wth, TRUE, &frame6, &err); + ret = ngsniffer_read_frame6(wth, TRUE, &frame6, err); length -= sizeof frame6; /* we already read that much */ @@ -939,7 +945,7 @@ static int ngsniffer_seek_read(wtap *wth, long seek_off, /* * Got the pseudo-header (if any), now get the data. */ - return ngsniffer_read_rec_data(wth, TRUE, pd, packet_size, &err); + return ngsniffer_read_rec_data(wth, TRUE, pd, packet_size, err); } static int ngsniffer_read_rec_header(wtap *wth, gboolean is_random, diff --git a/wiretap/pppdump.c b/wiretap/pppdump.c index 950c4e4e02..0988e1ef8f 100644 --- a/wiretap/pppdump.c +++ b/wiretap/pppdump.c @@ -1,6 +1,6 @@ /* pppdump.c * - * $Id: pppdump.c,v 1.15 2002/03/04 00:25:35 guy Exp $ + * $Id: pppdump.c,v 1.16 2002/03/05 05:58:40 guy Exp $ * * Copyright (c) 2000 by Gilbert Ramirez * @@ -95,7 +95,7 @@ typedef enum { static gboolean pppdump_read(wtap *wth, int *err, long *data_offset); static int pppdump_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guint8 *pd, int len); + union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err); typedef struct { long offset; @@ -513,6 +513,7 @@ collate(pppdump_t* state, FILE_T fh, int *err, guint8 *pd, int *num_bytes, } + *err = file_error(fh); return FALSE; } @@ -524,9 +525,9 @@ pppdump_seek_read (wtap *wth, long seek_off, union wtap_pseudo_header *pseudo_header, guint8 *pd, - int len) + int len, + int *err) { - int err = 0; int num_bytes; direction_enum direction; gboolean retval; @@ -539,16 +540,20 @@ pppdump_seek_read (wtap *wth, pid = g_ptr_array_index(state->pids, seek_off); if (!pid) { + *err = WTAP_ERR_BAD_RECORD; /* XXX - better error? */ return -1; } - file_seek(wth->random_fh, pid->offset, SEEK_SET); + if (file_seek(wth->random_fh, pid->offset, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); + return -1; + } init_state(state->seek_state); for (i = 0 ; i <= pid->num_saved_states; i++) { again: - retval = collate(state->seek_state, wth->random_fh, &err, pd, &num_bytes, + retval = collate(state->seek_state, wth->random_fh, err, pd, &num_bytes, &direction, NULL); if (!retval) { @@ -561,6 +566,7 @@ pppdump_seek_read (wtap *wth, } if (len != num_bytes) { + *err = WTAP_ERR_BAD_RECORD; /* XXX - better error? */ return -1; } diff --git a/wiretap/radcom.c b/wiretap/radcom.c index 3bf9adf2f4..610d934e38 100644 --- a/wiretap/radcom.c +++ b/wiretap/radcom.c @@ -1,6 +1,6 @@ /* radcom.c * - * $Id: radcom.c,v 1.33 2002/03/04 00:25:35 guy Exp $ + * $Id: radcom.c,v 1.34 2002/03/05 05:58:40 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -69,7 +69,8 @@ struct radcomrec_hdr { static gboolean radcom_read(wtap *wth, int *err, long *data_offset); static int radcom_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int length); + union wtap_pseudo_header *pseudo_header, u_char *pd, int length, + int *err); static int radcom_read_rec_header(FILE_T fh, struct radcomrec_hdr *hdr, int *err); static int radcom_read_rec_data(FILE_T fh, u_char *pd, int length, int *err); @@ -309,19 +310,25 @@ static gboolean radcom_read(wtap *wth, int *err, long *data_offset) static int radcom_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int length) + union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err) { int ret; - int err; /* XXX - return this */ struct radcomrec_hdr hdr; - file_seek(wth->random_fh, seek_off, SEEK_SET); + if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); + return -1; + } /* Read record header. */ - ret = radcom_read_rec_header(wth->random_fh, &hdr, &err); + ret = radcom_read_rec_header(wth->random_fh, &hdr, err); if (ret <= 0) { /* Read error or EOF */ - return ret; + if (ret == 0) { + /* EOF means "short read" in random-access mode */ + *err = WTAP_ERR_SHORT_READ; + } + return -1; } pseudo_header->x25.flags = (hdr.dce & 0x1) ? 0x00 : 0x80; @@ -329,7 +336,7 @@ radcom_seek_read(wtap *wth, long seek_off, /* * Read the packet data. */ - return radcom_read_rec_data(wth->random_fh, pd, length, &err); + return radcom_read_rec_data(wth->random_fh, pd, length, err); } static int diff --git a/wiretap/snoop.c b/wiretap/snoop.c index 124ef543f9..62713f3628 100644 --- a/wiretap/snoop.c +++ b/wiretap/snoop.c @@ -1,6 +1,6 @@ /* snoop.c * - * $Id: snoop.c,v 1.42 2002/03/02 20:41:07 guy Exp $ + * $Id: snoop.c,v 1.43 2002/03/05 05:58:40 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -58,7 +58,7 @@ struct snooprec_hdr { static gboolean snoop_read(wtap *wth, int *err, long *data_offset); static int snoop_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int length); + union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err); static int snoop_read_atm_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err); static int snoop_read_rec_data(FILE_T fh, u_char *pd, int length, int *err); @@ -404,16 +404,18 @@ static gboolean snoop_read(wtap *wth, int *err, long *data_offset) static int snoop_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int length) + union wtap_pseudo_header *pseudo_header, u_char *pd, int length, int *err) { int ret; - int err; /* XXX - return this */ - file_seek(wth->random_fh, seek_off, SEEK_SET); + if (file_seek(wth->random_fh, seek_off, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); + return -1; + } if (wth->file_encap == WTAP_ENCAP_ATM_SNIFFER) { ret = snoop_read_atm_pseudoheader(wth->random_fh, pseudo_header, - &err); + err); if (ret < 0) { /* Read error */ return ret; @@ -423,7 +425,7 @@ snoop_seek_read(wtap *wth, long seek_off, /* * Read the packet data. */ - return snoop_read_rec_data(wth->random_fh, pd, length, &err); + return snoop_read_rec_data(wth->random_fh, pd, length, err); } static int diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c index a644f5e566..c356959286 100644 --- a/wiretap/toshiba.c +++ b/wiretap/toshiba.c @@ -1,6 +1,6 @@ /* toshiba.c * - * $Id: toshiba.c,v 1.21 2002/03/04 00:25:35 guy Exp $ + * $Id: toshiba.c,v 1.22 2002/03/05 05:58:41 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -111,7 +111,7 @@ static const char toshiba_rec_magic[] = { '[', 'N', 'o', '.' }; static gboolean toshiba_read(wtap *wth, int *err, long *data_offset); static int toshiba_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guint8 *pd, int len); + union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err); static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset); static int parse_toshiba_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err); static int parse_toshiba_rec_hdr(wtap *wth, FILE_T fh, @@ -239,15 +239,17 @@ static gboolean toshiba_read(wtap *wth, int *err, long *data_offset) return FALSE; /* Parse the header */ - pkt_len = parse_toshiba_rec_hdr(wth, wth->fh, - &wth->pseudo_header, err); + pkt_len = parse_toshiba_rec_hdr(wth, wth->fh, &wth->pseudo_header, err); + if (pkt_len == -1) + return FALSE; /* Make sure we have enough room for the packet */ buffer_assure_space(wth->frame_buffer, TOSHIBA_MAX_PACKET_LEN); buf = buffer_start_ptr(wth->frame_buffer); /* Convert the ASCII hex dump to binary data */ - parse_toshiba_hex_dump(wth->fh, pkt_len, buf, err); + if (parse_toshiba_hex_dump(wth->fh, pkt_len, buf, err) == -1) + return FALSE; wth->data_offset = offset; *data_offset = offset; @@ -257,21 +259,26 @@ static gboolean toshiba_read(wtap *wth, int *err, long *data_offset) /* Used to read packets in random-access fashion */ static int toshiba_seek_read (wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guint8 *pd, int len) + union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err) { int pkt_len; - int err; - file_seek(wth->random_fh, seek_off - 1, SEEK_SET); - - pkt_len = parse_toshiba_rec_hdr(NULL, wth->random_fh, pseudo_header, - &err); - - if (pkt_len != len) { + if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); return -1; } - parse_toshiba_hex_dump(wth->random_fh, pkt_len, pd, &err); + pkt_len = parse_toshiba_rec_hdr(NULL, wth->random_fh, pseudo_header, + err); + + if (pkt_len != len) { + if (pkt_len != -1) + *err = WTAP_ERR_BAD_RECORD; + return -1; + } + + if (parse_toshiba_hex_dump(wth->random_fh, pkt_len, pd, err) == -1) + return -1; return 0; } diff --git a/wiretap/visual.c b/wiretap/visual.c index 2a75c93ce6..dcb11910dd 100644 --- a/wiretap/visual.c +++ b/wiretap/visual.c @@ -2,7 +2,7 @@ * File read and write routines for Visual Networks cap files. * Copyright (c) 2001, Tom Nisbet tnisbet@visualnetworks.com * - * $Id: visual.c,v 1.3 2002/03/04 00:25:35 guy Exp $ + * $Id: visual.c,v 1.4 2002/03/05 05:58:41 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -115,7 +115,8 @@ struct visual_write_info static gboolean visual_read(wtap *wth, int *err, long *data_offset); static void visual_close(wtap *wth); static int visual_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size); + union wtap_pseudo_header *pseudo_header, u_char *pd, int packet_size, + int *err); static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const union wtap_pseudo_header *pseudo_header, const u_char *pd, int *err); static gboolean visual_dump_close(wtap_dumper *wdh, int *err); @@ -328,7 +329,7 @@ static void visual_close(wtap *wth) This gets the packet data and rebuilds the pseudo header so that the direction flag works. */ static int visual_seek_read (wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guint8 *pd, int len) + union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err) { struct visual_pkt_hdr vpkt_hdr; int phdr_size = sizeof(vpkt_hdr); @@ -336,19 +337,30 @@ static int visual_seek_read (wtap *wth, long seek_off, int bytes_read; /* Seek to the packet header */ - file_seek(wth->random_fh, seek_off - sizeof(struct visual_pkt_hdr), SEEK_SET); + if (file_seek(wth->random_fh, seek_off - sizeof(struct visual_pkt_hdr), + SEEK_SET) == -1) { + *err = file_error(wth->random_fh); + return -1; + } /* Read the packet header to get the status flags. */ errno = WTAP_ERR_CANT_READ; bytes_read = file_read(&vpkt_hdr, 1, phdr_size, wth->random_fh); - if (bytes_read != phdr_size) + if (bytes_read != phdr_size) { + *err = file_error(wth->random_fh); + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; return -1; + } /* Read the packet data. */ errno = WTAP_ERR_CANT_READ; bytes_read = file_read(pd, sizeof(guint8), len, wth->random_fh); - if (bytes_read != len) + if (bytes_read != len) { + if (*err == 0) + *err = WTAP_ERR_SHORT_READ; return -1; + } /* Set status flags. The only status currently supported for all encapsulations is direction. This either goes in the p2p or the diff --git a/wiretap/vms.c b/wiretap/vms.c index 19af1bfbc1..9b0da71330 100644 --- a/wiretap/vms.c +++ b/wiretap/vms.c @@ -1,6 +1,6 @@ /* vms.c * - * $Id: vms.c,v 1.8 2002/03/04 00:25:35 guy Exp $ + * $Id: vms.c,v 1.9 2002/03/05 05:58:41 guy Exp $ * * Wiretap Library * Copyright (c) 2001 by Marc Milgram @@ -73,7 +73,7 @@ static const char vms_hdr_magic[] = static gboolean vms_read(wtap *wth, int *err, long *data_offset); static int vms_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guint8 *pd, int len); + union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err); static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf, long byte_offset, int in_off, int remaining_bytes); static int parse_vms_hex_dump(FILE_T fh, int pkt_len, guint8* buf, int *err); static int parse_vms_rec_hdr(wtap *wth, FILE_T fh, int *err); @@ -219,7 +219,6 @@ static gboolean vms_read(wtap *wth, int *err, long *data_offset) /* Parse the header */ pkt_len = parse_vms_rec_hdr(wth, wth->fh, err); - if (pkt_len == -1) return FALSE; @@ -228,7 +227,8 @@ static gboolean vms_read(wtap *wth, int *err, long *data_offset) buf = buffer_start_ptr(wth->frame_buffer); /* Convert the ASCII hex dump to binary data */ - parse_vms_hex_dump(wth->fh, pkt_len, buf, err); + if (parse_vms_hex_dump(wth->fh, pkt_len, buf, err) == -1) + return FALSE; wth->data_offset = offset; *data_offset = offset; @@ -239,20 +239,25 @@ static gboolean vms_read(wtap *wth, int *err, long *data_offset) static int vms_seek_read (wtap *wth, long seek_off, union wtap_pseudo_header *pseudo_header _U_, - guint8 *pd, int len) + guint8 *pd, int len, int *err) { int pkt_len; - int err; - file_seek(wth->random_fh, seek_off - 1, SEEK_SET); - - pkt_len = parse_vms_rec_hdr(NULL, wth->random_fh, &err); - - if (pkt_len != len) { + if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET) == -1) { + *err = file_error(wth->random_fh); return -1; } - parse_vms_hex_dump(wth->random_fh, pkt_len, pd, &err); + pkt_len = parse_vms_rec_hdr(NULL, wth->random_fh, err); + + if (pkt_len != len) { + if (pkt_len != -1) + *err = WTAP_ERR_BAD_RECORD; + return -1; + } + + if (parse_vms_hex_dump(wth->random_fh, pkt_len, pd, err) == -1) + return -1; return 0; } diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h index 299f232ed7..965b59fc32 100644 --- a/wiretap/wtap-int.h +++ b/wiretap/wtap-int.h @@ -1,6 +1,6 @@ /* wtap-int.h * - * $Id: wtap-int.h,v 1.20 2002/01/18 01:08:36 guy Exp $ + * $Id: wtap-int.h,v 1.21 2002/03/05 05:58:41 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -18,7 +18,6 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * */ #ifndef __WTAP_INT_H__ @@ -122,7 +121,7 @@ typedef struct { typedef int (*subtype_read_func)(struct wtap*, int*, long*); typedef int (*subtype_seek_read_func)(struct wtap*, long, union wtap_pseudo_header*, - guint8*, int); + guint8*, int, int *); struct wtap { FILE_T fh; int fd; /* File descriptor for cap file */ diff --git a/wiretap/wtap.c b/wiretap/wtap.c index b9ba2e1558..2bc0191f99 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -1,6 +1,6 @@ /* wtap.c * - * $Id: wtap.c,v 1.61 2002/02/07 20:41:28 guy Exp $ + * $Id: wtap.c,v 1.62 2002/03/05 05:58:41 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -18,8 +18,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * */ + #include #include @@ -312,7 +312,9 @@ wtap_loop(wtap *wth, int count, wtap_handler callback, u_char* user, int *err) int wtap_seek_read(wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guint8 *pd, int len) + union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, + int *err) { - return wth->subtype_seek_read(wth, seek_off, pseudo_header, pd, len); + return wth->subtype_seek_read(wth, seek_off, pseudo_header, pd, len, + err); } diff --git a/wiretap/wtap.h b/wiretap/wtap.h index dfc2f779d7..07881a7180 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1,6 +1,6 @@ /* wtap.h * - * $Id: wtap.h,v 1.105 2002/02/07 20:41:28 guy Exp $ + * $Id: wtap.h,v 1.106 2002/03/05 05:58:41 guy Exp $ * * Wiretap Library * Copyright (c) 1998 by Gilbert Ramirez @@ -342,9 +342,9 @@ const char *wtap_strerror(int err); void wtap_sequential_close(wtap *wth); void wtap_close(wtap *wth); int wtap_seek_read (wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guint8 *pd, int len); + union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err); int wtap_def_seek_read (wtap *wth, long seek_off, - union wtap_pseudo_header *pseudo_header, guint8 *pd, int len); + union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err); gboolean wtap_dump_can_open(int filetype); gboolean wtap_dump_can_write_encap(int filetype, int encap);