"wtap_read()" must *always* set "*err" when it returns FALSE - if it's

just an EOF, it should set "*err" to 0.  Fix up a bunch of read routines
for various capture file types to set "*err" appropriately.

svn path=/trunk/; revision=2667
This commit is contained in:
Guy Harris 2000-11-19 03:47:36 +00:00
parent ea9409cb04
commit 4933cc340f
8 changed files with 25 additions and 11 deletions

View File

@ -1,6 +1,6 @@
/* ascend.c
*
* $Id: ascend.c,v 1.21 2000/11/12 08:45:28 guy Exp $
* $Id: ascend.c,v 1.22 2000/11/19 03:47:35 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@ -257,6 +257,7 @@ static gboolean ascend_read(wtap *wth, int *err, int *data_offset)
file_seek(wth->fh, wth->capture.ascend->next_packet_seek_start, SEEK_SET);
offset = ascend_seek(wth, ASCEND_MAX_SEEK);
if (offset == -1) {
*err = 0; /* XXX - assume, for now, that it's an EOF */
return FALSE;
}
if (! parse_ascend(wth->fh, buf, &wth->pseudo_header.ascend, &header, 0)) {

View File

@ -1,6 +1,6 @@
/* csids.c
*
* $Id: csids.c,v 1.4 2000/09/07 05:34:07 gram Exp $
* $Id: csids.c,v 1.5 2000/11/19 03:47:35 guy Exp $
*
* Copyright (c) 2000 by Mike Hall <mlh@io.com>
* Copyright (c) 2000 by Cisco Systems
@ -151,6 +151,8 @@ static gboolean csids_read(wtap *wth, int *err, int *data_offset)
bytesRead = file_read( &hdr, 1, sizeof( struct csids_header) , wth->fh );
if( bytesRead != sizeof( struct csids_header) ) {
*err = file_error( wth->fh );
if (*err == 0 && bytesRead != 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
hdr.seconds = pntohl(&hdr.seconds);
@ -165,6 +167,8 @@ static gboolean csids_read(wtap *wth, int *err, int *data_offset)
bytesRead = file_read( buf, 1, hdr.caplen, wth->fh );
if( bytesRead != hdr.caplen ) {
*err = file_error( wth->fh );
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}

View File

@ -1,6 +1,6 @@
/* i4btrace.c
*
* $Id: i4btrace.c,v 1.12 2000/11/17 21:00:40 gram Exp $
* $Id: i4btrace.c,v 1.13 2000/11/19 03:47:35 guy Exp $
*
* Wiretap Library
* Copyright (c) 1999 by Bert Driehuis <driehuis@playbeing.org>
@ -130,9 +130,11 @@ static gboolean i4btrace_read(wtap *wth, int *err, int *data_offset)
}
wth->data_offset += sizeof hdr;
i4b_byte_swap_header(wth, &hdr);
length = hdr.length - sizeof(hdr);
if (length == 0)
if (hdr.length < sizeof(hdr)) {
*err = WTAP_ERR_BAD_RECORD; /* record length < header! */
return FALSE;
}
length = hdr.length - sizeof(hdr);
wth->phdr.len = length;
wth->phdr.caplen = length;

View File

@ -1,6 +1,6 @@
/* netmon.c
*
* $Id: netmon.c,v 1.34 2000/09/21 04:41:32 gram Exp $
* $Id: netmon.c,v 1.35 2000/11/19 03:47:35 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@ -298,7 +298,8 @@ static gboolean netmon_read(wtap *wth, int *err, int *data_offset)
free it. */
g_free(wth->capture.netmon->frame_table);
wth->capture.netmon->frame_table = NULL;
return 0;
*err = 0; /* it's just an EOF, not an error */
return FALSE;
}
/* Seek to the beginning of the current record, if we're

View File

@ -1,6 +1,6 @@
/* netxray.c
*
* $Id: netxray.c,v 1.33 2000/09/23 05:58:26 guy Exp $
* $Id: netxray.c,v 1.34 2000/11/19 03:47:35 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@ -234,6 +234,7 @@ reread:
/* Have we reached the end of the packet data? */
if (wth->data_offset == wth->capture.netxray->end_offset) {
/* Yes. */
*err = 0; /* it's just an EOF, not an error */
return FALSE;
}
/* Read record header. */

View File

@ -1,6 +1,6 @@
/* ngsniffer.c
*
* $Id: ngsniffer.c,v 1.54 2000/11/11 06:36:09 guy Exp $
* $Id: ngsniffer.c,v 1.55 2000/11/19 03:47:36 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@ -687,6 +687,7 @@ static gboolean ngsniffer_read(wtap *wth, int *err, int *data_offset)
/*
* End of file. Return an EOF indication.
*/
*err = 0; /* EOF, not error */
return FALSE;
default:

View File

@ -1,6 +1,6 @@
/* pppdump.c
*
* $Id: pppdump.c,v 1.4 2000/11/17 21:00:40 gram Exp $
* $Id: pppdump.c,v 1.5 2000/11/19 03:47:36 guy Exp $
*
* Copyright (c) 2000 by Gilbert Ramirez <gram@xiexie.org>
*
@ -30,6 +30,7 @@
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
/*
@ -232,6 +233,7 @@ pppdump_read(wtap *wth, int *err, int *data_offset)
state = wth->capture.generic;
pid = g_new(pkt_id, 1);
if (!pid) {
*err = errno; /* assume a malloc failed and set "errno" */
return FALSE;
}
pid->offset = 0;
@ -337,6 +339,7 @@ process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd, int *er
num_bytes--;
if (num_bytes > 0) {
if (!save_prec_state(state, num_bytes, pkt)) {
*err = errno;
return -1;
}
*state_saved = TRUE;

View File

@ -1,6 +1,6 @@
/* toshiba.c
*
* $Id: toshiba.c,v 1.13 2000/09/21 04:41:37 gram Exp $
* $Id: toshiba.c,v 1.14 2000/11/19 03:47:36 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@ -209,6 +209,7 @@ static gboolean toshiba_read(wtap *wth, int *err, int *data_offset)
/* Find the next packet */
offset = toshiba_seek_next_packet(wth);
if (offset < 1) {
*err = 0; /* XXX - assume, for now, that it's an EOF */
return FALSE;
}