Check for errors from all calls to "file_getc()".

If we get such an error, always call "file_error()" to get an indication
of what the error was and, if it returns 0, set the error to
WTAP_ERR_SHORT_READ.


git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@12442 f5534014-38df-0310-8fa8-9805f1628bb7
This commit is contained in:
guy 2004-10-30 09:14:36 +00:00
parent df503cc727
commit a31638b0b4
1 changed files with 25 additions and 3 deletions

View File

@ -381,6 +381,7 @@ process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd,
state->offset++;
switch (c) {
case EOF:
*err = file_error(fh);
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
@ -531,6 +532,7 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
{
int id;
pkt_t *pkt = NULL;
int byte0, byte1;
int n, num_written = 0;
guint32 time_long;
guint8 time_short;
@ -583,8 +585,21 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
/*
* Get the length of the record.
*/
n = file_getc(fh);
n = (n << 8) + file_getc(fh);
byte0 = file_getc(fh);
if (byte0 == EOF) {
*err = file_error(fh);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
byte1 = file_getc(fh);
if (byte1 == EOF) {
*err = file_error(fh);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
n = (byte0 << 8) | byte1;
state->offset += 2;
if (pkt->id_offset == 0) {
@ -606,7 +621,12 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
g_assert(num_bytes_to_skip < n);
while (num_bytes_to_skip) {
file_getc(fh);
if (file_getc(fh) == EOF) {
*err = file_error(fh);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
state->offset++;
num_bytes_to_skip--;
n--;
@ -672,6 +692,8 @@ collate(pppdump_t* state, FILE_T fh, int *err, gchar **err_info, guint8 *pd,
}
*err = file_error(fh);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}