aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2005-01-16 23:30:55 +0000
committerGuy Harris <guy@alum.mit.edu>2005-01-16 23:30:55 +0000
commit2bdef3c1229d5c492c0e574135b3ef4589647b2a (patch)
tree598e354d8cb4cd7006ea802dd45aa74e027b5454
parent13bf5539af20a4c372bbcb58c0a0f8d051ab3dbc (diff)
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
-rw-r--r--epan/dissectors/packet-frame.c25
-rw-r--r--epan/exceptions.h2
-rw-r--r--epan/proto.c7
-rw-r--r--epan/proto.h14
4 files changed, 31 insertions, 17 deletions
diff --git a/epan/dissectors/packet-frame.c b/epan/dissectors/packet-frame.c
index 0716595f72..e80ce51eda 100644
--- a/epan/dissectors/packet-frame.c
+++ b/epan/dissectors/packet-frame.c
@@ -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();
}
}
diff --git a/epan/exceptions.h b/epan/exceptions.h
index 343794382e..f8c7388786 100644
--- a/epan/exceptions.h
+++ b/epan/exceptions.h
@@ -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:
*
diff --git a/epan/proto.c b/epan/proto.c
index 100e7dd138..bcc3a877ef 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -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);
diff --git a/epan/proto.h b/epan/proto.h
index 31333f444b..9253450d07 100644
--- a/epan/proto.h
+++ b/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.