file_read() can return -1; don't just blindly add it to a previous
file_read() return value. Use wtap_file_read_expected_bytes() in a number of places. svn path=/trunk/; revision=37053
This commit is contained in:
parent
025f9ee4db
commit
2ca5312b64
|
@ -243,26 +243,24 @@ static gboolean
|
|||
commview_read_header(commview_header_t *cv_hdr, FILE_T fh, int *err,
|
||||
gchar **err_info)
|
||||
{
|
||||
int bytes_read = 0;
|
||||
|
||||
bytes_read += file_read(&cv_hdr->data_len, 2, fh);
|
||||
bytes_read += file_read(&cv_hdr->source_data_len, 2, fh);
|
||||
bytes_read += file_read(&cv_hdr->version, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->year, 2, fh);
|
||||
bytes_read += file_read(&cv_hdr->month, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->day, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->hours, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->minutes, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->seconds, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->usecs, 4, fh);
|
||||
bytes_read += file_read(&cv_hdr->flags, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->signal_level_percent, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->rate, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->band, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->channel, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->direction, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->signal_level_dbm, 1, fh);
|
||||
bytes_read += file_read(&cv_hdr->noise_level, 1, fh);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->data_len, 2, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->source_data_len, 2, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->version, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->year, 2, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->month, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->day, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->hours, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->minutes, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->seconds, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->usecs, 4, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->flags, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->signal_level_percent, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->rate, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->band, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->channel, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->direction, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->signal_level_dbm, 1, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&cv_hdr->noise_level, 1, fh, err, err_info);
|
||||
|
||||
/* Convert multi-byte values from little endian to host endian format */
|
||||
cv_hdr->data_len = GUINT16_FROM_LE(cv_hdr->data_len);
|
||||
|
@ -270,14 +268,6 @@ commview_read_header(commview_header_t *cv_hdr, FILE_T fh, int *err,
|
|||
cv_hdr->year = GUINT16_FROM_LE(cv_hdr->year);
|
||||
cv_hdr->usecs = GUINT32_FROM_LE(cv_hdr->usecs);
|
||||
|
||||
if(bytes_read < COMMVIEW_HEADER_SIZE) {
|
||||
*err = file_error(fh, err_info);
|
||||
if(*err == 0 && bytes_read > 0)
|
||||
*err = WTAP_ERR_SHORT_READ;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -143,14 +143,21 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
|
|||
|
||||
errno = WTAP_ERR_CANT_READ;
|
||||
bytes_read = file_read(LE_record_type, 2, wth->fh);
|
||||
bytes_read += file_read(LE_record_length, 2, wth->fh);
|
||||
if (bytes_read != 4) {
|
||||
if (bytes_read != 2) {
|
||||
*err = file_error(wth->fh, err_info);
|
||||
if (*err != 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
wth->data_offset += 4;
|
||||
wth->data_offset += 2;
|
||||
bytes_read = file_read(LE_record_length, 2, wth->fh);
|
||||
if (bytes_read != 2) {
|
||||
*err = file_error(wth->fh, err_info);
|
||||
if (*err != 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
wth->data_offset += 2;
|
||||
record_type = pletohs(LE_record_type);
|
||||
record_length = pletohs(LE_record_length); /* make sure to do this for while() loop */
|
||||
|
||||
|
@ -178,8 +185,7 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
|
|||
wth->data_offset += record_length;
|
||||
errno = WTAP_ERR_CANT_READ;
|
||||
bytes_read = file_read(LE_record_type, 2, wth->fh);
|
||||
bytes_read += file_read(LE_record_length, 2, wth->fh);
|
||||
if (bytes_read != 4) {
|
||||
if (bytes_read != 2) {
|
||||
*err = file_error(wth->fh, err_info);
|
||||
if (*err != 0) {
|
||||
g_free(wth->priv);
|
||||
|
@ -188,7 +194,18 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
|
|||
g_free(wth->priv);
|
||||
return 0;
|
||||
}
|
||||
wth->data_offset += 4;
|
||||
wth->data_offset += 2;
|
||||
bytes_read = file_read(LE_record_length, 2, wth->fh);
|
||||
if (bytes_read != 2) {
|
||||
*err = file_error(wth->fh, err_info);
|
||||
if (*err != 0) {
|
||||
g_free(wth->priv);
|
||||
return -1;
|
||||
}
|
||||
g_free(wth->priv);
|
||||
return 0;
|
||||
}
|
||||
wth->data_offset += 2;
|
||||
|
||||
record_type = pletohs(LE_record_type);
|
||||
record_length = pletohs(LE_record_length);
|
||||
|
|
|
@ -579,14 +579,21 @@ ngsniffer_open(wtap *wth, int *err, gchar **err_info)
|
|||
*/
|
||||
errno = WTAP_ERR_CANT_READ;
|
||||
bytes_read = file_read(record_type, 2, wth->fh);
|
||||
bytes_read += file_read(record_length, 4, wth->fh);
|
||||
if (bytes_read != 6) {
|
||||
if (bytes_read != 2) {
|
||||
*err = file_error(wth->fh, err_info);
|
||||
if (*err != 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
wth->data_offset += 6;
|
||||
wth->data_offset += 2;
|
||||
bytes_read = file_read(record_length, 4, wth->fh);
|
||||
if (bytes_read != 4) {
|
||||
*err = file_error(wth->fh, err_info);
|
||||
if (*err != 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
wth->data_offset += 4;
|
||||
|
||||
type = pletohs(record_type);
|
||||
|
||||
|
|
|
@ -48,8 +48,6 @@ typedef struct packetlogger_header {
|
|||
guint64 ts;
|
||||
} packetlogger_header_t;
|
||||
|
||||
#define PACKETLOGGER_HEADER_SIZE 12
|
||||
|
||||
static gboolean packetlogger_read(wtap *wth, int *err, gchar **err_info,
|
||||
gint64 *data_offset);
|
||||
static gboolean packetlogger_seek_read(wtap *wth, gint64 seek_off,
|
||||
|
@ -172,22 +170,12 @@ static gboolean
|
|||
packetlogger_read_header(packetlogger_header_t *pl_hdr, FILE_T fh, int *err,
|
||||
gchar **err_info)
|
||||
{
|
||||
guint bytes_read = 0;
|
||||
|
||||
bytes_read += file_read(&pl_hdr->len, 4, fh);
|
||||
bytes_read += file_read(&pl_hdr->ts, 8, fh);
|
||||
wtap_file_read_expected_bytes(&pl_hdr->len, 4, fh, err, err_info);
|
||||
wtap_file_read_expected_bytes(&pl_hdr->ts, 8, fh, err, err_info);
|
||||
|
||||
/* Convert multi-byte values from big endian to host endian */
|
||||
pl_hdr->len = GUINT32_FROM_BE(pl_hdr->len);
|
||||
pl_hdr->ts = GUINT64_FROM_BE(pl_hdr->ts);
|
||||
|
||||
if(bytes_read < PACKETLOGGER_HEADER_SIZE) {
|
||||
*err = file_error(fh, err_info);
|
||||
if(*err == 0 && bytes_read > 0)
|
||||
*err = WTAP_ERR_SHORT_READ;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue