forked from osmocom/wireshark
From Jeff Morriss: Fix crash: WTAP_ERR_BAD_RECORD error return needs to fill in *err_info.
From me: For ipfix_open() don't actually return with *err=WTAP_ERR_BAD_RECORD. Also: Move #define RECORDS_FOR_IPFIX_CHECK to ipfix.c from ipfix.h since the definition is only used in ipfix.c. svn path=/trunk/; revision=34589
This commit is contained in:
parent
54fa1f56da
commit
ce9f471175
|
@ -87,6 +87,8 @@
|
||||||
#define ipfix_debug3(str,p1,p2,p3)
|
#define ipfix_debug3(str,p1,p2,p3)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define RECORDS_FOR_IPFIX_CHECK 20
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ipfix_read(wtap *wth, int *err, gchar **err_info,
|
ipfix_read(wtap *wth, int *err, gchar **err_info,
|
||||||
gint64 *data_offset);
|
gint64 *data_offset);
|
||||||
|
@ -123,10 +125,10 @@ typedef struct ipfix_set_header_s {
|
||||||
* 0 on EOF, any other value for "real" errors (EOF is ok, since return
|
* 0 on EOF, any other value for "real" errors (EOF is ok, since return
|
||||||
* value is still FALSE)
|
* value is still FALSE)
|
||||||
*/
|
*/
|
||||||
static gboolean
|
static gboolean
|
||||||
ipfix_read_message_header(ipfix_message_header_t *pfx_hdr, FILE_T fh, int *err, gchar **err_info)
|
ipfix_read_message_header(ipfix_message_header_t *pfx_hdr, FILE_T fh, int *err, gchar **err_info)
|
||||||
{
|
{
|
||||||
wtap_file_read_expected_bytes(pfx_hdr, IPFIX_MSG_HDR_SIZE, fh, err);
|
wtap_file_read_expected_bytes(pfx_hdr, IPFIX_MSG_HDR_SIZE, fh, err); /* macro which does a return if read fails */
|
||||||
|
|
||||||
/* fix endianess, because IPFIX files are always big-endian */
|
/* fix endianess, because IPFIX files are always big-endian */
|
||||||
pfx_hdr->version = g_ntohs(pfx_hdr->version);
|
pfx_hdr->version = g_ntohs(pfx_hdr->version);
|
||||||
|
@ -139,6 +141,7 @@ ipfix_read_message_header(ipfix_message_header_t *pfx_hdr, FILE_T fh, int *err,
|
||||||
if (pfx_hdr->version != IPFIX_VERSION) {
|
if (pfx_hdr->version != IPFIX_VERSION) {
|
||||||
/* Not an ipfix file. */
|
/* Not an ipfix file. */
|
||||||
*err = WTAP_ERR_BAD_RECORD;
|
*err = WTAP_ERR_BAD_RECORD;
|
||||||
|
*err_info = g_strdup_printf("ipfix: wrong version %d", pfx_hdr->version);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,10 +191,16 @@ ipfix_open(wtap *wth, int *err, gchar **err_info)
|
||||||
for (i = 0; i < records_for_ipfix_check; i++) {
|
for (i = 0; i < records_for_ipfix_check; i++) {
|
||||||
/* read first message header to check version */
|
/* read first message header to check version */
|
||||||
if (!ipfix_read_message_header(&msg_hdr, wth->fh, err, err_info)) {
|
if (!ipfix_read_message_header(&msg_hdr, wth->fh, err, err_info)) {
|
||||||
ipfix_debug2("ipfix_open: couldn't read message header #%d with err code #%d",
|
ipfix_debug3("ipfix_open: couldn't read message header #%d with err code #%d (%s)",
|
||||||
i, *err);
|
i, *err, *err_info);
|
||||||
if (*err == WTAP_ERR_BAD_RECORD) return 0;
|
if (*err == WTAP_ERR_BAD_RECORD) {
|
||||||
if (*err != 0) return -1; /* real failure */
|
*err = 0; /* not actually an error in this case */
|
||||||
|
g_free(*err_info);
|
||||||
|
*err_info = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (*err != 0)
|
||||||
|
return -1; /* real failure */
|
||||||
/* else it's EOF */
|
/* else it's EOF */
|
||||||
if (i < 1) {
|
if (i < 1) {
|
||||||
/* we haven't seen enough to prove this is a ipfix file */
|
/* we haven't seen enough to prove this is a ipfix file */
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
#ifndef __W_IPFIX_H__
|
#ifndef __W_IPFIX_H__
|
||||||
#define __W_IPFIX_H__
|
#define __W_IPFIX_H__
|
||||||
|
|
||||||
#define RECORDS_FOR_IPFIX_CHECK 20
|
|
||||||
|
|
||||||
int ipfix_open(wtap *wth, int *err, gchar **err_info);
|
int ipfix_open(wtap *wth, int *err, gchar **err_info);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue