forked from osmocom/wireshark
When we get an EOF, only return WTAP_ERR_SHORT_READ as the error if we
were in the middle of processing a record. If we got one at the *beginning* of the record, that just means we've come to a clean end-of-file. svn path=/trunk/; revision=13064
This commit is contained in:
parent
d1ae7c688f
commit
714ca234a6
|
@ -88,8 +88,9 @@ Daniel Thompson (STMicroelectronics) <daniel.thompson@st.com>
|
||||||
#define PPPD_TIME_STEP_SHORT 0x06
|
#define PPPD_TIME_STEP_SHORT 0x06
|
||||||
#define PPPD_RESET_TIME 0x07
|
#define PPPD_RESET_TIME 0x07
|
||||||
|
|
||||||
/* this buffer must be at least (2*PPPD_MTU) + sizeof(ppp_header) + sizeof(lcp_header) +
|
/* this buffer must be at least (2*PPPD_MTU) + sizeof(ppp_header) +
|
||||||
* sizeof(ipcp_header). PPPD_MTU is *very* rarely larger than 1500 so this value is fine
|
* sizeof(lcp_header) + sizeof(ipcp_header). PPPD_MTU is *very* rarely
|
||||||
|
* larger than 1500 so this value is fine.
|
||||||
*/
|
*/
|
||||||
#define PPPD_BUF_SIZE 8192
|
#define PPPD_BUF_SIZE 8192
|
||||||
|
|
||||||
|
@ -365,8 +366,8 @@ pppdump_read(wtap *wth, int *err, gchar **err_info, long *data_offset)
|
||||||
|
|
||||||
/* Returns number of bytes copied for record, -1 if failure.
|
/* Returns number of bytes copied for record, -1 if failure.
|
||||||
*
|
*
|
||||||
* This is modeled after pppdump.c, the utility to parse pppd log files; it comes with the ppp
|
* This is modeled after pppdump.c, the utility to parse pppd log files; it
|
||||||
* distribution.
|
* comes with the ppp distribution.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd,
|
process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd,
|
||||||
|
@ -378,16 +379,15 @@ process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd,
|
||||||
|
|
||||||
for (; num_bytes > 0; --num_bytes) {
|
for (; num_bytes > 0; --num_bytes) {
|
||||||
c = file_getc(fh);
|
c = file_getc(fh);
|
||||||
|
if (c == EOF) {
|
||||||
|
*err = file_error(fh);
|
||||||
|
if (*err == 0) {
|
||||||
|
*err = WTAP_ERR_SHORT_READ;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
state->offset++;
|
state->offset++;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case EOF:
|
|
||||||
*err = file_error(fh);
|
|
||||||
if (*err == 0) {
|
|
||||||
*err = WTAP_ERR_SHORT_READ;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0x7e:
|
case 0x7e:
|
||||||
/*
|
/*
|
||||||
* Flag Sequence for RFC 1662 HDLC-like
|
* Flag Sequence for RFC 1662 HDLC-like
|
||||||
|
@ -534,6 +534,7 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
|
||||||
pkt_t *pkt = NULL;
|
pkt_t *pkt = NULL;
|
||||||
int byte0, byte1;
|
int byte0, byte1;
|
||||||
int n, num_written = 0;
|
int n, num_written = 0;
|
||||||
|
long start_offset;
|
||||||
guint32 time_long;
|
guint32 time_long;
|
||||||
guint8 time_short;
|
guint8 time_short;
|
||||||
|
|
||||||
|
@ -569,6 +570,7 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
|
||||||
* That didn't get all the data for this packet, so process
|
* That didn't get all the data for this packet, so process
|
||||||
* subsequent records.
|
* subsequent records.
|
||||||
*/
|
*/
|
||||||
|
start_offset = state->offset;
|
||||||
while ((id = file_getc(fh)) != EOF) {
|
while ((id = file_getc(fh)) != EOF) {
|
||||||
state->offset++;
|
state->offset++;
|
||||||
switch (id) {
|
switch (id) {
|
||||||
|
@ -586,21 +588,14 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
|
||||||
* Get the length of the record.
|
* Get the length of the record.
|
||||||
*/
|
*/
|
||||||
byte0 = file_getc(fh);
|
byte0 = file_getc(fh);
|
||||||
if (byte0 == EOF) {
|
if (byte0 == EOF)
|
||||||
*err = file_error(fh);
|
goto done;
|
||||||
if (*err == 0)
|
state->offset++;
|
||||||
*err = WTAP_ERR_SHORT_READ;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
byte1 = file_getc(fh);
|
byte1 = file_getc(fh);
|
||||||
if (byte1 == EOF) {
|
if (byte1 == EOF)
|
||||||
*err = file_error(fh);
|
goto done;
|
||||||
if (*err == 0)
|
state->offset++;
|
||||||
*err = WTAP_ERR_SHORT_READ;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
n = (byte0 << 8) | byte1;
|
n = (byte0 << 8) | byte1;
|
||||||
state->offset += 2;
|
|
||||||
|
|
||||||
if (pkt->id_offset == 0) {
|
if (pkt->id_offset == 0) {
|
||||||
/*
|
/*
|
||||||
|
@ -621,12 +616,8 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
|
||||||
|
|
||||||
g_assert(num_bytes_to_skip < n);
|
g_assert(num_bytes_to_skip < n);
|
||||||
while (num_bytes_to_skip) {
|
while (num_bytes_to_skip) {
|
||||||
if (file_getc(fh) == EOF) {
|
if (file_getc(fh) == EOF)
|
||||||
*err = file_error(fh);
|
goto done;
|
||||||
if (*err == 0)
|
|
||||||
*err = WTAP_ERR_SHORT_READ;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
state->offset++;
|
state->offset++;
|
||||||
num_bytes_to_skip--;
|
num_bytes_to_skip--;
|
||||||
n--;
|
n--;
|
||||||
|
@ -643,7 +634,6 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
/* if 0 bytes written, keep looping */
|
/* if 0 bytes written, keep looping */
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PPPD_SEND_DELIM:
|
case PPPD_SEND_DELIM:
|
||||||
|
@ -691,9 +681,18 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
*err = file_error(fh);
|
*err = file_error(fh);
|
||||||
if (*err == 0)
|
if (*err == 0) {
|
||||||
*err = WTAP_ERR_SHORT_READ;
|
if (state->offset != start_offset) {
|
||||||
|
/*
|
||||||
|
* We read at least one byte, so we were working
|
||||||
|
* on a record; an EOF means that record was
|
||||||
|
* cut short.
|
||||||
|
*/
|
||||||
|
*err = WTAP_ERR_SHORT_READ;
|
||||||
|
}
|
||||||
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue