forked from osmocom/wireshark
Rename the FieldError exception to DissectorError.
Add a DISSECTOR_ASSERT() macro, which is the usual type of assertion macro, but throws a DissectorError exception with a message giving the flien and line number and the failed test as a string. Use that macro in "alloc_field_info()". Report that exception in the Info column and the protocol tree, as well as logging the exception failure with g_warning(). svn path=/trunk/; revision=13078
This commit is contained in:
parent
13bf5539af
commit
2bdef3c122
|
@ -220,18 +220,23 @@ show_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
|
|||
case ReportedBoundsError:
|
||||
show_reported_bounds_error(tvb, pinfo, tree);
|
||||
break;
|
||||
case FieldError:
|
||||
|
||||
case DissectorError:
|
||||
if (check_col(pinfo->cinfo, COL_INFO))
|
||||
col_append_str(pinfo->cinfo, COL_INFO, "[Dissector Bug]");
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO,
|
||||
"[Dissector bug, protocol %s: %s]",
|
||||
pinfo->current_proto, exception_message);
|
||||
proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0,
|
||||
"[FieldError: %s]", exception_message);
|
||||
g_warning("FieldError in packet: %u (%s)", pinfo->fd->num, exception_message);
|
||||
if(exception_message)
|
||||
g_free( (void *) exception_message);
|
||||
break;
|
||||
default:
|
||||
/* XXX - we want to know, if an unknown exception passed until here, don't we? */
|
||||
g_assert_not_reached();
|
||||
"[Dissector bug, protocol %s: %s]",
|
||||
pinfo->current_proto, exception_message);
|
||||
g_warning("Dissector bug, protocol %s, in packet %u: %s",
|
||||
pinfo->current_proto, pinfo->fd->num, exception_message);
|
||||
g_free((void *)exception_message);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* XXX - we want to know, if an unknown exception passed until here, don't we? */
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#define BoundsError 1 /* Index is out of range */
|
||||
#define ReportedBoundsError 2 /* Index is beyond reported length (not cap_len) */
|
||||
#define TypeError 3 /* During dfilter parsing */
|
||||
#define FieldError 4 /* A buggy dissector tried to add a field with invalid parameters */
|
||||
#define DissectorError 4 /* A bug was detected in a dissector */
|
||||
|
||||
/* Usage:
|
||||
*
|
||||
|
|
|
@ -2002,7 +2002,6 @@ alloc_field_info(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
|||
{
|
||||
header_field_info *hfinfo;
|
||||
field_info *fi;
|
||||
gchar *error_descr;
|
||||
|
||||
/*
|
||||
* We only allow a null tvbuff if the item has a zero length,
|
||||
|
@ -2093,11 +2092,7 @@ alloc_field_info(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
|||
g_assert_not_reached();
|
||||
}
|
||||
} else
|
||||
if(*length < 0) {
|
||||
error_descr = g_strdup_printf("\"%s\" - \"%s\" invalid length: %d %s/%u",
|
||||
hfinfo->name, hfinfo->abbrev, *length, __FILE__, __LINE__);
|
||||
THROW_MESSAGE(FieldError, error_descr);
|
||||
}
|
||||
DISSECTOR_ASSERT(*length >= 0);
|
||||
|
||||
FIELD_INFO_NEW(fi);
|
||||
|
||||
|
|
14
epan/proto.h
14
epan/proto.h
|
@ -78,6 +78,20 @@ typedef struct _protocol protocol_t;
|
|||
} \
|
||||
}
|
||||
|
||||
/** Macro used for assertions in dissectors; it doesn't abort, it just
|
||||
* throws a DissectorError exception, with the assertion failure
|
||||
* message as a parameter, so that it can show up in the protocol tree.
|
||||
*/
|
||||
#define DISSECTOR_ASSERT(expression) \
|
||||
((void) ((expression) ? 0 : \
|
||||
__DISSECTOR_ASSERT (expression, __FILE__, __LINE__)))
|
||||
|
||||
#define __DISSECTOR_ASSERT_STRINGIFY(s) # s
|
||||
|
||||
#define __DISSECTOR_ASSERT(expression, file, lineno) \
|
||||
(THROW_MESSAGE(DissectorError, \
|
||||
g_strdup_printf("%s:%u: failed assertion \"%s\"", \
|
||||
file, lineno, __DISSECTOR_ASSERT_STRINGIFY(expression))))
|
||||
|
||||
/** GNUC has the ability to check format strings that follow the syntax used in printf and others.
|
||||
Hide the differences between different compilers in this GNUC_FORMAT_CHECK macro.
|
||||
|
|
Loading…
Reference in New Issue