Remove misuse of wtap_file_read_expected_bytes().
authorGuy Harris <guy@alum.mit.edu>
Tue, 23 Sep 2014 01:13:59 +0000 (18:13 -0700)
committerGuy Harris <guy@alum.mit.edu>
Tue, 23 Sep 2014 01:14:30 +0000 (01:14 +0000)
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>
wiretap/ipfix.c

index 8229255cb2e83ce2228ce54d77451c6e8af1996d..70b700d0923cc2b894354d4fd3766e89c400b4c0 100644 (file)
@@ -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;
         }