diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-09-22 18:13:59 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-09-23 01:14:30 +0000 |
commit | e543818734975e70d88752bdc898c30c09e48950 (patch) | |
tree | 7dd8e9c2a8310aff9817b3c463347bcf86a7a989 | |
parent | 6ebffcc5fa805a25f22e29ccdb7ca4fbece2e2d9 (diff) |
Remove misuse of wtap_file_read_expected_bytes().
wtap_file_read_expected_bytes() is a macro that can return a Boolean
FALSE; it should not be used in routines that don't return a Boolean.
In addition, both EOF *and* a short read, in that routine, should be
treated as a "not an IPFIX file" indication.
While we're at it, a seek failure should be treated as an error.
Change-Id: I97815bc9e78169ded567b60835cc7bcf6a0e6f0c
Reviewed-on: https://code.wireshark.org/review/4261
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | wiretap/ipfix.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/wiretap/ipfix.c b/wiretap/ipfix.c index 8229255cb2..70b700d092 100644 --- a/wiretap/ipfix.c +++ b/wiretap/ipfix.c @@ -242,7 +242,20 @@ ipfix_open(wtap *wth, int *err, gchar **err_info) /* check each Set in IPFIX Message for sanity */ while (checked_len < msg_hdr.message_length) { - wtap_file_read_expected_bytes(&set_hdr, IPFIX_SET_HDR_SIZE, wth->fh, err, err_info); + int bytes_read; + + bytes_read = file_read(&set_hdr, IPFIX_SET_HDR_SIZE, wth->fh); + if (bytes_read != IPFIX_SET_HDR_SIZE) { + *err = file_error(wth->fh, err_info); + if (*err == 0 || *err == WTAP_ERR_SHORT_READ) { + /* Not a valid IPFIX Set, so not an IPFIX file. */ + ipfix_debug1("ipfix_open: error %d reading set", *err); + return 0; + } + + /* A real I/O error; fail. */ + return -1; + } set_hdr.set_length = g_ntohs(set_hdr.set_length); if ((set_hdr.set_length < IPFIX_SET_HDR_SIZE) || ((set_hdr.set_length + checked_len) > msg_hdr.message_length)) { @@ -256,7 +269,7 @@ ipfix_open(wtap *wth, int *err, gchar **err_info) { ipfix_debug1("ipfix_open: failed seek to next set in file, %d bytes away", set_hdr.set_length - IPFIX_SET_HDR_SIZE); - return 0; + return -1; } checked_len += set_hdr.set_length; } |