aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-ber.c
diff options
context:
space:
mode:
authorBill Meier <wmeier@newsguy.com>2012-10-18 02:33:11 +0000
committerBill Meier <wmeier@newsguy.com>2012-10-18 02:33:11 +0000
commitf498c3a17273dd868f77d70f582ae650bed7f4b2 (patch)
tree7d8643155826b5d2a6b1437cca8c2663b76923d2 /epan/dissectors/packet-ber.c
parent98e6481be8a42cfbdbc1e16a936436be82718412 (diff)
Reformat for readability:
indentation, whitespace, long-lines, etc. Also; - replace two usages of fprintf(stderr,...) by g_warning(); - revert incorrect replacement of FALSE by ENC_BIG_ENDIAN done a while back (2 cases); [The incorrect use of ENC_BIG_ENDIAN was benign since ENC_BIG_ENDIAN is currently defined ad 0x0000000] svn path=/trunk/; revision=45625
Diffstat (limited to 'epan/dissectors/packet-ber.c')
-rw-r--r--epan/dissectors/packet-ber.c3198
1 files changed, 1798 insertions, 1400 deletions
diff --git a/epan/dissectors/packet-ber.c b/epan/dissectors/packet-ber.c
index a23f05c32d..e5a9599210 100644
--- a/epan/dissectors/packet-ber.c
+++ b/epan/dissectors/packet-ber.c
@@ -148,23 +148,24 @@ static gint ett_ber_T_encoding = -1;
static gint ett_ber_fragment = -1;
static gint ett_ber_fragments = -1;
-static gboolean show_internal_ber_fields = FALSE;
-static gboolean decode_octetstring_as_ber = FALSE;
-static gboolean decode_primitive_as_ber = FALSE;
-static gboolean decode_unexpected = FALSE;
+static gboolean show_internal_ber_fields = FALSE;
+static gboolean decode_octetstring_as_ber = FALSE;
+static gboolean decode_primitive_as_ber = FALSE;
+static gboolean decode_unexpected = FALSE;
static gboolean decode_warning_leading_zero_bits = FALSE;
static gchar *decode_as_syntax = NULL;
-static gchar *ber_filename = NULL;
+static gchar *ber_filename = NULL;
-static dissector_table_t ber_oid_dissector_table=NULL;
-static dissector_table_t ber_syntax_dissector_table=NULL;
-static GHashTable *syntax_table=NULL;
+static dissector_table_t ber_oid_dissector_table = NULL;
+static dissector_table_t ber_syntax_dissector_table = NULL;
-static gint8 last_class;
+static GHashTable *syntax_table = NULL;
+
+static gint8 last_class;
static gboolean last_pc;
-static gint32 last_tag;
-static guint32 last_length;
+static gint32 last_tag;
+static guint32 last_length;
static gboolean last_ind;
static const value_string ber_class_codes[] = {
@@ -289,7 +290,7 @@ static const fragment_items octet_string_frag_items = {
static void *
oid_copy_cb(void *dest, const void *orig, size_t len _U_)
{
- oid_user_t *u = dest;
+ oid_user_t *u = dest;
const oid_user_t *o = orig;
u->oid = g_strdup(o->oid);
@@ -343,7 +344,7 @@ register_ber_oid_dissector(const char *oid, dissector_t dissector, int proto, co
{
dissector_handle_t dissector_handle;
- dissector_handle=create_dissector_handle(dissector, proto);
+ dissector_handle = create_dissector_handle(dissector, proto);
dissector_add_string("ber.oid", oid, dissector_handle);
oid_add_from_string(name, oid);
}
@@ -353,7 +354,7 @@ register_ber_syntax_dissector(const char *syntax, int proto, dissector_t dissect
{
dissector_handle_t dissector_handle;
- dissector_handle=create_dissector_handle(dissector, proto);
+ dissector_handle = create_dissector_handle(dissector, proto);
dissector_add_string("ber.syntax", syntax, dissector_handle);
}
@@ -362,10 +363,10 @@ void
register_ber_oid_syntax(const char *oid, const char *name, const char *syntax)
{
- if(syntax && *syntax)
+ if (syntax && *syntax)
g_hash_table_insert(syntax_table, (gpointer)g_strdup(oid), (gpointer)g_strdup(syntax));
- if(name && *name)
+ if (name && *name)
register_ber_oid_name(oid, name);
}
@@ -381,7 +382,7 @@ ber_add_syntax_name(gpointer key, gpointer value _U_, gpointer user_data)
{
guint *i = (guint*)user_data;
- if(*i < MAX_SYNTAX_NAMES) {
+ if (*i < MAX_SYNTAX_NAMES) {
syntax_names[*i].value = *i;
syntax_names[*i].strptr = (const gchar*)key;
@@ -390,7 +391,8 @@ ber_add_syntax_name(gpointer key, gpointer value _U_, gpointer user_data)
}
-static void ber_decode_as_dt(const gchar *table_name _U_, ftenum_t selector_type _U_, gpointer key, gpointer value, gpointer user_data)
+static void
+ber_decode_as_dt(const gchar *table_name _U_, ftenum_t selector_type _U_, gpointer key, gpointer value, gpointer user_data)
{
da_data *decode_as_data;
@@ -399,7 +401,8 @@ static void ber_decode_as_dt(const gchar *table_name _U_, ftenum_t selector_type
decode_as_data->func(key, value, decode_as_data->user_data);
}
-void ber_decode_as_foreach(GHFunc func, gpointer user_data)
+void
+ber_decode_as_foreach(GHFunc func, gpointer user_data)
{
da_data decode_as_data;
@@ -410,15 +413,16 @@ void ber_decode_as_foreach(GHFunc func, gpointer user_data)
}
-void ber_decode_as(const gchar *syntax)
+void
+ber_decode_as(const gchar *syntax)
{
- if(decode_as_syntax) {
+ if (decode_as_syntax) {
g_free(decode_as_syntax);
decode_as_syntax = NULL;
}
- if(syntax)
+ if (syntax)
decode_as_syntax = g_strdup(syntax);
}
@@ -429,20 +433,21 @@ get_ber_oid_syntax(const char *oid)
return g_hash_table_lookup(syntax_table, oid);
}
-void ber_set_filename(gchar *filename)
+void
+ber_set_filename(gchar *filename)
{
gchar *ptr;
- if(ber_filename) {
+ if (ber_filename) {
g_free(ber_filename);
ber_filename = NULL;
}
- if(filename) {
+ if (filename) {
ber_filename = g_strdup(filename);
- if((ptr = strrchr(ber_filename, '.')) != NULL) {
+ if ((ptr = strrchr(ber_filename, '.')) != NULL) {
ber_decode_as(get_ber_oid_syntax(ptr));
@@ -456,74 +461,99 @@ ber_update_oids(void)
{
guint i;
- for(i = 0; i < num_oid_users; i++)
+ for (i = 0; i < num_oid_users; i++)
register_ber_oid_syntax(oid_users[i].oid, oid_users[i].name, oid_users[i].syntax);
}
static void
ber_check_length (guint32 length, gint32 min_len, gint32 max_len, asn1_ctx_t *actx, proto_item *item, gboolean bit)
{
- if (min_len != -1 && length < (guint32)min_len) {
- expert_add_info_format(actx->pinfo, item, PI_PROTOCOL, PI_WARN, "Size constraint: %sstring too short: %d (%d .. %d)", bit ? "bit " : "", length, min_len, max_len);
- } else if (max_len != -1 && length > (guint32)max_len) {
- expert_add_info_format(actx->pinfo, item, PI_PROTOCOL, PI_WARN, "Size constraint: %sstring too long: %d (%d .. %d)", bit ? "bit " : "", length, min_len, max_len);
+ if ((min_len != -1) && (length < (guint32)min_len)) {
+ expert_add_info_format(
+ actx->pinfo, item, PI_PROTOCOL, PI_WARN,
+ "Size constraint: %sstring too short: %d (%d .. %d)",
+ bit ? "bit " : "", length, min_len, max_len);
+ } else if ((max_len != -1) && (length > (guint32)max_len)) {
+ expert_add_info_format(
+ actx->pinfo, item, PI_PROTOCOL, PI_WARN,
+ "Size constraint: %sstring too long: %d (%d .. %d)",
+ bit ? "bit " : "", length, min_len, max_len);
}
}
static void
ber_check_value64 (gint64 value, gint64 min_len, gint64 max_len, asn1_ctx_t *actx, proto_item *item)
{
- if (min_len != -1 && value < min_len) {
- expert_add_info_format(actx->pinfo, item, PI_PROTOCOL, PI_WARN, "Size constraint: value too small: %" G_GINT64_MODIFIER "d (%" G_GINT64_MODIFIER "d .. %" G_GINT64_MODIFIER "d)", value, min_len, max_len);
- } else if (max_len != -1 && value > max_len) {
- expert_add_info_format(actx->pinfo, item, PI_PROTOCOL, PI_WARN, "Size constraint: value too big: %" G_GINT64_MODIFIER "d (%" G_GINT64_MODIFIER "d .. %" G_GINT64_MODIFIER "d)", value, min_len, max_len);
+ if ((min_len != -1) && (value < min_len)) {
+ expert_add_info_format(
+ actx->pinfo, item, PI_PROTOCOL, PI_WARN,
+ "Size constraint: value too small: %" G_GINT64_MODIFIER "d (%" G_GINT64_MODIFIER "d .. %" G_GINT64_MODIFIER "d)",
+ value, min_len, max_len);
+ } else if ((max_len != -1) && (value > max_len)) {
+ expert_add_info_format(
+ actx->pinfo, item, PI_PROTOCOL, PI_WARN,
+ "Size constraint: value too big: %" G_GINT64_MODIFIER "d (%" G_GINT64_MODIFIER "d .. %" G_GINT64_MODIFIER "d)",
+ value, min_len, max_len);
}
}
static void
ber_check_value (guint32 value, gint32 min_len, gint32 max_len, asn1_ctx_t *actx, proto_item *item)
{
- if (min_len != -1 && value < (guint32)min_len) {
- expert_add_info_format(actx->pinfo, item, PI_PROTOCOL, PI_WARN, "Size constraint: value too small: %d (%d .. %d)", value, min_len, max_len);
- } else if (max_len != -1 && value > (guint32)max_len) {
- expert_add_info_format(actx->pinfo, item, PI_PROTOCOL, PI_WARN, "Size constraint: value too big: %d (%d .. %d)", value, min_len, max_len);
+ if ((min_len != -1) && (value < (guint32)min_len)) {
+ expert_add_info_format(
+ actx->pinfo, item, PI_PROTOCOL, PI_WARN,
+ "Size constraint: value too small: %d (%d .. %d)",
+ value, min_len, max_len);
+ } else if ((max_len != -1) && (value > (guint32)max_len)) {
+ expert_add_info_format(
+ actx->pinfo, item, PI_PROTOCOL, PI_WARN,
+ "Size constraint: value too big: %d (%d .. %d)",
+ value, min_len, max_len);
}
}
static void
ber_check_items (int cnt, gint32 min_len, gint32 max_len, asn1_ctx_t *actx, proto_item *item)
{
- if (min_len != -1 && cnt < min_len) {
- expert_add_info_format(actx->pinfo, item, PI_PROTOCOL, PI_WARN, "Size constraint: too few items: %d (%d .. %d)", cnt, min_len, max_len);
- } else if (max_len != -1 && cnt > max_len) {
- expert_add_info_format(actx->pinfo, item, PI_PROTOCOL, PI_WARN, "Size constraint: too many items: %d (%d .. %d)", cnt, min_len, max_len);
+ if ((min_len != -1) && (cnt < min_len)) {
+ expert_add_info_format(
+ actx->pinfo, item, PI_PROTOCOL, PI_WARN,
+ "Size constraint: too few items: %d (%d .. %d)",
+ cnt, min_len, max_len);
+ } else if ((max_len != -1) && (cnt > max_len)) {
+ expert_add_info_format(
+ actx->pinfo, item, PI_PROTOCOL, PI_WARN,
+ "Size constraint: too many items: %d (%d .. %d)",
+ cnt, min_len, max_len);
}
}
-int dissect_ber_tagged_type(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, gint8 tag_cls, gint32 tag_tag, gboolean tag_impl, ber_type_fn type)
+int
+dissect_ber_tagged_type(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, gint8 tag_cls, gint32 tag_tag, gboolean tag_impl, ber_type_fn type)
{
- gint8 tmp_cls;
- gint32 tmp_tag;
- guint32 tmp_len;
- tvbuff_t *next_tvb = tvb;
+ gint8 tmp_cls;
+ gint32 tmp_tag;
+ guint32 tmp_len;
+ tvbuff_t *next_tvb = tvb;
proto_item *cause;
#ifdef DEBUG_BER
- {
- const char *name;
- header_field_info *hfinfo;
- if(hf_id>=0){
- hfinfo = proto_registrar_get_nth(hf_id);
- name=hfinfo->name;
- } else {
- name="unnamed";
- }
- if(tvb_length_remaining(tvb,offset)>3){
- printf("dissect_ber_tagged_type(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n",name,implicit_tag,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
- }else{
- printf("dissect_ber_tagged_type(%s) entered\n",name);
- }
- }
+{
+const char *name;
+header_field_info *hfinfo;
+if (hf_id >= 0) {
+hfinfo = proto_registrar_get_nth(hf_id);
+name = hfinfo->name;
+} else {
+name = "unnamed";
+}
+if (tvb_length_remaining(tvb, offset) > 3) {
+printf("dissect_ber_tagged_type(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n", name, implicit_tag, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("dissect_ber_tagged_type(%s) entered\n", name);
+}
+}
#endif
if (implicit_tag) {
@@ -535,16 +565,19 @@ int dissect_ber_tagged_type(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &tmp_len, NULL);
if ((tmp_cls != tag_cls) || (tmp_tag != tag_tag)) {
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, tmp_len, "wrong_tag",
- "BER Error: Wrong tag in tagged type - expected class:%s(%d) tag:%d (%s) but found class:%s(%d) tag:%d",
- val_to_str_const(tag_cls, ber_class_codes, "Unknown"),
- tag_cls,
- tag_tag,
- val_to_str_ext_const(tag_tag, &ber_uni_tag_codes_ext, "Unknown"),
- val_to_str_const(tmp_cls, ber_class_codes, "Unknown"),
- tmp_cls,
- tmp_tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Wrong tag in tagged type");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, tmp_len, "wrong_tag",
+ "BER Error: Wrong tag in tagged type - expected class:%s(%d) tag:%d (%s) but found class:%s(%d) tag:%d",
+ val_to_str_const(tag_cls, ber_class_codes, "Unknown"),
+ tag_cls,
+ tag_tag,
+ val_to_str_ext_const(tag_tag, &ber_uni_tag_codes_ext, "Unknown"),
+ val_to_str_const(tmp_cls, ber_class_codes, "Unknown"),
+ tmp_cls,
+ tmp_tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Wrong tag in tagged type");
}
if (tag_impl) {
@@ -568,9 +601,12 @@ ber_add_bad_length_error(packet_info *pinfo, proto_tree *tree,
{
proto_item *ti;
- ti = proto_tree_add_string_format(tree, hf_ber_error, tvb, start, length, "illegal_length",
- "%s: length of item (%d) is not valid", name, length);
- expert_add_info_format(pinfo, ti, PI_MALFORMED, PI_WARN,
+ ti = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, start, length, "illegal_length",
+ "%s: length of item (%d) is not valid",
+ name, length);
+ expert_add_info_format(
+ pinfo, ti, PI_MALFORMED, PI_WARN,
"Length of item (%d) is not valid", length);
return ti;
}
@@ -612,8 +648,8 @@ ber_proto_tree_add_item(packet_info *pinfo, proto_tree *tree,
case FT_INT16:
case FT_INT24:
case FT_INT32:
- if (length != 1 && length != 2 && length != 3 &&
- length != 4)
+ if ((length != 1) && (length != 2) && (length != 3) &&
+ (length != 4))
return ber_add_bad_length_error(pinfo, tree,
hfinfo->name, tvb, start, length);
break;
@@ -631,7 +667,7 @@ ber_proto_tree_add_item(packet_info *pinfo, proto_tree *tree,
break;
case FT_IPv6:
- if (length < 0 || length > FT_IPv6_LEN)
+ if ((length < 0) || (length > FT_IPv6_LEN))
return ber_add_bad_length_error(pinfo, tree,
hfinfo->name, tvb, start, length);
break;
@@ -662,7 +698,7 @@ ber_proto_tree_add_item(packet_info *pinfo, proto_tree *tree,
case FT_ABSOLUTE_TIME:
case FT_RELATIVE_TIME:
- if (length != 4 && length != 8)
+ if ((length != 4) && (length != 8))
return ber_add_bad_length_error(pinfo, tree,
hfinfo->name, tvb, start, length);
break;
@@ -677,54 +713,60 @@ ber_proto_tree_add_item(packet_info *pinfo, proto_tree *tree,
static int
try_dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, volatile int offset, proto_tree *tree, gint nest_level)
{
- int start_offset;
- gint8 ber_class;
- gboolean pc, ind;
- gint32 tag;
- guint32 len;
- int hdr_len;
- proto_item *item=NULL;
- proto_tree *next_tree=NULL;
- guint8 c;
- guint32 i;
- gboolean is_printable;
- volatile gboolean is_decoded_as;
- proto_item *pi, *cause;
- asn1_ctx_t asn1_ctx;
+ int start_offset;
+ gint8 ber_class;
+ gboolean pc, ind;
+ gint32 tag;
+ guint32 len;
+ int hdr_len;
+ proto_item *item = NULL;
+ proto_tree *next_tree = NULL;
+ guint8 c;
+ guint32 i;
+ gboolean is_printable;
+ volatile gboolean is_decoded_as;
+ proto_item *pi, *cause;
+ asn1_ctx_t asn1_ctx;
if (nest_level > BER_MAX_NESTING) {
/* Assume that we have a malformed packet. */
THROW(ReportedBoundsError);
}
- start_offset=offset;
+ start_offset = offset;
asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
- offset=get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
- offset=get_ber_length(tvb, offset, &len, &ind);
+ offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
+ offset = get_ber_length(tvb, offset, &len, &ind);
- if(len>(guint32)tvb_length_remaining(tvb, offset)){
- /* hmm maybe something bad happened or the frame is short,
+ if (len > (guint32)tvb_length_remaining(tvb, offset)) {
+ /* hmm maybe something bad happened or the frame is short;
since these are not vital outputs just return instead of
throwing an exception.
*/
- if(show_internal_ber_fields) {
- offset=dissect_ber_identifier(pinfo, tree, tvb, start_offset, &ber_class, &pc, &tag);
- offset=dissect_ber_length(pinfo, tree, tvb, offset, &len, NULL);
- }
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "illegal_length", "BER Error: length:%u longer than tvb_length_remaining:%d",len, tvb_length_remaining(tvb, offset));
- expert_add_info_format(pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error length");
+ if (show_internal_ber_fields) {
+ offset = dissect_ber_identifier(pinfo, tree, tvb, start_offset, &ber_class, &pc, &tag);
+ offset = dissect_ber_length(pinfo, tree, tvb, offset, &len, NULL);
+ }
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "illegal_length",
+ "BER Error: length:%u longer than tvb_length_remaining:%d",
+ len,
+ tvb_length_remaining(tvb, offset));
+ expert_add_info_format(
+ pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error length");
return tvb_length(tvb);
}
-/* we dont care about the class only on the constructor flag */
- switch(pc){
+/* we don't care about the class only on the constructor flag */
+ switch (pc) {
case FALSE: /* this is not constructed */
- switch(ber_class) { /* we do care about the class */
+ switch (ber_class) { /* we do care about the class */
case BER_CLASS_UNI: /* it a Universal tag - we can decode it */
- switch(tag){
+ switch (tag) {
case BER_UNI_TAG_EOC:
/* XXX: shouldn't really get here */
break;
@@ -742,7 +784,7 @@ try_dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, volatile int offset,
break;
case BER_UNI_TAG_OCTETSTRING:
is_decoded_as = FALSE;
- if (decode_octetstring_as_ber && len >= 2) {
+ if (decode_octetstring_as_ber && (len >= 2)) {
volatile int ber_offset = 0;
guint32 ber_len = 0;
TRY {
@@ -770,7 +812,7 @@ try_dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, volatile int offset,
}
break;
case BER_UNI_TAG_OID:
- offset=dissect_ber_object_identifier_str(FALSE, &asn1_ctx, tree, tvb, start_offset, hf_ber_unknown_OID, NULL);
+ offset = dissect_ber_object_identifier_str(FALSE, &asn1_ctx, tree, tvb, start_offset, hf_ber_unknown_OID, NULL);
break;
case BER_UNI_TAG_NumericString:
offset = dissect_ber_octet_string(FALSE, &asn1_ctx, tree, tvb, start_offset, hf_ber_unknown_NumericString, NULL);
@@ -812,10 +854,15 @@ try_dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, volatile int offset,
offset = dissect_ber_boolean(FALSE, &asn1_ctx, tree, tvb, start_offset, hf_ber_unknown_BOOLEAN, NULL);
break;
default:
- offset=dissect_ber_identifier(pinfo, tree, tvb, start_offset, &ber_class, &pc, &tag);
- offset=dissect_ber_length(pinfo, tree, tvb, offset, &len, NULL);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "unknown_universal_tag", "BER Error: can not handle universal tag:%d",tag);
- expert_add_info_format(pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: can not handle universal");
+ offset = dissect_ber_identifier(pinfo, tree, tvb, start_offset, &ber_class, &pc, &tag);
+ offset = dissect_ber_length(pinfo, tree, tvb, offset, &len, NULL);
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "unknown_universal_tag",
+ "BER Error: can not handle universal tag:%d",
+ tag);
+ expert_add_info_format(
+ pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: can not handle universal");
offset += len;
}
break;
@@ -824,17 +871,17 @@ try_dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, volatile int offset,
case BER_CLASS_PRI:
default:
/* we dissect again if show_internal_ber_fields is set */
- if(show_internal_ber_fields) {
- offset=dissect_ber_identifier(pinfo, tree, tvb, start_offset, &ber_class, &pc, &tag);
- offset=dissect_ber_length(pinfo, tree, tvb, offset, &len, NULL);
+ if (show_internal_ber_fields) {
+ offset = dissect_ber_identifier(pinfo, tree, tvb, start_offset, &ber_class, &pc, &tag);
+ offset = dissect_ber_length(pinfo, tree, tvb, offset, &len, NULL);
}
/* we can't dissect this directly as it is specific */
pi = proto_tree_add_none_format(tree, hf_ber_unknown_BER_primitive, tvb, offset, len,
- "[%s %d] ", val_to_str_const(ber_class,ber_class_codes,"Unknown"), tag);
+ "[%s %d] ", val_to_str_const(ber_class, ber_class_codes, "Unknown"), tag);
is_decoded_as = FALSE;
- if (decode_primitive_as_ber && len >= 2) {
+ if (decode_primitive_as_ber && (len >= 2)) {
volatile int ber_offset = 0;
guint32 ber_len = 0;
TRY {
@@ -857,21 +904,21 @@ try_dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, volatile int offset,
if (!is_decoded_as && len) {
/* we may want to do better and show the bytes */
is_printable = TRUE;
- for(i=0;i<len;i++){
+ for (i=0; i<len; i++) {
c = tvb_get_guint8(tvb, offset+i);
- if(is_printable && !g_ascii_isprint(c))
- is_printable=FALSE;
+ if (is_printable && !g_ascii_isprint(c))
+ is_printable = FALSE;
- proto_item_append_text(pi,"%02x",c);
+ proto_item_append_text(pi, "%02x", c);
}
- if(is_printable) { /* give a nicer representation if it looks like a string */
- proto_item_append_text(pi," (");
- for(i=0;i<len;i++){
- proto_item_append_text(pi,"%c",tvb_get_guint8(tvb, offset+i));
+ if (is_printable) { /* give a nicer representation if it looks like a string */
+ proto_item_append_text(pi, " (");
+ for (i=0; i<len; i++) {
+ proto_item_append_text(pi, "%c", tvb_get_guint8(tvb, offset+i));
}
- proto_item_append_text(pi,")");
+ proto_item_append_text(pi, ")");
}
offset += len;
}
@@ -883,32 +930,32 @@ try_dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, volatile int offset,
case TRUE: /* this is constructed */
/* we dissect again if show_internal_ber_fields is set */
- if(show_internal_ber_fields) {
- offset=dissect_ber_identifier(pinfo, tree, tvb, start_offset, &ber_class, &pc, &tag);
- offset=dissect_ber_length(pinfo, tree, tvb, offset, &len, NULL);
+ if (show_internal_ber_fields) {
+ offset = dissect_ber_identifier(pinfo, tree, tvb, start_offset, &ber_class, &pc, &tag);
+ offset = dissect_ber_length(pinfo, tree, tvb, offset, &len, NULL);
}
- hdr_len=offset-start_offset;
+ hdr_len = offset-start_offset;
- switch(ber_class) {
+ switch (ber_class) {
case BER_CLASS_UNI:
- item=proto_tree_add_text(tree, tvb, offset, len, "%s", val_to_str_ext_const(tag,&ber_uni_tag_codes_ext,"Unknown"));
- if(item){
- next_tree=proto_item_add_subtree(item, ett_ber_SEQUENCE);
+ item = proto_tree_add_text(tree, tvb, offset, len, "%s", val_to_str_ext_const(tag, &ber_uni_tag_codes_ext, "Unknown"));
+ if (item) {
+ next_tree = proto_item_add_subtree(item, ett_ber_SEQUENCE);
}
- while(offset < (int)(start_offset + len + hdr_len))
- offset=try_dissect_unknown_ber(pinfo, tvb, offset, next_tree, nest_level+1);
+ while (offset < (int)(start_offset + len + hdr_len))
+ offset = try_dissect_unknown_ber(pinfo, tvb, offset, next_tree, nest_level+1);
break;
case BER_CLASS_APP:
case BER_CLASS_CON:
case BER_CLASS_PRI:
default:
- item=proto_tree_add_text(tree, tvb, offset, len, "[%s %d]", val_to_str_const(ber_class,ber_class_codes,"Unknown"), tag);
- if(item){
- next_tree=proto_item_add_subtree(item, ett_ber_SEQUENCE);
+ item = proto_tree_add_text(tree, tvb, offset, len, "[%s %d]", val_to_str_const(ber_class, ber_class_codes, "Unknown"), tag);
+ if (item) {
+ next_tree = proto_item_add_subtree(item, ett_ber_SEQUENCE);
}
- while(offset < (int)(start_offset + len + hdr_len))
- offset=try_dissect_unknown_ber(pinfo, tvb, offset, next_tree, nest_level+1);
+ while (offset < (int)(start_offset + len + hdr_len))
+ offset = try_dissect_unknown_ber(pinfo, tvb, offset, next_tree, nest_level+1);
break;
}
@@ -928,7 +975,7 @@ dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, int offset, proto_tree *t
int
call_ber_oid_callback(const char *oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
{
- tvbuff_t *next_tvb;
+ tvbuff_t *next_tvb;
const char *syntax = NULL;
if (!tvb) {
@@ -936,36 +983,51 @@ call_ber_oid_callback(const char *oid, tvbuff_t *tvb, int offset, packet_info *p
}
next_tvb = tvb_new_subset_remaining(tvb, offset);
- if(oid == NULL ||
- ((((syntax = get_ber_oid_syntax(oid)) == NULL) ||
- /* First see if a syntax has been registered for this oid (user defined) */
- !dissector_try_string(ber_syntax_dissector_table, syntax, next_tvb, pinfo, tree)) &&
- /* Then try registered oid's */
- (!dissector_try_string(ber_oid_dissector_table, oid, next_tvb, pinfo, tree)))) {
- proto_item *item=NULL;
- proto_tree *next_tree=NULL;
- gint length_remaining;
+ if (oid == NULL ||
+ ((((syntax = get_ber_oid_syntax(oid)) == NULL) ||
+ /* First see if a syntax has been registered for this oid (user defined) */
+ !dissector_try_string(ber_syntax_dissector_table, syntax, next_tvb, pinfo, tree)) &&
+ /* Then try registered oid's */
+ (!dissector_try_string(ber_oid_dissector_table, oid, next_tvb, pinfo, tree)))) {
+ proto_item *item = NULL;
+ proto_tree *next_tree = NULL;
+ gint length_remaining;
length_remaining = tvb_length_remaining(tvb, offset);
if (oid == NULL) {
- item=proto_tree_add_none_format(tree, hf_ber_no_oid, next_tvb, 0, length_remaining, "BER: No OID supplied to call_ber_oid_callback");
- expert_add_info_format(pinfo, item, PI_MALFORMED, PI_WARN, "BER Error: No OID supplied");
+ item = proto_tree_add_none_format(
+ tree, hf_ber_no_oid, next_tvb, 0, length_remaining,
+ "BER: No OID supplied to call_ber_oid_callback");
+ expert_add_info_format(
+ pinfo, item, PI_MALFORMED, PI_WARN,
+ "BER Error: No OID supplied");
} else if (tvb_get_ntohs (tvb, offset) != 0x0500) { /* Not NULL tag */
- if(syntax)
- item=proto_tree_add_none_format(tree, hf_ber_syntax_not_implemented, next_tvb, 0, length_remaining, "BER: Dissector for syntax:%s not implemented. Contact Wireshark developers if you want this supported", syntax);
- else
- item=proto_tree_add_none_format(tree, hf_ber_oid_not_implemented, next_tvb, 0, length_remaining, "BER: Dissector for OID:%s not implemented. Contact Wireshark developers if you want this supported", oid);
- expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN, "BER: Dissector for OID %s not implemented", oid);
+ if (syntax) {
+ item = proto_tree_add_none_format(
+ tree, hf_ber_syntax_not_implemented, next_tvb, 0, length_remaining,
+ "BER: Dissector for syntax:%s not implemented."
+ " Contact Wireshark developers if you want this supported",
+ syntax);
+ } else {
+ item = proto_tree_add_none_format(
+ tree, hf_ber_oid_not_implemented, next_tvb, 0, length_remaining,
+ "BER: Dissector for OID:%s not implemented."
+ " Contact Wireshark developers if you want this supported",
+ oid);
+ }
+ expert_add_info_format(
+ pinfo, item, PI_UNDECODED, PI_WARN,
+ "BER: Dissector for OID %s not implemented", oid);
} else {
- next_tree=tree;
+ next_tree = tree;
}
if (decode_unexpected) {
int ber_offset;
gint32 ber_len;
- if(item){
- next_tree=proto_item_add_subtree(item, ett_ber_unknown);
+ if (item) {
+ next_tree = proto_item_add_subtree(item, ett_ber_unknown);
}
ber_offset = get_ber_identifier(next_tvb, 0, NULL, NULL, NULL);
ber_offset = get_ber_length(next_tvb, ber_offset, &ber_len, NULL);
@@ -987,7 +1049,7 @@ call_ber_oid_callback(const char *oid, tvbuff_t *tvb, int offset, packet_info *p
* into new_dissector_t we have to do this kludge with
* manually step past the content in the ANY type.
*/
- offset+=tvb_length_remaining(tvb, offset);
+ offset += tvb_length_remaining(tvb, offset);
return offset;
}
@@ -998,17 +1060,23 @@ call_ber_syntax_callback(const char *syntax, tvbuff_t *tvb, int offset, packet_i
tvbuff_t *next_tvb;
next_tvb = tvb_new_subset_remaining(tvb, offset);
- if(syntax == NULL ||
- !dissector_try_string(ber_syntax_dissector_table, syntax, next_tvb, pinfo, tree)){
- proto_item *item=NULL;
- proto_tree *next_tree=NULL;
-
- if (syntax == NULL)
- item=proto_tree_add_none_format(tree, hf_ber_no_syntax, next_tvb, 0, tvb_length_remaining(tvb, offset), "BER: No syntax supplied to call_ber_syntax_callback");
- else
- item=proto_tree_add_none_format(tree, hf_ber_syntax_not_implemented, next_tvb, 0, tvb_length_remaining(tvb, offset), "BER: Dissector for syntax: %s not implemented. Contact Wireshark developers if you want this supported", syntax);
- if(item){
- next_tree=proto_item_add_subtree(item, ett_ber_unknown);
+ if (syntax == NULL ||
+ !dissector_try_string(ber_syntax_dissector_table, syntax, next_tvb, pinfo, tree)) {
+ proto_item *item = NULL;
+ proto_tree *next_tree = NULL;
+
+ if (syntax == NULL) {
+ item = proto_tree_add_none_format(
+ tree, hf_ber_no_syntax, next_tvb, 0, tvb_length_remaining(tvb, offset),
+ "BER: No syntax supplied to call_ber_syntax_callback");
+ } else {
+ item = proto_tree_add_none_format(
+ tree, hf_ber_syntax_not_implemented, next_tvb, 0, tvb_length_remaining(tvb, offset),
+ "BER: Dissector for syntax: %s not implemented. Contact Wireshark developers if you want this supported",
+ syntax);
+ }
+ if (item) {
+ next_tree = proto_item_add_subtree(item, ett_ber_unknown);
}
dissect_unknown_ber(pinfo, next_tvb, 0, next_tree);
}
@@ -1026,11 +1094,12 @@ call_ber_syntax_callback(const char *syntax, tvbuff_t *tvb, int offset, packet_i
/* 8.1 General rules for encoding */
/* 8.1.2 Identifier octets */
-int get_ber_identifier(tvbuff_t *tvb, int offset, gint8 *ber_class, gboolean *pc, gint32 *tag) {
- guint8 id, t;
- gint8 tmp_class;
+int
+get_ber_identifier(tvbuff_t *tvb, int offset, gint8 *ber_class, gboolean *pc, gint32 *tag) {
+ guint8 id, t;
+ gint8 tmp_class;
gboolean tmp_pc;
- gint32 tmp_tag;
+ gint32 tmp_tag;
id = tvb_get_guint8(tvb, offset);
offset += 1;
@@ -1038,9 +1107,9 @@ int get_ber_identifier(tvbuff_t *tvb, int offset, gint8 *ber_class, gboolean *pc
printf ("BER ID=%02x", id);
#endif
/* 8.1.2.2 */
- tmp_class = (id>>6) & 0x03;
- tmp_pc = (id>>5) & 0x01;
- tmp_tag = id&0x1F;
+ tmp_class = (id >> 6) & 0x03;
+ tmp_pc = (id >> 5) & 0x01;
+ tmp_tag = id & 0x1F;
/* 8.1.2.4 */
if (tmp_tag == 0x1F) {
tmp_tag = 0;
@@ -1063,48 +1132,50 @@ printf ("\n");
if (ber_class)
*ber_class = tmp_class;
if (pc)
- *pc = tmp_pc;
+ *pc = tmp_pc;
if (tag)
*tag = tmp_tag;
last_class = tmp_class;
- last_pc = tmp_pc;
+ last_pc = tmp_pc;
last_tag = tmp_tag;
return offset;
}
-static void get_last_ber_identifier(gint8 *ber_class, gboolean *pc, gint32 *tag)
+static void
+get_last_ber_identifier(gint8 *ber_class, gboolean *pc, gint32 *tag)
{
if (ber_class)
*ber_class = last_class;
if (pc)
- *pc = last_pc;
+ *pc = last_pc;
if (tag)
*tag = last_tag;
}
-int dissect_ber_identifier(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, gint8 *ber_class, gboolean *pc, gint32 *tag)
+int
+dissect_ber_identifier(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, gint8 *ber_class, gboolean *pc, gint32 *tag)
{
- int old_offset = offset;
- gint8 tmp_class;
+ int old_offset = offset;
+ gint8 tmp_class;
gboolean tmp_pc;
- gint32 tmp_tag;
+ gint32 tmp_tag;
offset = get_ber_identifier(tvb, offset, &tmp_class, &tmp_pc, &tmp_tag);
- if(show_internal_ber_fields){
- proto_tree_add_uint(tree, hf_ber_id_class, tvb, old_offset, 1, tmp_class<<6);
- proto_tree_add_boolean(tree, hf_ber_id_pc, tvb, old_offset, 1, (tmp_pc)?0x20:0x00);
- if(tmp_tag>0x1F){
- if(tmp_class==BER_CLASS_UNI){
+ if (show_internal_ber_fields) {
+ proto_tree_add_uint(tree, hf_ber_id_class, tvb, old_offset, 1, tmp_class << 6);
+ proto_tree_add_boolean(tree, hf_ber_id_pc, tvb, old_offset, 1, (tmp_pc) ? 0x20 : 0x00);
+ if (tmp_tag > 0x1F) {
+ if (tmp_class == BER_CLASS_UNI) {
proto_tree_add_uint(tree, hf_ber_id_uni_tag_ext, tvb, old_offset + 1, offset - (old_offset + 1), tmp_tag);
} else {
proto_tree_add_uint(tree, hf_ber_id_tag_ext, tvb, old_offset + 1, offset - (old_offset + 1), tmp_tag);
}
} else {
- if(tmp_class==BER_CLASS_UNI){
+ if (tmp_class == BER_CLASS_UNI) {
proto_tree_add_uint(tree, hf_ber_id_uni_tag, tvb, old_offset, 1, tmp_tag);
} else {
proto_tree_add_uint(tree, hf_ber_id_tag, tvb, old_offset, 1, tmp_tag);
@@ -1112,11 +1183,11 @@ int dissect_ber_identifier(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *t
}
}
- if(ber_class)
+ if (ber_class)
*ber_class = tmp_class;
- if(pc)
+ if (pc)
*pc = tmp_pc;
- if(tag)
+ if (tag)
*tag = tmp_tag;
return offset;
@@ -1132,16 +1203,17 @@ int dissect_ber_identifier(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *t
static int
try_get_ber_length(tvbuff_t *tvb, int offset, guint32 *length, gboolean *ind, gint nest_level) {
- guint8 oct, len;
- guint32 indef_len;
- guint32 tmp_length;
+ guint8 oct, len;
+ guint32 indef_len;
+ guint32 tmp_length;
gboolean tmp_ind;
- int tmp_offset,s_offset;
- gint8 tclass;
+ int tmp_offset, s_offset;
+ gint8 tclass;
gboolean tpc;
- gint32 ttag;
+ gint32 ttag;
+
tmp_length = 0;
- tmp_ind = FALSE;
+ tmp_ind = FALSE;
if (nest_level > BER_MAX_NESTING) {
/* Assume that we have a malformed packet. */
@@ -1151,12 +1223,12 @@ try_get_ber_length(tvbuff_t *tvb, int offset, guint32 *length, gboolean *ind, gi
oct = tvb_get_guint8(tvb, offset);
offset += 1;
- if(!(oct&0x80)) {
+ if (!(oct & 0x80)) {
/* 8.1.3.4 */
tmp_length = oct;
} else {
len = oct & 0x7F;
- if(len) {
+ if (len) {
/* 8.1.3.5 */
while (len--) {
oct = tvb_get_guint8(tvb, offset);
@@ -1172,9 +1244,9 @@ try_get_ber_length(tvbuff_t *tvb, int offset, guint32 *length, gboolean *ind, gi
/* check for EOC */
while (tvb_get_guint8(tvb, offset) || tvb_get_guint8(tvb, offset+1)) {
/* not an EOC at offset */
- s_offset=offset;
+ s_offset = offset;
offset= get_ber_identifier(tvb, offset, &tclass, &tpc, &ttag);
- offset= try_get_ber_length(tvb,offset, &indef_len, NULL, nest_level+1);
+ offset= try_get_ber_length(tvb, offset, &indef_len, NULL, nest_level+1);
tmp_length += indef_len+(offset-s_offset); /* length + tag and length */
offset += indef_len;
/* Make sure we've moved forward in the packet */
@@ -1205,7 +1277,8 @@ get_ber_length(tvbuff_t *tvb, int offset, guint32 *length, gboolean *ind)
return try_get_ber_length(tvb, offset, length, ind, 1);
}
-static void get_last_ber_length(guint32 *length, gboolean *ind)
+static void
+get_last_ber_length(guint32 *length, gboolean *ind)
{
if (length)
*length = last_length;
@@ -1219,22 +1292,22 @@ static void get_last_ber_length(guint32 *length, gboolean *ind)
int
dissect_ber_length(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, guint32 *length, gboolean *ind)
{
- int old_offset = offset;
- guint32 tmp_length;
+ int old_offset = offset;
+ guint32 tmp_length;
gboolean tmp_ind;
offset = get_ber_length(tvb, offset, &tmp_length, &tmp_ind);
- if(show_internal_ber_fields){
- if(tmp_ind){
+ if (show_internal_ber_fields) {
+ if (tmp_ind) {
proto_tree_add_text(tree, tvb, old_offset, 1, "Length: Indefinite length %d", tmp_length);
} else {
proto_tree_add_uint(tree, hf_ber_length, tvb, old_offset, offset - old_offset, tmp_length);
}
}
- if(length)
+ if (length)
*length = tmp_length;
- if(ind)
+ if (ind)
*ind = tmp_ind;
#ifdef DEBUG_BER
@@ -1247,7 +1320,7 @@ printf("dissect BER length %d, offset %d (remaining %d)\n", tmp_length, offset,
return offset;
}
-static GHashTable *octet_segment_table = NULL;
+static GHashTable *octet_segment_table = NULL;
static GHashTable *octet_reassembled_table = NULL;
static void ber_defragment_init(void) {
@@ -1258,18 +1331,18 @@ static void ber_defragment_init(void) {
static int
reassemble_octet_string(asn1_ctx_t *actx, proto_tree *tree, gint hf_id, tvbuff_t *tvb, int offset, guint32 con_len, gboolean ind, tvbuff_t **out_tvb)
{
- fragment_data *fd_head = NULL;
- tvbuff_t *next_tvb = NULL;
- tvbuff_t *reassembled_tvb = NULL;
- guint16 dst_ref = 0;
- int start_offset = offset;
- gboolean fragment = TRUE;
- gboolean firstFragment = TRUE;
+ fragment_data *fd_head = NULL;
+ tvbuff_t *next_tvb = NULL;
+ tvbuff_t *reassembled_tvb = NULL;
+ guint16 dst_ref = 0;
+ int start_offset = offset;
+ gboolean fragment = TRUE;
+ gboolean firstFragment = TRUE;
/* so we need to consume octet strings for the given length */
- if(out_tvb)
- *out_tvb=NULL;
+ if (out_tvb)
+ *out_tvb = NULL;
if (con_len == 0) /* Zero encodings (8.7.3) */
return offset;
@@ -1286,21 +1359,21 @@ reassemble_octet_string(asn1_ctx_t *actx, proto_tree *tree, gint hf_id, tvbuff_t
THROW(ReportedBoundsError);
}
- if(ind) {
+ if (ind) {
/* this was indefinite length - so check for EOC */
- if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0)) {
+ if ((tvb_get_guint8(tvb, offset) == 0) && (tvb_get_guint8(tvb, offset+1) == 0)) {
fragment = FALSE;
/* skip past EOC */
offset +=2;
}
} else {
- if((guint32)(offset - start_offset) >= con_len)
+ if ((guint32)(offset - start_offset) >= con_len)
fragment = FALSE;
}
- if(!fragment && firstFragment) {
+ if (!fragment && firstFragment) {
/* there is only one fragment (I'm sure there's a reason it was constructed) */
/* anyway, we can get out of here */
gboolean pc;
@@ -1327,8 +1400,8 @@ reassemble_octet_string(asn1_ctx_t *actx, proto_tree *tree, gint hf_id, tvbuff_t
firstFragment = FALSE;
}
- if(fd_head) {
- if(fd_head->next) {
+ if (fd_head) {
+ if (fd_head->next) {
/* not sure I really want to do this here - should be nearer the application where we can give it a better name*/
proto_tree *next_tree;
proto_item *frag_tree_item;
@@ -1343,7 +1416,7 @@ reassemble_octet_string(asn1_ctx_t *actx, proto_tree *tree, gint hf_id, tvbuff_t
}
}
- if(out_tvb)
+ if (out_tvb)
*out_tvb = reassembled_tvb;
/* again - not sure we need this */
@@ -1356,82 +1429,96 @@ reassemble_octet_string(asn1_ctx_t *actx, proto_tree *tree, gint hf_id, tvbuff_t
/* 8.7 Encoding of an octetstring value */
int
dissect_ber_constrained_octet_string(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, gint hf_id, tvbuff_t **out_tvb) {
- gint8 ber_class;
- gboolean pc, ind;
- gint32 tag;
- guint32 len;
- int hoffset;
- int end_offset;
+ gint8 ber_class;
+ gboolean pc, ind;
+ gint32 tag;
+ guint32 len;
+ int hoffset;
+ int end_offset;
proto_item *it, *cause;
- guint32 i;
- guint32 len_remain;
+ guint32 i;
+ guint32 len_remain;
#ifdef DEBUG_BER
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(tvb,offset)>3){
-printf("OCTET STRING dissect_ber_octet string(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n",name,implicit_tag,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
-}else{
-printf("OCTET STRING dissect_ber_octet_string(%s) entered\n",name);
+if (tvb_length_remaining(tvb, offset) > 3) {
+printf("OCTET STRING dissect_ber_octet string(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n", name, implicit_tag, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("OCTET STRING dissect_ber_octet_string(%s) entered\n", name);
}
}
#endif
- if(out_tvb)
- *out_tvb=NULL;
+ if (out_tvb)
+ *out_tvb = NULL;
if (!implicit_tag) {
hoffset = offset;
/* read header and len for the octet string */
- offset=dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
- offset=dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, &ind);
- end_offset=offset+len;
+ offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
+ offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, &ind);
+ end_offset = offset+len;
/* sanity check: we only handle Constructed Universal Sequences */
- if ((ber_class!=BER_CLASS_APP)&&(ber_class!=BER_CLASS_PRI))
-
- if( (ber_class!=BER_CLASS_UNI)
- ||((tag<BER_UNI_TAG_NumericString)&&(tag!=BER_UNI_TAG_OCTETSTRING)&&(tag!=BER_UNI_TAG_UTF8String)) ){
- tvb_ensure_bytes_exist(tvb, hoffset, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "octetstring_expected", "BER Error: OctetString expected but class:%s(%d) %s tag:%d was unexpected", val_to_str_const(ber_class,ber_class_codes,"Unknown"), ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: OctetString expected");
- if (decode_unexpected) {
- proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
- dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
+ if ((ber_class != BER_CLASS_APP) && (ber_class != BER_CLASS_PRI)) {
+ if ( (ber_class != BER_CLASS_UNI)
+ || ((tag < BER_UNI_TAG_NumericString) && (tag != BER_UNI_TAG_OCTETSTRING) && (tag != BER_UNI_TAG_UTF8String)) ) {
+ tvb_ensure_bytes_exist(tvb, hoffset, 2);
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "octetstring_expected",
+ "BER Error: OctetString expected but class:%s(%d) %s tag:%d was unexpected",
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: OctetString expected");
+ if (decode_unexpected) {
+ proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
+ dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
+ }
+ return end_offset;
}
- return end_offset;
}
} else {
- /* implicit tag so get from last tag/length */
+ /* implicit tag so get from last tag/length */
- get_last_ber_identifier(&ber_class, &pc, &tag);
- get_last_ber_length(&len, &ind);
+ get_last_ber_identifier(&ber_class, &pc, &tag);
+ get_last_ber_length(&len, &ind);
- end_offset=offset+len;
+ end_offset = offset+len;
- /* caller may have created new buffer for indefinite length data Verify via length */
- len_remain = (guint32)tvb_length_remaining(tvb, offset);
- if((ind) && (len_remain == len - 2)) {
+ /* caller may have created new buffer for indefinite length data Verify via length */
+ len_remain = (guint32)tvb_length_remaining(tvb, offset);
+ if (ind && (len_remain == (len - 2))) {
/* new buffer received so adjust length and indefinite flag */
- len -=2;
+ len -= 2;
end_offset -= 2;
ind = FALSE;
- } else if (len_remain < len) {
+ } else if (len_remain < len) {
/*
* error - short frame, or this item runs past the
* end of the item containing it
*/
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "illegal_length", "BER Error: length:%u longer than tvb_length_remaining:%d", len, len_remain);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error length");
- return end_offset;
- }
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "illegal_length",
+ "BER Error: length:%u longer than tvb_length_remaining:%d",
+ len,
+ len_remain);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error length");
+ return end_offset;
+ }
}
@@ -1446,31 +1533,31 @@ printf("OCTET STRING dissect_ber_octet_string(%s) entered\n",name);
length_remaining = tvb_length_remaining(tvb, offset);
#if 0
- if(length_remaining<1){
+ if (length_remaining < 1) {
return end_offset;
}
#endif
- if(len<=(guint32)length_remaining){
- length_remaining=len;
+ if (len <= (guint32)length_remaining) {
+ length_remaining = len;
}
- if(hf_id >= 0) {
+ if (hf_id >= 0) {
it = ber_proto_tree_add_item(actx->pinfo, tree, hf_id, tvb, offset, length_remaining, ENC_BIG_ENDIAN);
actx->created_item = it;
- ber_check_length(length_remaining, min_len, max_len, actx, it, ENC_BIG_ENDIAN);
+ ber_check_length(length_remaining, min_len, max_len, actx, it, FALSE);
} else {
proto_item *pi;
- pi=proto_tree_add_text(tree, tvb, offset, len, "Unknown OctetString: Length: 0x%02x, Value: 0x", len);
- if(pi){
- for(i=0;i<len;i++){
- proto_item_append_text(pi,"%02x",tvb_get_guint8(tvb, offset));
+ pi = proto_tree_add_text(tree, tvb, offset, len, "Unknown OctetString: Length: 0x%02x, Value: 0x", len);
+ if (pi) {
+ for (i=0; i<len; i++) {
+ proto_item_append_text(pi, "%02x", tvb_get_guint8(tvb, offset));
offset++;
}
}
}
- if(out_tvb) {
+ if (out_tvb) {
*out_tvb = tvb_new_subset(tvb, offset, length_remaining, len);
}
}
@@ -1482,12 +1569,13 @@ dissect_ber_octet_string(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tr
return dissect_ber_constrained_octet_string(implicit_tag, actx, tree, tvb, offset, NO_BOUND, NO_BOUND, hf_id, out_tvb);
}
-int dissect_ber_octet_string_wcb(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, ber_callback func)
+int
+dissect_ber_octet_string_wcb(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, ber_callback func)
{
tvbuff_t *out_tvb = NULL;
- offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_id, (func)?&out_tvb:NULL);
- if (func && out_tvb && (tvb_length(out_tvb)>0)) {
+ offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_id, (func) ? &out_tvb : NULL);
+ if (func && out_tvb && (tvb_length(out_tvb) > 0)) {
if (hf_id >= 0)
tree = proto_item_add_subtree(actx->created_item, ett_ber_octet_string);
/* TODO Should hf_id2 be pased as last parameter???*/
@@ -1496,12 +1584,13 @@ int dissect_ber_octet_string_wcb(gboolean implicit_tag, asn1_ctx_t *actx, proto_
return offset;
}
-int dissect_ber_old_octet_string_wcb(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, ber_old_callback func)
+int
+dissect_ber_old_octet_string_wcb(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, ber_old_callback func)
{
tvbuff_t *out_tvb = NULL;
- offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_id, (func)?&out_tvb:NULL);
- if (func && out_tvb && (tvb_length(out_tvb)>0)) {
+ offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_id, (func) ? &out_tvb : NULL);
+ if (func && out_tvb && (tvb_length(out_tvb) > 0)) {
if (hf_id >= 0)
tree = proto_item_add_subtree(actx->created_item, ett_ber_octet_string);
/* TODO Should hf_id2 be pased as last parameter???*/
@@ -1512,29 +1601,43 @@ int dissect_ber_old_octet_string_wcb(gboolean implicit_tag, asn1_ctx_t *actx, pr
/* 8.8 Encoding of a null value */
int
dissect_ber_null(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id) {
- gint8 ber_class;
- gboolean pc;
- gint32 tag;
- guint32 len;
- int offset_old;
+ gint8 ber_class;
+ gboolean pc;
+ gint32 tag;
+ guint32 len;
+ int offset_old;
proto_item* cause;
- if (!implicit_tag)
- {
+ if (!implicit_tag) {
offset_old = offset;
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
- if((pc) ||
- (!implicit_tag && ((ber_class != BER_CLASS_UNI) || (tag != BER_UNI_TAG_NULL)))) {
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset_old, offset - offset_old, "null_expected", "BER Error: NULL expected but class:%s(%d) %s tag:%d was unexpected", val_to_str_const(ber_class,ber_class_codes,"Unknown"), ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: NULL expected");
+ if (pc ||
+ (!implicit_tag && ((ber_class != BER_CLASS_UNI) || (tag != BER_UNI_TAG_NULL)))) {
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset_old, offset - offset_old, "null_expected",
+ "BER Error: NULL expected but class:%s(%d) %s tag:%d was unexpected",
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: NULL expected");
}
offset_old = offset;
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
- if(len) {
- proto_tree_add_string_format(tree, hf_ber_error, tvb, offset_old, offset - offset_old, "illegal_length", "BER Error: NULL expect zero length but Length=%d", len);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "unexpected_data", "BER Error: unexpected data in NULL type");
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: NULL expect zero length");
+ if (len) {
+ proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset_old, offset - offset_old, "illegal_length",
+ "BER Error: NULL expect zero length but Length=%d",
+ len);
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "unexpected_data",
+ "BER Error: unexpected data in NULL type");
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: NULL expect zero length");
offset += len;
}
}
@@ -1546,56 +1649,56 @@ dissect_ber_null(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbu
int
dissect_ber_integer64(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, gint64 *value)
{
- gint8 ber_class;
+ gint8 ber_class;
gboolean pc;
- gint32 tag;
- guint32 len;
- gint64 val;
- guint32 i;
+ gint32 tag;
+ guint32 len;
+ gint64 val;
+ guint32 i;
gboolean used_too_many_bytes = FALSE;
#ifdef DEBUG_BER
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(tvb,offset)>3){
-printf("INTEGERnew dissect_ber_integer(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n",name,implicit_tag,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
-}else{
-printf("INTEGERnew dissect_ber_integer(%s) entered implicit_tag:%d \n",name,implicit_tag);
+if (tvb_length_remaining(tvb, offset) > 3) {
+printf("INTEGERnew dissect_ber_integer(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n", name, implicit_tag, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("INTEGERnew dissect_ber_integer(%s) entered implicit_tag:%d \n", name, implicit_tag);
}
}
#endif
- if(value){
- *value=0;
+ if (value) {
+ *value = 0;
}
- if(!implicit_tag){
- offset=dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
- offset=dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
+ if (!implicit_tag) {
+ offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
+ offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
} else {
- gint32 remaining=tvb_length_remaining(tvb, offset);
- len=remaining>0 ? remaining : 0;
+ gint32 remaining = tvb_length_remaining(tvb, offset);
+ len = remaining>0 ? remaining : 0;
}
- /* we cant handle integers > 64 bits */
- if(len>8){
+ /* we can't handle integers > 64 bits */
+ if (len > 8) {
header_field_info *hfinfo;
- proto_item *pi = NULL;
+ proto_item *pi = NULL;
if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
- pi=proto_tree_add_text(tree, tvb, offset, len, "%s : 0x", hfinfo->name);
+ pi = proto_tree_add_text(tree, tvb, offset, len, "%s : 0x", hfinfo->name);
}
- if(pi){
- for(i=0;i<len;i++){
- proto_item_append_text(pi,"%02x",tvb_get_guint8(tvb, offset));
+ if (pi) {
+ for (i=0; i<len; i++) {
+ proto_item_append_text(pi, "%02x", tvb_get_guint8(tvb, offset));
offset++;
}
} else {
@@ -1605,69 +1708,75 @@ printf("INTEGERnew dissect_ber_integer(%s) entered implicit_tag:%d \n",name,impl
}
val=0;
- if(len > 0) {
+ if (len > 0) {
/* extend sign bit */
guint8 first = tvb_get_guint8(tvb, offset);
- if(first & 0x80){
- val=-1;
+ if (first & 0x80) {
+ val = -1;
}
- if(len > 1 && decode_warning_leading_zero_bits) {
+ if ((len > 1) && decode_warning_leading_zero_bits) {
guint8 second = tvb_get_guint8(tvb, offset+1);
- if((first == 0x00 && (second & 0x80) == 0) ||
- (first == 0xff && (second & 0x80)))
- {
+ if (((first == 0x00) && ((second & 0x80) == 0)) ||
+ ((first == 0xff) && ((second & 0x80) != 0))) {
used_too_many_bytes = TRUE;
}
}
- for(i=0;i<len;i++){
- val=(val<<8)|tvb_get_guint8(tvb, offset);
+ for (i=0; i<len; i++) {
+ val = (val<<8) | tvb_get_guint8(tvb, offset);
offset++;
}
}
- actx->created_item=NULL;
+ actx->created_item = NULL;
- if(hf_id >= 0){
+ if (hf_id >= 0) {
/* */
- if(len < 1 || len > 8) {
- proto_item *pi = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset-len, len, "invalid length", "BER Error: Can't handle integer length: %u", len);
- expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "BER Error: Illegal integer length: %u", len);
+ if ((len < 1) || (len > 8)) {
+ proto_item *pi = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset-len, len, "invalid length",
+ "BER Error: Can't handle integer length: %u",
+ len);
+ expert_add_info_format(
+ actx->pinfo, pi, PI_MALFORMED, PI_WARN,
+ "BER Error: Illegal integer length: %u", len);
} else {
header_field_info* hfi;
hfi = proto_registrar_get_nth(hf_id);
- switch(hfi->type){
+ switch (hfi->type) {
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
case FT_UINT32:
- actx->created_item=proto_tree_add_uint(tree, hf_id, tvb, offset-len, len, (guint32)val);
+ actx->created_item = proto_tree_add_uint(tree, hf_id, tvb, offset-len, len, (guint32)val);
break;
case FT_INT8:
case FT_INT16:
case FT_INT24:
case FT_INT32:
- actx->created_item=proto_tree_add_int(tree, hf_id, tvb, offset-len, len, (gint32)val);
+ actx->created_item = proto_tree_add_int(tree, hf_id, tvb, offset-len, len, (gint32)val);
break;
case FT_INT64:
- actx->created_item=proto_tree_add_int64(tree, hf_id, tvb, offset-len, len, val);
+ actx->created_item = proto_tree_add_int64(tree, hf_id, tvb, offset-len, len, val);
break;
case FT_UINT64:
- actx->created_item=proto_tree_add_uint64(tree, hf_id, tvb, offset-len, len, (guint64)val);
+ actx->created_item = proto_tree_add_uint64(tree, hf_id, tvb, offset-len, len, (guint64)val);
break;
default:
DISSECTOR_ASSERT_NOT_REACHED();
}
if (used_too_many_bytes) {
- expert_add_info_format(actx->pinfo, actx->created_item, PI_PROTOCOL, PI_WARN,
- "Value is encoded with too many bytes(9 leading zero or one bits), hf_abbr: %s",hfi->abbrev);
+ expert_add_info_format(
+ actx->pinfo, actx->created_item, PI_PROTOCOL, PI_WARN,
+ "Value is encoded with too many bytes(9 leading zero or one bits), hf_abbr: %s",
+ hfi->abbrev);
}
}
}
- if(value){
- *value=val;
+ if (value) {
+ *value = val;
}
return offset;
@@ -1678,9 +1787,9 @@ dissect_ber_constrained_integer64(gboolean implicit_tag, asn1_ctx_t *actx, proto
{
gint64 val;
- offset=dissect_ber_integer64(implicit_tag, actx, tree, tvb, offset, hf_id, &val);
- if(value){
- *value=val;
+ offset = dissect_ber_integer64(implicit_tag, actx, tree, tvb, offset, hf_id, &val);
+ if (value) {
+ *value = val;
}
ber_check_value64 (val, min_len, max_len, actx, actx->created_item);
@@ -1693,9 +1802,9 @@ dissect_ber_integer(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, t
{
gint64 val;
- offset=dissect_ber_integer64(implicit_tag, actx, tree, tvb, offset, hf_id, &val);
- if(value){
- *value=(guint32)val;
+ offset = dissect_ber_integer64(implicit_tag, actx, tree, tvb, offset, hf_id, &val);
+ if (value) {
+ *value = (guint32)val;
}
return offset;
@@ -1706,9 +1815,9 @@ dissect_ber_constrained_integer(gboolean implicit_tag, asn1_ctx_t *actx, proto_t
{
gint64 val;
- offset=dissect_ber_integer64(implicit_tag, actx, tree, tvb, offset, hf_id, &val);
- if(value){
- *value=(guint32)val;
+ offset = dissect_ber_integer64(implicit_tag, actx, tree, tvb, offset, hf_id, &val);
+ if (value) {
+ *value = (guint32)val;
}
ber_check_value ((guint32)val, min_len, max_len, actx, actx->created_item);
@@ -1719,36 +1828,36 @@ dissect_ber_constrained_integer(gboolean implicit_tag, asn1_ctx_t *actx, proto_t
int
dissect_ber_boolean(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, gboolean *value)
{
- gint8 ber_class;
+ gint8 ber_class;
gboolean pc;
- gint32 tag;
- guint32 len;
- guint8 val;
+ gint32 tag;
+ guint32 len;
+ guint8 val;
header_field_info *hfi;
- if(!implicit_tag){
- offset=dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
- offset=dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
- /*if(ber_class!=BER_CLASS_UNI)*/
+ if (!implicit_tag) {
+ offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
+ offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
+ /*if (ber_class != BER_CLASS_UNI)*/
} else {
/* nothing to do here, yet */
}
- val=tvb_get_guint8(tvb, offset);
- offset+=1;
+ val = tvb_get_guint8(tvb, offset);
+ offset += 1;
- actx->created_item=NULL;
+ actx->created_item = NULL;
- if(hf_id >= 0){
+ if (hf_id >= 0) {
hfi = proto_registrar_get_nth(hf_id);
- if(hfi->type == FT_BOOLEAN)
- actx->created_item=proto_tree_add_boolean(tree, hf_id, tvb, offset-1, 1, val);
+ if (hfi->type == FT_BOOLEAN)
+ actx->created_item = proto_tree_add_boolean(tree, hf_id, tvb, offset-1, 1, val);
else
- actx->created_item=proto_tree_add_uint(tree, hf_id, tvb, offset-1, 1, val?1:0);
+ actx->created_item = proto_tree_add_uint(tree, hf_id, tvb, offset-1, 1, val ? 1 : 0);
}
- if(value){
- *value=(val?TRUE:ENC_BIG_ENDIAN);
+ if (value) {
+ *value = (val ? TRUE : FALSE);
}
return offset;
@@ -1760,15 +1869,15 @@ dissect_ber_boolean(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, t
int
dissect_ber_real(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id _U_, double *value)
{
- gint8 ber_class;
+ gint8 ber_class;
gboolean pc;
- gint32 tag;
- guint32 val_length = 0, end_offset;
- double val = 0;
+ gint32 tag;
+ guint32 val_length = 0, end_offset;
+ double val = 0;
- if(!implicit_tag){
- offset=dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
- offset=dissect_ber_length(actx->pinfo, tree, tvb, offset, &val_length, NULL);
+ if (!implicit_tag) {
+ offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
+ offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &val_length, NULL);
} else {
/* 8.5.1 The encoding of a real value shall be primitive. */
DISSECTOR_ASSERT_NOT_REACHED();
@@ -1776,7 +1885,7 @@ dissect_ber_real(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbu
/* 8.5.2 If the real value is the value zero,
* there shall be no contents octets in the encoding.
*/
- if (val_length==0){
+ if (val_length == 0) {
if (value)
*value = 0;
return offset;
@@ -1786,66 +1895,68 @@ dissect_ber_real(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbu
val = asn1_get_real(tvb_get_ptr(tvb, offset, val_length), val_length);
actx->created_item = proto_tree_add_double(tree, hf_id, tvb, offset, val_length, val);
- if (value) *value = val;
+ if (value)
+ *value = val;
return end_offset;
}
/* this function dissects a BER sequence
*/
-int dissect_ber_sequence(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
- gint8 classx;
- gboolean pcx, ind = 0, ind_field, imp_tag=FALSE;
- gint32 tagx;
- guint32 lenx;
- proto_tree *tree = parent_tree;
- proto_item *item = NULL;
+int
+dissect_ber_sequence(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
+ gint8 classx;
+ gboolean pcx, ind = 0, ind_field, imp_tag = FALSE;
+ gint32 tagx;
+ guint32 lenx;
+ proto_tree *tree = parent_tree;
+ proto_item *item = NULL;
proto_item *cause;
- int end_offset = 0;
- int hoffset;
- gint length_remaining;
- tvbuff_t *next_tvb;
+ int end_offset = 0;
+ int hoffset;
+ gint length_remaining;
+ tvbuff_t *next_tvb;
#ifdef DEBUG_BER
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(tvb,offset)>3){
-printf("SEQUENCE dissect_ber_sequence(%s) entered offset:%d len:%d %02x:%02x:%02x\n",name,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
-}else{
-printf("SEQUENCE dissect_ber_sequence(%s) entered\n",name);
+if (tvb_length_remaining(tvb, offset) > 3) {
+printf("SEQUENCE dissect_ber_sequence(%s) entered offset:%d len:%d %02x:%02x:%02x\n", name, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("SEQUENCE dissect_ber_sequence(%s) entered\n", name);
}
}
#endif
hoffset = offset;
- if(!implicit_tag) {
+ if (!implicit_tag) {
offset = get_ber_identifier(tvb, offset, NULL, NULL, NULL);
offset = get_ber_length(tvb, offset, &lenx, NULL);
} else {
/* was implicit tag so just use the length of the tvb */
- lenx=tvb_length_remaining(tvb,offset);
- end_offset=offset+lenx;
+ lenx = tvb_length_remaining(tvb, offset);
+ end_offset = offset+lenx;
}
/* create subtree */
- if(hf_id >= 0) {
- if(parent_tree){
+ if (hf_id >= 0) {
+ if (parent_tree) {
item = proto_tree_add_item(parent_tree, hf_id, tvb, hoffset, lenx + offset - hoffset, ENC_BIG_ENDIAN);
tree = proto_item_add_subtree(item, ett_id);
}
}
offset = hoffset;
- if(!implicit_tag){
+ if (!implicit_tag) {
/* first we must read the sequence header */
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &classx, &pcx, &tagx);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &lenx, &ind);
- if(ind){
+ if (ind) {
/* Fixed the length is correctly returned from dissect ber_length
end_offset = tvb_length(tvb);*/
end_offset = offset + lenx -2;
@@ -1854,44 +1965,52 @@ printf("SEQUENCE dissect_ber_sequence(%s) entered\n",name);
}
/* sanity check: we only handle Constructed Universal Sequences */
- if((classx!=BER_CLASS_APP)&&(classx!=BER_CLASS_PRI))
- if((!pcx)
- ||(!implicit_tag&&((classx!=BER_CLASS_UNI)
- ||(tagx!=BER_UNI_TAG_SEQUENCE)))) {
- tvb_ensure_bytes_exist(tvb, hoffset, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, lenx, "sequence_expected", "BER Error: Sequence expected but class:%s(%d) %s tag:%d was unexpected", val_to_str_const(classx,ber_class_codes,"Unknown"), classx, pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tagx);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Sequence expected");
- if (decode_unexpected) {
- proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
- dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
+ if ((classx != BER_CLASS_APP) && (classx != BER_CLASS_PRI)) {
+ if (!pcx
+ || (!implicit_tag && ((classx != BER_CLASS_UNI) || (tagx != BER_UNI_TAG_SEQUENCE)))) {
+ tvb_ensure_bytes_exist(tvb, hoffset, 2);
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, lenx, "sequence_expected",
+ "BER Error: Sequence expected but class:%s(%d) %s tag:%d was unexpected",
+ val_to_str_const(classx, ber_class_codes, "Unknown"),
+ classx,
+ pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tagx);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Sequence expected");
+ if (decode_unexpected) {
+ proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
+ dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
+ }
+ return end_offset;
}
- return end_offset;
}
}
/* loop over all entries until we reach the end of the sequence */
- while (offset < end_offset){
- gint8 ber_class;
+ while (offset < end_offset) {
+ gint8 ber_class;
gboolean pc;
- gint32 tag;
- guint32 len;
- int eoffset, count;
+ gint32 tag;
+ guint32 len;
+ int eoffset, count;
- /*if(ind){ this sequence was of indefinite length, if this is implicit indefinite impossible maybe
+ /*if (ind) { this sequence was of indefinite length, if this is implicit indefinite impossible maybe
but ber dissector uses this to eat the tag length then pass into here... EOC still on there...*/
- if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0)){
+ if ((tvb_get_guint8(tvb, offset) == 0) && (tvb_get_guint8(tvb, offset+1) == 0)) {
/* If the first bytes is 00 00 of a indefenert length field it's a zero length field*/
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, &ind);
- proto_item_append_text(item," 0 items");
+ proto_item_append_text(item, " 0 items");
return end_offset;
/*
- if(show_internal_ber_fields){
+ if (show_internal_ber_fields) {
proto_tree_add_text(tree, tvb, s_offset, offset+2, "ERROR WRONG SEQ EOC");
}
return end_offset;
*/
}
- /*}*/
+ /* } */
hoffset = offset;
/* read header and len for next field */
offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
@@ -1901,7 +2020,7 @@ printf("SEQUENCE dissect_ber_sequence(%s) entered\n",name);
if (eoffset <= hoffset)
THROW(ReportedBoundsError);
- /*if(ind_field && (len == 2)){
+ /*if (ind_field && (len == 2)) {
/ disgusting indefinite length zero length field, what are these people doing /
offset = eoffset;
continue;
@@ -1910,22 +2029,26 @@ printf("SEQUENCE dissect_ber_sequence(%s) entered\n",name);
ber_sequence_try_again:
/* have we run out of known entries in the sequence ?*/
- if(!seq->func) {
+ if (!seq->func) {
/* it was not, move to the next one and try again */
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, NULL, NULL);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "unknown_field", "BER Error: This field lies beyond the end of the known sequence definition.");
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Unknown field in Sequence");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "unknown_field",
+ "BER Error: This field lies beyond the end of the known sequence definition.");
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Unknown field in Sequence");
if (decode_unexpected) {
- proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
- dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
+ proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
+ dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
}
offset = eoffset;
continue;
}
/* Verify that this one is the one we want.
- * Skip check completely if ber_class==ANY
+ * Skip check completely if ber_class == ANY
* of if NOCHKTAG is set
*/
/* XXX Bug in asn2eth,
@@ -1934,48 +2057,63 @@ ber_sequence_try_again:
* { BER_CLASS_CON, 7, BER_FLAGS_OPTIONAL|BER_FLAGS_NOTCHKTAG, dissect_scope },
* and there should not be a NOTCHKTAG here
*/
- if( ((seq->ber_class==BER_CLASS_CON)||(seq->ber_class==BER_CLASS_APP)||(seq->ber_class==BER_CLASS_PRI)) && (!(seq->flags&BER_FLAGS_NOOWNTAG)) ){
- if( (seq->ber_class!=BER_CLASS_ANY)
- && (seq->tag!=-1)
- &&( (seq->ber_class!=ber_class)
- ||(seq->tag!=tag) ) ){
+ if ( ((seq->ber_class == BER_CLASS_CON) || (seq->ber_class == BER_CLASS_APP) || (seq->ber_class == BER_CLASS_PRI))
+ && (!(seq->flags & BER_FLAGS_NOOWNTAG)) ) {
+ if ( (seq->ber_class != BER_CLASS_ANY)
+ && (seq->tag != -1)
+ && ( (seq->ber_class != ber_class)
+ || (seq->tag != tag) ) ) {
/* it was not, move to the next one and try again */
- if(seq->flags&BER_FLAGS_OPTIONAL){
+ if (seq->flags & BER_FLAGS_OPTIONAL) {
/* well this one was optional so just skip to the next one and try again. */
seq++;
goto ber_sequence_try_again;
}
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, NULL, NULL);
- if( seq->ber_class == BER_CLASS_UNI){
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "wrong_field",
- "BER Error: Wrong field in SEQUENCE expected class:%s(%d) tag:%d (%s) but found class:%s(%d) tag:%d",
- val_to_str_const(seq->ber_class,ber_class_codes,"Unknown"),seq->ber_class,
- seq->tag,val_to_str_ext_const(seq->tag,&ber_uni_tag_codes_ext,"Unknown"),
- val_to_str_const(ber_class,ber_class_codes,"Unknown"),ber_class,tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Wrong field in SEQUENCE");
- }else{
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "wrong_field",
- "BER Error: Wrong field in SEQUENCE expected class:%s(%d) tag:%d but found class:%s(%d) tag:%d",
- val_to_str_const(seq->ber_class,ber_class_codes,"Unknown"),seq->ber_class,
- seq->tag,val_to_str_const(ber_class,ber_class_codes,"Unknown"),ber_class,tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Wrong field in SEQUENCE");
+ if (seq->ber_class == BER_CLASS_UNI) {
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "wrong_field",
+ "BER Error: Wrong field in SEQUENCE expected class:%s(%d) tag:%d (%s) but found class:%s(%d) tag:%d",
+ val_to_str_const(seq->ber_class, ber_class_codes, "Unknown"),
+ seq->ber_class,
+ seq->tag,
+ val_to_str_ext_const(seq->tag, &ber_uni_tag_codes_ext, "Unknown"),
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Wrong field in SEQUENCE");
+ } else {
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "wrong_field",
+ "BER Error: Wrong field in SEQUENCE expected class:%s(%d) tag:%d but found class:%s(%d) tag:%d",
+ val_to_str_const(seq->ber_class, ber_class_codes, "Unknown"),
+ seq->ber_class,
+ seq->tag,
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Wrong field in SEQUENCE");
}
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
}
seq++;
- offset=eoffset;
+ offset = eoffset;
continue;
}
- } else if(!(seq->flags & BER_FLAGS_NOTCHKTAG)) {
- if( (seq->ber_class!=BER_CLASS_ANY)
- && (seq->tag!=-1)
- &&( (seq->ber_class!=ber_class)
- ||(seq->tag!=tag) ) ){
+ } else if (!(seq->flags & BER_FLAGS_NOTCHKTAG)) {
+ if ( (seq->ber_class != BER_CLASS_ANY)
+ && (seq->tag != -1)
+ && ( (seq->ber_class != ber_class)
+ || (seq->tag != tag) ) ) {
/* it was not, move to the next one and try again */
- if(seq->flags&BER_FLAGS_OPTIONAL){
+ if (seq->flags & BER_FLAGS_OPTIONAL) {
/* well this one was optional so just skip to the next one and try again. */
seq++;
goto ber_sequence_try_again;
@@ -1983,54 +2121,72 @@ ber_sequence_try_again:
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, NULL, NULL);
- if( seq->ber_class == BER_CLASS_UNI){
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "wrong_field", "BER Error: Wrong field in sequence expected class:%s(%d) tag:%d(%s) but found class:%s(%d) tag:%d",
- val_to_str_const(seq->ber_class,ber_class_codes,"Unknown"),seq->ber_class,seq->tag,val_to_str_ext_const(seq->tag,&ber_uni_tag_codes_ext,"Unknown"),val_to_str_const(ber_class,ber_class_codes,"Unknown"),ber_class,tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Wrong field in sequence");
- }else{
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "wrong_field", "BER Error: Wrong field in sequence expected class:%s(%d) tag:%d but found class:%s(%d) tag:%d",val_to_str_const(seq->ber_class,ber_class_codes,"Unknown"),seq->ber_class,seq->tag,val_to_str_const(ber_class,ber_class_codes,"Unknown"),ber_class,tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Wrong field in sequence");
+ if ( seq->ber_class == BER_CLASS_UNI) {
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "wrong_field",
+ "BER Error: Wrong field in sequence expected class:%s(%d) tag:%d(%s) but found class:%s(%d) tag:%d",
+ val_to_str_const(seq->ber_class, ber_class_codes, "Unknown"),
+ seq->ber_class,
+ seq->tag,
+ val_to_str_ext_const(seq->tag, &ber_uni_tag_codes_ext, "Unknown"),
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class, tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Wrong field in sequence");
+ } else {
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "wrong_field",
+ "BER Error: Wrong field in sequence expected class:%s(%d) tag:%d but found class:%s(%d) tag:%d",
+ val_to_str_const(seq->ber_class, ber_class_codes, "Unknown"),
+ seq->ber_class,
+ seq->tag,
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Wrong field in sequence");
}
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
}
seq++;
- offset=eoffset;
+ offset = eoffset;
continue;
}
}
- if(!(seq->flags & BER_FLAGS_NOOWNTAG) ) {
+ if (!(seq->flags & BER_FLAGS_NOOWNTAG) ) {
/* dissect header and len for field */
- if(ind_field && (len == 2)){
+ if (ind_field && (len == 2)) {
/* This is a Zero length field */
next_tvb = tvb_new_subset(tvb, offset, len, len);
hoffset = eoffset;
- }else{
+ } else {
hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
hoffset = dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
- length_remaining=tvb_length_remaining(tvb, hoffset);
- if (length_remaining>eoffset-hoffset-(2*ind_field))
- length_remaining=eoffset-hoffset-(2*ind_field);
- next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset-hoffset-(2*ind_field));
+ length_remaining = tvb_length_remaining(tvb, hoffset);
+ if (length_remaining > (eoffset - hoffset - (2 * ind_field)))
+ length_remaining = eoffset - hoffset - (2 * ind_field);
+ next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset - hoffset - (2 * ind_field));
}
- }
- else {
- length_remaining=tvb_length_remaining(tvb, hoffset);
- if (length_remaining>eoffset-hoffset)
- length_remaining=eoffset-hoffset;
- next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset-hoffset);
+ } else {
+ length_remaining = tvb_length_remaining(tvb, hoffset);
+ if (length_remaining > (eoffset - hoffset))
+ length_remaining = eoffset - hoffset;
+ next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset - hoffset);
}
#if 0
/* call the dissector for this field */
- if ((eoffset-hoffset)>length_remaining) {
- /* If the field is indefinite (i.e. we dont know the
+ if ((eoffset-hoffset) > length_remaining) {
+ /* If the field is indefinite (i.e. we don't know the
* length) of if the tvb is short, then just
* give it all of the tvb and hope for the best.
*/
- next_tvb = tvb_new_subset_remaining(tvb, hoffset);
+ next_tvb = tvb_new_subset_remaining(tvb, hoffset);
} else {
}
@@ -2040,16 +2196,16 @@ ber_sequence_try_again:
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(next_tvb,0)>3){
-printf("SEQUENCE dissect_ber_sequence(%s) calling subdissector offset:%d len:%d %02x:%02x:%02x\n",name,offset,tvb_length_remaining(next_tvb,0),tvb_get_guint8(next_tvb,0),tvb_get_guint8(next_tvb,1),tvb_get_guint8(next_tvb,2));
-}else{
-printf("SEQUENCE dissect_ber_sequence(%s) calling subdissector\n",name);
+if (tvb_length_remaining(next_tvb, 0) > 3) {
+printf("SEQUENCE dissect_ber_sequence(%s) calling subdissector offset:%d len:%d %02x:%02x:%02x\n", name, offset, tvb_length_remaining(next_tvb, 0), tvb_get_guint8(next_tvb, 0), tvb_get_guint8(next_tvb, 1), tvb_get_guint8(next_tvb, 2));
+} else {
+printf("SEQUENCE dissect_ber_sequence(%s) calling subdissector\n", name);
}
}
#endif
@@ -2057,42 +2213,42 @@ printf("SEQUENCE dissect_ber_sequence(%s) calling subdissector\n",name);
/* Assume that we have a malformed packet. */
THROW(ReportedBoundsError);
}
- imp_tag=FALSE;
- if (seq->flags & BER_FLAGS_IMPLTAG){
+ imp_tag = FALSE;
+ if (seq->flags & BER_FLAGS_IMPLTAG) {
imp_tag = TRUE;
}
- count=seq->func(imp_tag, next_tvb, 0, actx, tree, *seq->p_id);
+ count = seq->func(imp_tag, next_tvb, 0, actx, tree, *seq->p_id);
#ifdef DEBUG_BER
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-printf("SEQUENCE dissect_ber_sequence(%s) subdissector ate %d bytes\n",name,count);
+printf("SEQUENCE dissect_ber_sequence(%s) subdissector ate %d bytes\n", name, count);
}
#endif
/* if it was optional and no bytes were eaten and it was */
- /* supposed to (len<>0), just try again. */
- if((len!=0)&&(count==0)&&(seq->flags&BER_FLAGS_OPTIONAL)){
+ /* supposed to (len <> 0), just try again. */
+ if ((len != 0) && (count == 0) && (seq->flags & BER_FLAGS_OPTIONAL)) {
seq++;
goto ber_sequence_try_again;
/* move the offset to the beginning of the next sequenced item */
}
offset = eoffset;
- if(!(seq->flags & BER_FLAGS_NOOWNTAG) ) {
+ if (!(seq->flags & BER_FLAGS_NOOWNTAG) ) {
/* if we stripped the tag and length we should also strip the EOC is ind_len
* Unless its a zero length field (len = 2)
*/
- if((ind_field == 1)&&(len>2))
+ if ((ind_field == 1) && (len > 2))
{
/* skip over EOC */
- if(show_internal_ber_fields){
+ if (show_internal_ber_fields) {
proto_tree_add_text(tree, tvb, offset, count, "SEQ FIELD EOC");
}
}
@@ -2101,75 +2257,80 @@ printf("SEQUENCE dissect_ber_sequence(%s) subdissector ate %d bytes\n",name,coun
}
/* if we didnt end up at exactly offset, then we ate too many bytes */
- if(offset != end_offset) {
+ if (offset != end_offset) {
tvb_ensure_bytes_exist(tvb, offset-2, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset-2, 2, "illegal_length", "BER Error: Sequence ate %d too many bytes", offset-end_offset);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: too many bytes in Sequence");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset-2, 2, "illegal_length",
+ "BER Error: Sequence ate %d too many bytes",
+ offset - end_offset);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: too many bytes in Sequence");
}
- if(ind){
+ if (ind) {
/* need to eat this EOC
end_offset = tvb_length(tvb);*/
end_offset += 2;
- if(show_internal_ber_fields){
- proto_tree_add_text(tree, tvb, end_offset-2,2 , "SEQ EOC");
+ if (show_internal_ber_fields) {
+ proto_tree_add_text(tree, tvb, end_offset-2, 2 , "SEQ EOC");
}
}
return end_offset;
}
-
-int dissect_ber_old_sequence(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_old_sequence_t *seq, gint hf_id, gint ett_id) {
- gint8 classx;
- gboolean pcx, ind = 0, ind_field;
- gint32 tagx;
- guint32 lenx;
- proto_tree *tree = parent_tree;
- proto_item *item = NULL;
+int
+dissect_ber_old_sequence(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_old_sequence_t *seq, gint hf_id, gint ett_id) {
+ gint8 classx;
+ gboolean pcx, ind = 0, ind_field;
+ gint32 tagx;
+ guint32 lenx;
+ proto_tree *tree = parent_tree;
+ proto_item *item = NULL;
proto_item *cause;
- int end_offset = 0;
- int hoffset;
- gint length_remaining;
- tvbuff_t *next_tvb;
+ int end_offset = 0;
+ int hoffset;
+ gint length_remaining;
+ tvbuff_t *next_tvb;
#ifdef DEBUG_BER
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(tvb,offset)>3){
-printf("SEQUENCE dissect_ber_old_sequence(%s) entered offset:%d len:%d %02x:%02x:%02x\n",name,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
-}else{
-printf("SEQUENCE dissect_ber_old_sequence(%s) entered\n",name);
+if (tvb_length_remaining(tvb, offset) > 3) {
+printf("SEQUENCE dissect_ber_old_sequence(%s) entered offset:%d len:%d %02x:%02x:%02x\n", name, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("SEQUENCE dissect_ber_old_sequence(%s) entered\n", name);
}
}
#endif
hoffset = offset;
- if(!implicit_tag) {
+ if (!implicit_tag) {
offset = get_ber_identifier(tvb, offset, NULL, NULL, NULL);
offset = get_ber_length(tvb, offset, &lenx, NULL);
} else {
/* was implicit tag so just use the length of the tvb */
- lenx=tvb_length_remaining(tvb,offset);
- end_offset=offset+lenx;
+ lenx = tvb_length_remaining(tvb, offset);
+ end_offset = offset+lenx;
}
/* create subtree */
- if(hf_id >= 0) {
- if(parent_tree){
+ if (hf_id >= 0) {
+ if (parent_tree) {
item = proto_tree_add_item(parent_tree, hf_id, tvb, hoffset, lenx + offset - hoffset, ENC_BIG_ENDIAN);
tree = proto_item_add_subtree(item, ett_id);
}
}
offset = hoffset;
- if(!implicit_tag){
+ if (!implicit_tag) {
/* first we must read the sequence header */
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &classx, &pcx, &tagx);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &lenx, &ind);
- if(ind){
+ if (ind) {
/* Fixed the length is correctly returned from dissect ber_length
end_offset = tvb_length(tvb);*/
end_offset = offset + lenx -2;
@@ -2178,44 +2339,52 @@ printf("SEQUENCE dissect_ber_old_sequence(%s) entered\n",name);
}
/* sanity check: we only handle Constructed Universal Sequences */
- if((classx!=BER_CLASS_APP)&&(classx!=BER_CLASS_PRI))
- if((!pcx)
- ||(!implicit_tag&&((classx!=BER_CLASS_UNI)
- ||(tagx!=BER_UNI_TAG_SEQUENCE)))) {
- tvb_ensure_bytes_exist(tvb, hoffset, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, lenx, "sequence_expected", "BER Error: Sequence expected but class:%s(%d) %s tag:%d was unexpected", val_to_str_const(classx,ber_class_codes,"Unknown"), classx, pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tagx);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Sequence expected");
- if (decode_unexpected) {
- proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
- dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
+ if ((classx != BER_CLASS_APP) && (classx != BER_CLASS_PRI)) {
+ if (!pcx
+ || (!implicit_tag && ((classx != BER_CLASS_UNI) || (tagx != BER_UNI_TAG_SEQUENCE)))) {
+ tvb_ensure_bytes_exist(tvb, hoffset, 2);
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, lenx, "sequence_expected",
+ "BER Error: Sequence expected but class:%s(%d) %s tag:%d was unexpected",
+ val_to_str_const(classx, ber_class_codes, "Unknown"),
+ classx,
+ pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tagx);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Sequence expected");
+ if (decode_unexpected) {
+ proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
+ dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
+ }
+ return end_offset;
}
- return end_offset;
}
}
/* loop over all entries until we reach the end of the sequence */
- while (offset < end_offset){
- gint8 ber_class;
+ while (offset < end_offset) {
+ gint8 ber_class;
gboolean pc;
- gint32 tag;
- guint32 len;
- int eoffset, count;
+ gint32 tag;
+ guint32 len;
+ int eoffset, count;
- /*if(ind){ this sequence was of indefinite length, if this is implicit indefinite impossible maybe
+ /*if (ind) { this sequence was of indefinite length, if this is implicit indefinite impossible maybe
but ber dissector uses this to eat the tag length then pass into here... EOC still on there...*/
- if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0)){
- /* If the first bytes is 00 00 of a indefenert length field it's a zero length field*/
+ if ((tvb_get_guint8(tvb, offset) == 0) && (tvb_get_guint8(tvb, offset+1) == 0)) {
+ /* If the first bytes are 00 00 in an indefinite length field, it's a zero length field */
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, &ind);
- proto_item_append_text(item," 0 items");
+ proto_item_append_text(item, " 0 items");
return end_offset;
/*
- if(show_internal_ber_fields){
+ if (show_internal_ber_fields) {
proto_tree_add_text(tree, tvb, s_offset, offset+2, "ERROR WRONG SEQ EOC");
}
return end_offset;
*/
}
- /*}*/
+ /* } */
hoffset = offset;
/* read header and len for next field */
offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
@@ -2225,7 +2394,7 @@ printf("SEQUENCE dissect_ber_old_sequence(%s) entered\n",name);
if (eoffset <= hoffset)
THROW(ReportedBoundsError);
- /*if(ind_field && (len == 2)){
+ /*if (ind_field && (len == 2)) {
/ disgusting indefinite length zero length field, what are these people doing /
offset = eoffset;
continue;
@@ -2234,12 +2403,16 @@ printf("SEQUENCE dissect_ber_old_sequence(%s) entered\n",name);
ber_old_sequence_try_again:
/* have we run out of known entries in the sequence ?*/
- if(!seq->func) {
+ if (!seq->func) {
/* it was not, move to the next one and try again */
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, NULL, NULL);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "illegal_length", "BER Error: This field lies beyond the end of the known sequence definition.");
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Unknown field in Sequence");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "illegal_length",
+ "BER Error: This field lies beyond the end of the known sequence definition.");
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Unknown field in Sequence");
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
@@ -2249,7 +2422,7 @@ ber_old_sequence_try_again:
}
/* Verify that this one is the one we want.
- * Skip check completely if ber_class==ANY
+ * Skip check completely if ber_class == ANY
* of if NOCHKTAG is set
*/
/* XXX Bug in asn2eth,
@@ -2258,48 +2431,63 @@ ber_old_sequence_try_again:
* { BER_CLASS_CON, 7, BER_FLAGS_OPTIONAL|BER_FLAGS_NOTCHKTAG, dissect_scope },
* and there should not be a NOTCHKTAG here
*/
- if( ((seq->ber_class==BER_CLASS_CON)||(seq->ber_class==BER_CLASS_APP)||(seq->ber_class==BER_CLASS_PRI)) && (!(seq->flags&BER_FLAGS_NOOWNTAG)) ){
- if( (seq->ber_class!=BER_CLASS_ANY)
- && (seq->tag!=-1)
- &&( (seq->ber_class!=ber_class)
- ||(seq->tag!=tag) ) ){
+ if ( ((seq->ber_class == BER_CLASS_CON) || (seq->ber_class == BER_CLASS_APP) || (seq->ber_class == BER_CLASS_PRI))
+ && (!(seq->flags & BER_FLAGS_NOOWNTAG)) ) {
+ if ( (seq->ber_class != BER_CLASS_ANY)
+ && (seq->tag != -1)
+ && ( (seq->ber_class != ber_class)
+ || (seq->tag != tag) ) ) {
/* it was not, move to the next one and try again */
- if(seq->flags&BER_FLAGS_OPTIONAL){
+ if (seq->flags & BER_FLAGS_OPTIONAL) {
/* well this one was optional so just skip to the next one and try again. */
seq++;
goto ber_old_sequence_try_again;
}
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, NULL, NULL);
- if( seq->ber_class == BER_CLASS_UNI){
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "wrong_field",
- "BER Error: Wrong field in SEQUENCE expected class:%s(%d) tag:%d (%s) but found class:%s(%d) tag:%d",
- val_to_str_const(seq->ber_class,ber_class_codes,"Unknown"),seq->ber_class,
- seq->tag,val_to_str_ext_const(seq->tag,&ber_uni_tag_codes_ext,"Unknown"),
- val_to_str_const(ber_class,ber_class_codes,"Unknown"),ber_class,tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Wrong field in SEQUENCE");
- }else{
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "wrong_field"
- "BER Error: Wrong field in SEQUENCE expected class:%s(%d) tag:%d but found class:%s(%d) tag:%d",
- val_to_str_const(seq->ber_class,ber_class_codes,"Unknown"),seq->ber_class,
- seq->tag,val_to_str_const(ber_class,ber_class_codes,"Unknown"),ber_class,tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Wrong field in SEQUENCE");
+ if ( seq->ber_class == BER_CLASS_UNI) {
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "wrong_field",
+ "BER Error: Wrong field in SEQUENCE expected class:%s(%d) tag:%d (%s) but found class:%s(%d) tag:%d",
+ val_to_str_const(seq->ber_class, ber_class_codes, "Unknown"),
+ seq->ber_class,
+ seq->tag,
+ val_to_str_ext_const(seq->tag, &ber_uni_tag_codes_ext, "Unknown"),
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Wrong field in SEQUENCE");
+ } else {
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "wrong_field"
+ "BER Error: Wrong field in SEQUENCE expected class:%s(%d) tag:%d but found class:%s(%d) tag:%d",
+ val_to_str_const(seq->ber_class, ber_class_codes, "Unknown"),
+ seq->ber_class,
+ seq->tag,
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED,
+ PI_WARN, "BER Error: Wrong field in SEQUENCE");
}
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
}
seq++;
- offset=eoffset;
+ offset = eoffset;
continue;
}
- } else if(!(seq->flags & BER_FLAGS_NOTCHKTAG)) {
- if( (seq->ber_class!=BER_CLASS_ANY)
- && (seq->tag!=-1)
- &&( (seq->ber_class!=ber_class)
- ||(seq->tag!=tag) ) ){
+ } else if (!(seq->flags & BER_FLAGS_NOTCHKTAG)) {
+ if ( (seq->ber_class != BER_CLASS_ANY)
+ && (seq->tag != -1)
+ && ( (seq->ber_class != ber_class)
+ || (seq->tag != tag) ) ) {
/* it was not, move to the next one and try again */
- if(seq->flags&BER_FLAGS_OPTIONAL){
+ if (seq->flags & BER_FLAGS_OPTIONAL) {
/* well this one was optional so just skip to the next one and try again. */
seq++;
goto ber_old_sequence_try_again;
@@ -2307,50 +2495,70 @@ ber_old_sequence_try_again:
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, NULL, NULL);
- if( seq->ber_class == BER_CLASS_UNI){
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "wrong_field", "BER Error: Wrong field in sequence expected class:%s(%d) tag:%d(%s) but found class:%s(%d) tag:%d",
- val_to_str_const(seq->ber_class,ber_class_codes,"Unknown"),seq->ber_class,seq->tag,val_to_str_ext_const(seq->tag,&ber_uni_tag_codes_ext,"Unknown"),val_to_str_const(ber_class,ber_class_codes,"Unknown"),ber_class,tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Wrong field in sequence");
- }else{
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "wrong_field", "BER Error: Wrong field in sequence expected class:%s(%d) tag:%d but found class:%s(%d) tag:%d",val_to_str_const(seq->ber_class,ber_class_codes,"Unknown"),seq->ber_class,seq->tag,val_to_str_const(ber_class,ber_class_codes,"Unknown"),ber_class,tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Wrong field in sequence");
+ if ( seq->ber_class == BER_CLASS_UNI) {
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "wrong_field",
+ "BER Error: Wrong field in sequence expected class:%s(%d) tag:%d(%s) but found class:%s(%d) tag:%d",
+ val_to_str_const(seq->ber_class, ber_class_codes, "Unknown"),
+ seq->ber_class,
+ seq->tag,
+ val_to_str_ext_const(seq->tag, &ber_uni_tag_codes_ext, "Unknown"),
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED,
+ PI_WARN, "BER Error: Wrong field in sequence");
+ } else {
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "wrong_field",
+ "BER Error: Wrong field in sequence expected class:%s(%d) tag:%d but found class:%s(%d) tag:%d",
+ val_to_str_const(seq->ber_class, ber_class_codes, "Unknown"),
+ seq->ber_class,
+ seq->tag,
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Wrong field in sequence");
}
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
}
seq++;
- offset=eoffset;
+ offset = eoffset;
continue;
}
}
- if(!(seq->flags & BER_FLAGS_NOOWNTAG) ) {
+ if (!(seq->flags & BER_FLAGS_NOOWNTAG) ) {
/* dissect header and len for field */
- if(ind_field && (len == 2)){
+ if (ind_field && (len == 2)) {
/* This is a Zero length field */
next_tvb = tvb_new_subset(tvb, offset, len, len);
- hoffset = eoffset;
- }else{
- hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
- hoffset = dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
- length_remaining=tvb_length_remaining(tvb, hoffset);
- if (length_remaining>eoffset-hoffset-(2*ind_field))
- length_remaining=eoffset-hoffset-(2*ind_field);
- next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset-hoffset-(2*ind_field));
+ hoffset = eoffset;
+ } else {
+ hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
+ hoffset = dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
+ length_remaining = tvb_length_remaining(tvb, hoffset);
+ if (length_remaining > (eoffset - hoffset - (2 * ind_field)))
+ length_remaining = eoffset - hoffset - (2 * ind_field);
+ next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset - hoffset - (2 * ind_field));
}
}
else {
- length_remaining=tvb_length_remaining(tvb, hoffset);
- if (length_remaining>eoffset-hoffset)
- length_remaining=eoffset-hoffset;
- next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset-hoffset);
+ length_remaining = tvb_length_remaining(tvb, hoffset);
+ if (length_remaining > (eoffset - hoffset))
+ length_remaining = eoffset - hoffset;
+ next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset - hoffset);
}
#if 0
/* call the dissector for this field */
- if ((eoffset-hoffset)>length_remaining) {
- /* If the field is indefinite (i.e. we dont know the
+ if ((eoffset-hoffset) > length_remaining) {
+ /* If the field is indefinite (i.e. we don't know the
* length) of if the tvb is short, then just
* give it all of the tvb and hope for the best.
*/
@@ -2364,16 +2572,16 @@ ber_old_sequence_try_again:
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(next_tvb,0)>3){
-printf("SEQUENCE dissect_ber_old_sequence(%s) calling subdissector offset:%d len:%d %02x:%02x:%02x\n",name,offset,tvb_length_remaining(next_tvb,0),tvb_get_guint8(next_tvb,0),tvb_get_guint8(next_tvb,1),tvb_get_guint8(next_tvb,2));
-}else{
-printf("SEQUENCE dissect_ber_old_sequence(%s) calling subdissector\n",name);
+if (tvb_length_remaining(next_tvb, 0) > 3) {
+printf("SEQUENCE dissect_ber_old_sequence(%s) calling subdissector offset:%d len:%d %02x:%02x:%02x\n", name, offset, tvb_length_remaining(next_tvb, 0), tvb_get_guint8(next_tvb, 0), tvb_get_guint8(next_tvb, 1), tvb_get_guint8(next_tvb, 2));
+} else {
+printf("SEQUENCE dissect_ber_old_sequence(%s) calling subdissector\n", name);
}
}
#endif
@@ -2381,38 +2589,38 @@ printf("SEQUENCE dissect_ber_old_sequence(%s) calling subdissector\n",name);
/* Assume that we have a malformed packet. */
THROW(ReportedBoundsError);
}
- count=seq->func(tree, next_tvb, 0, actx);
+ count = seq->func(tree, next_tvb, 0, actx);
#ifdef DEBUG_BER
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-printf("SEQUENCE dissect_ber_old_sequence(%s) subdissector ate %d bytes\n",name,count);
+printf("SEQUENCE dissect_ber_old_sequence(%s) subdissector ate %d bytes\n", name, count);
}
#endif
/* if it was optional and no bytes were eaten and it was */
/* supposed to (len<>0), just try again. */
- if((len!=0)&&(count==0)&&(seq->flags&BER_FLAGS_OPTIONAL)){
+ if ((len != 0) && (count == 0) && (seq->flags & BER_FLAGS_OPTIONAL)) {
seq++;
goto ber_old_sequence_try_again;
/* move the offset to the beginning of the next sequenced item */
}
offset = eoffset;
seq++;
- if(!(seq->flags & BER_FLAGS_NOOWNTAG) ) {
+ if (!(seq->flags & BER_FLAGS_NOOWNTAG) ) {
/* if we stripped the tag and length we should also strip the EOC is ind_len
* Unless its a zero length field (len = 2)
*/
- if((ind_field == 1)&&(len>2))
+ if ((ind_field == 1) && (len > 2))
{
/* skip over EOC */
- if(show_internal_ber_fields){
+ if (show_internal_ber_fields) {
proto_tree_add_text(tree, tvb, offset, count, "SEQ FIELD EOC");
}
}
@@ -2420,17 +2628,22 @@ printf("SEQUENCE dissect_ber_old_sequence(%s) subdissector ate %d bytes\n",name,
}
/* if we didnt end up at exactly offset, then we ate too many bytes */
- if(offset != end_offset) {
+ if (offset != end_offset) {
tvb_ensure_bytes_exist(tvb, offset-2, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset-2, 2, "illegal_length", "BER Error: Sequence ate %d too many bytes", offset-end_offset);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: too many bytes in Sequence");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset-2, 2, "illegal_length",
+ "BER Error: Sequence ate %d too many bytes",
+ offset - end_offset);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: too many bytes in Sequence");
}
- if(ind){
+ if (ind) {
/* need to eat this EOC
end_offset = tvb_length(tvb);*/
end_offset += 2;
- if(show_internal_ber_fields){
- proto_tree_add_text(tree, tvb, end_offset-2,2 , "SEQ EOC");
+ if (show_internal_ber_fields) {
+ proto_tree_add_text(tree, tvb, end_offset-2, 2 , "SEQ EOC");
}
}
return end_offset;
@@ -2438,48 +2651,52 @@ printf("SEQUENCE dissect_ber_old_sequence(%s) subdissector ate %d bytes\n",name,
/* This function dissects a BER set
*/
-int dissect_ber_set(gboolean implicit_tag,asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *set, gint hf_id, gint ett_id) {
- gint8 classx;
- gboolean pcx, ind = 0, ind_field, imp_tag = FALSE;
- gint32 tagx;
- guint32 lenx;
- proto_tree *tree = parent_tree;
- proto_item *item = NULL;
+int
+dissect_ber_set(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *set, gint hf_id, gint ett_id) {
+ gint8 classx;
+ gboolean pcx, ind = 0, ind_field, imp_tag = FALSE;
+ gint32 tagx;
+ guint32 lenx;
+ proto_tree *tree = parent_tree;
+ proto_item *item = NULL;
proto_item *cause;
- int end_offset, s_offset;
- int hoffset;
- gint length_remaining;
- tvbuff_t *next_tvb;
+ int end_offset, s_offset;
+ int hoffset;
+ gint length_remaining;
+ tvbuff_t *next_tvb;
+ guint32 mandatory_fields = 0;
+ guint8 set_idx;
+ gboolean first_pass;
const ber_sequence_t *cset = NULL;
-# define MAX_SET_ELEMENTS 32
- guint32 mandatory_fields = 0;
- guint8 set_idx;
- gboolean first_pass;
+
+#define MAX_SET_ELEMENTS 32
+
s_offset = offset;
+
#ifdef DEBUG_BER
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(tvb,offset)>3){
-printf("SET dissect_ber_set(%s) entered offset:%d len:%d %02x:%02x:%02x\n",name,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
-}else{
-printf("SET dissect_ber_set(%s) entered\n",name);
+if (tvb_length_remaining(tvb, offset) > 3) {
+printf("SET dissect_ber_set(%s) entered offset:%d len:%d %02x:%02x:%02x\n", name, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("SET dissect_ber_set(%s) entered\n", name);
}
}
#endif
- if(!implicit_tag){
+ if (!implicit_tag) {
hoffset = offset;
/* first we must read the sequence header */
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &classx, &pcx, &tagx);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &lenx, &ind);
- if(ind){
+ if (ind) {
/* Fixed the length is correctly returned from dissect ber_length
end_offset = tvb_length(tvb);*/
end_offset = offset + lenx -2;
@@ -2488,28 +2705,37 @@ printf("SET dissect_ber_set(%s) entered\n",name);
}
/* sanity check: we only handle Constructed Universal Sets */
- if ((classx!=BER_CLASS_APP)&&(classx!=BER_CLASS_PRI))
- if ((!pcx)
- ||(!implicit_tag&&((classx!=BER_CLASS_UNI)
- ||(tagx!=BER_UNI_TAG_SET)))) {
- tvb_ensure_bytes_exist(tvb, hoffset, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, lenx, "set_expected", "BER Error: SET expected but class:%s(%d) %s tag:%d was found", val_to_str_const(classx,ber_class_codes,"Unknown"), classx, pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tagx);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: SET expected");
- if (decode_unexpected) {
- proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
- dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
- }
- return end_offset;
+ if ((classx != BER_CLASS_APP) && (classx != BER_CLASS_PRI)) {
+ if (!pcx
+ || (!implicit_tag && ((classx != BER_CLASS_UNI)
+ || (tagx != BER_UNI_TAG_SET)))) {
+ tvb_ensure_bytes_exist(tvb, hoffset, 2);
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, lenx, "set_expected",
+ "BER Error: SET expected but class:%s(%d) %s tag:%d was found",
+ val_to_str_const(classx, ber_class_codes, "Unknown"),
+ classx,
+ pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tagx);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: SET expected");
+ if (decode_unexpected) {
+ proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
+ dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
+ }
+ return end_offset;
+ }
}
} else {
/* was implicit tag so just use the length of the tvb */
- lenx=tvb_length_remaining(tvb,offset);
- end_offset=offset+lenx;
+ lenx = tvb_length_remaining(tvb, offset);
+ end_offset = offset+lenx;
}
/* create subtree */
if (hf_id >= 0) {
- if(parent_tree){
+ if (parent_tree) {
item = proto_tree_add_item(parent_tree, hf_id, tvb, offset, lenx, ENC_BIG_ENDIAN);
tree = proto_item_add_subtree(item, ett_id);
}
@@ -2517,79 +2743,77 @@ printf("SET dissect_ber_set(%s) entered\n",name);
/* record the mandatory elements of the set so we can check we found everything at the end
we can only record 32 elements for now ... */
- for(set_idx = 0; (cset=&set[set_idx])->func && (set_idx < MAX_SET_ELEMENTS); set_idx++) {
+ for (set_idx = 0; (cset = &set[set_idx])->func && (set_idx < MAX_SET_ELEMENTS); set_idx++) {
- if(!(cset->flags & BER_FLAGS_OPTIONAL))
+ if (!(cset->flags & BER_FLAGS_OPTIONAL))
mandatory_fields |= 1 << set_idx;
}
/* loop over all entries until we reach the end of the set */
- while (offset < end_offset){
- gint8 ber_class;
+ while (offset < end_offset) {
+ gint8 ber_class;
gboolean pc;
- gint32 tag;
- guint32 len;
- int eoffset, count;
+ gint32 tag;
+ guint32 len;
+ int eoffset, count;
- /*if(ind){ this sequence was of indefinite length, if this is implicit indefinite impossible maybe
+ /*if (ind) { this sequence was of indefinite length, if this is implicit indefinite impossible maybe
but ber dissector uses this to eat the tag length then pass into here... EOC still on there...*/
- if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0)){
- if(show_internal_ber_fields){
+ if ((tvb_get_guint8(tvb, offset) == 0) && (tvb_get_guint8(tvb, offset+1) == 0)) {
+ if (show_internal_ber_fields) {
proto_tree_add_text(tree, tvb, s_offset, offset+2, "SEQ EOC");
}
return end_offset;
}
- /* } */
+ /* } */
hoffset = offset;
/* read header and len for next field */
- offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
- offset = get_ber_length(tvb, offset, &len, &ind_field);
+ offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
+ offset = get_ber_length(tvb, offset, &len, &ind_field);
eoffset = offset + len;
/* Look through the Set to see if this class/id exists and
* hasn't been seen before
- * Skip check completely if ber_class==ANY
+ * Skip check completely if ber_class == ANY
* of if NOCHKTAG is set
*/
- for(first_pass=TRUE, cset = set, set_idx = 0; cset->func || first_pass; cset++, set_idx++) {
+ for (first_pass = TRUE, cset = set, set_idx = 0; cset->func || first_pass; cset++, set_idx++) {
/* we reset for a second pass when we will look for choices */
- if(!cset->func) {
+ if (!cset->func) {
first_pass = FALSE;
- cset=set; /* reset to the beginning */
+ cset = set; /* reset to the beginning */
set_idx = 0;
}
- if((first_pass && ((cset->ber_class==ber_class) && (cset->tag==tag))) ||
- (!first_pass && ((cset->ber_class== BER_CLASS_ANY) && (cset->tag == -1))) ) /* choices */
+ if ((first_pass && ((cset->ber_class == ber_class) && (cset->tag == tag))) ||
+ (!first_pass && ((cset->ber_class == BER_CLASS_ANY) && (cset->tag == -1))) ) /* choices */
{
-
if (!(cset->flags & BER_FLAGS_NOOWNTAG) ) {
/* dissect header and len for field */
hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
hoffset = dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
- length_remaining=tvb_length_remaining(tvb, hoffset);
- if (length_remaining>eoffset-hoffset-(2*ind_field))
- length_remaining=eoffset-hoffset-(2*ind_field);
- next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset-hoffset-(2*ind_field));
- }
- else {
- length_remaining=tvb_length_remaining(tvb, hoffset);
- if (length_remaining>eoffset-hoffset)
- length_remaining=eoffset-hoffset;
- next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset-hoffset);
+ length_remaining = tvb_length_remaining(tvb, hoffset);
+ if (length_remaining > (eoffset - hoffset - (2 * ind_field)))
+ length_remaining = eoffset - hoffset - (2 * ind_field);
+ next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset - hoffset - (2 * ind_field));
+ } else {
+ length_remaining = tvb_length_remaining(tvb, hoffset);
+ if (length_remaining > (eoffset - hoffset))
+ length_remaining = eoffset - hoffset;
+ next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset - hoffset);
}
#if 0
/* call the dissector for this field */
if ((eoffset-hoffset)>length_remaining) {
- /* If the field is indefinite (i.e. we dont know the
+ /* If the field is indefinite (i.e. we don't know the
* length) of if the tvb is short, then just
* give it all of the tvb and hope for the best.
*/
@@ -2603,16 +2827,16 @@ printf("SET dissect_ber_set(%s) entered\n",name);
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(next_tvb,0)>3){
-printf("SET dissect_ber_set(%s) calling subdissector offset:%d len:%d %02x:%02x:%02x\n",name,offset,tvb_length_remaining(next_tvb,0),tvb_get_guint8(next_tvb,0),tvb_get_guint8(next_tvb,1),tvb_get_guint8(next_tvb,2));
-}else{
-printf("SET dissect_ber_set(%s) calling subdissector\n",name);
+if (tvb_length_remaining(next_tvb, 0) > 3) {
+printf("SET dissect_ber_set(%s) calling subdissector offset:%d len:%d %02x:%02x:%02x\n", name, offset, tvb_length_remaining(next_tvb, 0), tvb_get_guint8(next_tvb, 0), tvb_get_guint8(next_tvb, 1), tvb_get_guint8(next_tvb, 2));
+} else {
+printf("SET dissect_ber_set(%s) calling subdissector\n", name);
}
}
#endif
@@ -2623,22 +2847,22 @@ printf("SET dissect_ber_set(%s) calling subdissector\n",name);
imp_tag = FALSE;
if ((cset->flags & BER_FLAGS_IMPLTAG))
imp_tag = TRUE;
- count=cset->func(imp_tag, next_tvb, 0, actx, tree, *cset->p_id);
+ count = cset->func(imp_tag, next_tvb, 0, actx, tree, *cset->p_id);
/* if we consumed some bytes,
or we knew the length was zero (during the first pass only) */
- if(count || (first_pass && (len == 0 || (ind_field == 1 && len == 2)))) {
+ if (count || (first_pass && ((len == 0) || ((ind_field == 1) && (len == 2))))) {
/* we found it! */
- if(set_idx < MAX_SET_ELEMENTS)
+ if (set_idx < MAX_SET_ELEMENTS)
mandatory_fields &= ~(1 << set_idx);
offset = eoffset;
- if(!(cset->flags & BER_FLAGS_NOOWNTAG) ) {
+ if (!(cset->flags & BER_FLAGS_NOOWNTAG) ) {
/* if we stripped the tag and length we should also strip the EOC is ind_len */
- if(ind_field == 1){
+ if (ind_field == 1) {
/* skip over EOC */
- if(show_internal_ber_fields){
+ if (show_internal_ber_fields) {
proto_tree_add_text(tree, tvb, offset, count, "SET FIELD EOC");
}
}
@@ -2648,10 +2872,17 @@ printf("SET dissect_ber_set(%s) calling subdissector\n",name);
}
}
- if(!cset->func) {
+ if (!cset->func) {
/* we didn't find a match */
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "unknown_field", "BER Error: Unknown field in SET class:%s(%d) tag:%d",val_to_str_const(ber_class,ber_class_codes,"Unknown"),ber_class,tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Unknown field in SET");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "unknown_field",
+ "BER Error: Unknown field in SET class:%s(%d) tag:%d",
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Unknown field in SET");
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
@@ -2660,20 +2891,22 @@ printf("SET dissect_ber_set(%s) calling subdissector\n",name);
}
}
- if(mandatory_fields) {
+ if (mandatory_fields) {
/* OK - we didn't find some of the elements we expected */
- for(set_idx = 0; (cset = &set[set_idx])->func && (set_idx < MAX_SET_ELEMENTS); set_idx++) {
-
- if(mandatory_fields & (1 << set_idx)) {
-
+ for (set_idx = 0; (cset = &set[set_idx])->func && (set_idx < MAX_SET_ELEMENTS); set_idx++) {
+ if (mandatory_fields & (1 << set_idx)) {
/* here is something we should have seen - but didn't! */
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, lenx, "missing_field",
- "BER Error: Missing field in SET class:%s(%d) tag:%d expected",
- val_to_str_const(cset->ber_class,ber_class_codes,"Unknown"),cset->ber_class,
- cset->tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Missing field in SET");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, lenx, "missing_field",
+ "BER Error: Missing field in SET class:%s(%d) tag:%d expected",
+ val_to_str_const(cset->ber_class, ber_class_codes, "Unknown"),
+ cset->ber_class,
+ cset->tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Missing field in SET");
}
@@ -2683,16 +2916,21 @@ printf("SET dissect_ber_set(%s) calling subdissector\n",name);
/* if we didnt end up at exactly offset, then we ate too many bytes */
if (offset != end_offset) {
tvb_ensure_bytes_exist(tvb, offset-2, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset-2, 2, "illegal_length", "BER Error: SET ate %d too many bytes", offset-end_offset);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: too many bytes in SET");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset-2, 2, "illegal_length",
+ "BER Error: SET ate %d too many bytes",
+ offset - end_offset);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: too many bytes in SET");
}
- if(ind){
+ if (ind) {
/* need to eat this EOC
end_offset = tvb_length(tvb);*/
end_offset += 2;
- if(show_internal_ber_fields){
- proto_tree_add_text(tree, tvb, end_offset-2,2 , "SET EOC");
+ if (show_internal_ber_fields) {
+ proto_tree_add_text(tree, tvb, end_offset-2, 2 , "SET EOC");
}
}
@@ -2700,48 +2938,52 @@ printf("SET dissect_ber_set(%s) calling subdissector\n",name);
}
-int dissect_ber_old_set(gboolean implicit_tag,asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_old_sequence_t *set, gint hf_id, gint ett_id) {
- gint8 classx;
- gboolean pcx, ind = 0, ind_field;
- gint32 tagx;
- guint32 lenx;
- proto_tree *tree = parent_tree;
- proto_item *item = NULL;
+int
+dissect_ber_old_set(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_old_sequence_t *set, gint hf_id, gint ett_id) {
+ gint8 classx;
+ gboolean pcx, ind = 0, ind_field;
+ gint32 tagx;
+ guint32 lenx;
+ proto_tree *tree = parent_tree;
+ proto_item *item = NULL;
proto_item *cause;
- int end_offset, s_offset;
- int hoffset;
- gint length_remaining;
- tvbuff_t *next_tvb;
+ int end_offset, s_offset;
+ int hoffset;
+ gint length_remaining;
+ tvbuff_t *next_tvb;
+ guint32 mandatory_fields = 0;
+ guint8 set_idx;
+ gboolean first_pass;
const ber_old_sequence_t *cset = NULL;
-# define MAX_SET_ELEMENTS 32
- guint32 mandatory_fields = 0;
- guint8 set_idx;
- gboolean first_pass;
+
s_offset = offset;
+
+#define MAX_SET_ELEMENTS 32
+
#ifdef DEBUG_BER
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(tvb,offset)>3){
-printf("SET dissect_old_ber_set(%s) entered offset:%d len:%d %02x:%02x:%02x\n",name,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
-}else{
-printf("SET dissect_old_ber_set(%s) entered\n",name);
+if (tvb_length_remaining(tvb, offset) > 3) {
+printf("SET dissect_old_ber_set(%s) entered offset:%d len:%d %02x:%02x:%02x\n", name, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("SET dissect_old_ber_set(%s) entered\n", name);
}
}
#endif
- if(!implicit_tag){
+ if (!implicit_tag) {
hoffset = offset;
/* first we must read the sequence header */
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &classx, &pcx, &tagx);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &lenx, &ind);
- if(ind){
+ if (ind) {
/* Fixed the length is correctly returned from dissect ber_length
end_offset = tvb_length(tvb);*/
end_offset = offset + lenx -2;
@@ -2750,28 +2992,37 @@ printf("SET dissect_old_ber_set(%s) entered\n",name);
}
/* sanity check: we only handle Constructed Universal Sets */
- if ((classx!=BER_CLASS_APP)&&(classx!=BER_CLASS_PRI))
- if ((!pcx)
- ||(!implicit_tag&&((classx!=BER_CLASS_UNI)
- ||(tagx!=BER_UNI_TAG_SET)))) {
- tvb_ensure_bytes_exist(tvb, hoffset, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, lenx, "set_expected", "BER Error: SET expected but class:%s(%d) %s tag:%d was found", val_to_str_const(classx,ber_class_codes,"Unknown"), classx, pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tagx);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: SET expected");
- if (decode_unexpected) {
- proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
- dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
+ if ((classx != BER_CLASS_APP) && (classx != BER_CLASS_PRI)) {
+ if (!pcx
+ || (!implicit_tag && ((classx != BER_CLASS_UNI)
+ || (tagx != BER_UNI_TAG_SET)))) {
+ tvb_ensure_bytes_exist(tvb, hoffset, 2);
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, lenx, "set_expected",
+ "BER Error: SET expected but class:%s(%d) %s tag:%d was found",
+ val_to_str_const(classx, ber_class_codes, "Unknown"),
+ classx,
+ pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tagx);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: SET expected");
+ if (decode_unexpected) {
+ proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
+ dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
+ }
+ return end_offset;
}
- return end_offset;
}
} else {
/* was implicit tag so just use the length of the tvb */
- lenx=tvb_length_remaining(tvb,offset);
- end_offset=offset+lenx;
+ lenx = tvb_length_remaining(tvb, offset);
+ end_offset = offset+lenx;
}
/* create subtree */
if (hf_id >= 0) {
- if(parent_tree){
+ if (parent_tree) {
item = proto_tree_add_item(parent_tree, hf_id, tvb, offset, lenx, ENC_BIG_ENDIAN);
tree = proto_item_add_subtree(item, ett_id);
}
@@ -2779,26 +3030,26 @@ printf("SET dissect_old_ber_set(%s) entered\n",name);
/* record the mandatory elements of the set so we can check we found everything at the end
we can only record 32 elements for now ... */
- for(set_idx = 0; (cset=&set[set_idx])->func && (set_idx < MAX_SET_ELEMENTS); set_idx++) {
+ for (set_idx = 0; (cset = &set[set_idx])->func && (set_idx < MAX_SET_ELEMENTS); set_idx++) {
- if(!(cset->flags & BER_FLAGS_OPTIONAL))
+ if (!(cset->flags & BER_FLAGS_OPTIONAL))
mandatory_fields |= 1 << set_idx;
}
/* loop over all entries until we reach the end of the set */
- while (offset < end_offset){
- gint8 ber_class;
+ while (offset < end_offset) {
+ gint8 ber_class;
gboolean pc;
- gint32 tag;
- guint32 len;
- int eoffset, count;
+ gint32 tag;
+ guint32 len;
+ int eoffset, count;
- /*if(ind){ this sequence was of indefinite length, if this is implicit indefinite impossible maybe
+ /*if (ind) { this sequence was of indefinite length, if this is implicit indefinite impossible maybe
but ber dissector uses this to eat the tag length then pass into here... EOC still on there...*/
- if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0)){
- if(show_internal_ber_fields){
+ if ((tvb_get_guint8(tvb, offset) == 0) && (tvb_get_guint8(tvb, offset+1) == 0)) {
+ if (show_internal_ber_fields) {
proto_tree_add_text(tree, tvb, s_offset, offset+2, "SEQ EOC");
}
return end_offset;
@@ -2806,52 +3057,49 @@ printf("SET dissect_old_ber_set(%s) entered\n",name);
/* } */
hoffset = offset;
/* read header and len for next field */
- offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
- offset = get_ber_length(tvb, offset, &len, &ind_field);
+ offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
+ offset = get_ber_length(tvb, offset, &len, &ind_field);
eoffset = offset + len;
/* Look through the Set to see if this class/id exists and
* hasn't been seen before
- * Skip check completely if class==ANY
+ * Skip check completely if class == ANY
* of if NOCHKTAG is set
*/
- for(first_pass=TRUE, cset = set, set_idx = 0; cset->func || first_pass; cset++, set_idx++) {
+ for (first_pass=TRUE, cset=set, set_idx=0; cset->func || first_pass; cset++, set_idx++) {
/* we reset for a second pass when we will look for choices */
- if(!cset->func) {
+ if (!cset->func) {
first_pass = FALSE;
- cset=set; /* reset to the beginning */
+ cset = set; /* reset to the beginning */
set_idx = 0;
}
- if((first_pass && ((cset->ber_class==ber_class) && (cset->tag==tag))) ||
- (!first_pass && ((cset->ber_class== BER_CLASS_ANY) && (cset->tag == -1))) ) /* choices */
+ if ((first_pass && ((cset->ber_class == ber_class) && (cset->tag == tag))) ||
+ (!first_pass && ((cset->ber_class == BER_CLASS_ANY) && (cset->tag == -1))) ) /* choices */
{
-
if (!(cset->flags & BER_FLAGS_NOOWNTAG) ) {
/* dissect header and len for field */
hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
hoffset = dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
- length_remaining=tvb_length_remaining(tvb, hoffset);
- if (length_remaining>eoffset-hoffset-(2*ind_field))
- length_remaining=eoffset-hoffset-(2*ind_field);
- next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset-hoffset-(2*ind_field));
- }
- else {
- length_remaining=tvb_length_remaining(tvb, hoffset);
- if (length_remaining>eoffset-hoffset)
- length_remaining=eoffset-hoffset;
- next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset-hoffset);
+ length_remaining = tvb_length_remaining(tvb, hoffset);
+ if (length_remaining > (eoffset - hoffset - (2 * ind_field)))
+ length_remaining = eoffset - hoffset - (2 * ind_field);
+ next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset - hoffset - (2 * ind_field));
+ } else {
+ length_remaining = tvb_length_remaining(tvb, hoffset);
+ if (length_remaining > (eoffset - hoffset))
+ length_remaining = eoffset - hoffset;
+ next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset - hoffset);
}
-
#if 0
/* call the dissector for this field */
if ((eoffset-hoffset)>length_remaining) {
- /* If the field is indefinite (i.e. we dont know the
+ /* If the field is indefinite (i.e. we don't know the
* length) of if the tvb is short, then just
* give it all of the tvb and hope for the best.
*/
@@ -2865,16 +3113,16 @@ printf("SET dissect_old_ber_set(%s) entered\n",name);
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(next_tvb,0)>3){
-printf("SET dissect_old_ber_set(%s) calling subdissector offset:%d len:%d %02x:%02x:%02x\n",name,offset,tvb_length_remaining(next_tvb,0),tvb_get_guint8(next_tvb,0),tvb_get_guint8(next_tvb,1),tvb_get_guint8(next_tvb,2));
-}else{
-printf("SET dissect_old_ber_set(%s) calling subdissector\n",name);
+if (tvb_length_remaining(next_tvb, 0) > 3) {
+printf("SET dissect_old_ber_set(%s) calling subdissector offset:%d len:%d %02x:%02x:%02x\n", name, offset, tvb_length_remaining(next_tvb, 0), tvb_get_guint8(next_tvb, 0), tvb_get_guint8(next_tvb, 1), tvb_get_guint8(next_tvb, 2));
+} else {
+printf("SET dissect_old_ber_set(%s) calling subdissector\n", name);
}
}
#endif
@@ -2882,22 +3130,22 @@ printf("SET dissect_old_ber_set(%s) calling subdissector\n",name);
/* Assume that we have a malformed packet. */
THROW(ReportedBoundsError);
}
- count=cset->func(tree, next_tvb, 0, actx);
+ count = cset->func(tree, next_tvb, 0, actx);
/* if we consumed some bytes,
or we knew the length was zero (during the first pass only) */
- if(count || (first_pass && (len == 0 || (ind_field == 1 && len == 2)))) {
+ if (count || (first_pass && ((len == 0) || ((ind_field == 1) && (len == 2))))) {
/* we found it! */
- if(set_idx < MAX_SET_ELEMENTS)
+ if (set_idx < MAX_SET_ELEMENTS)
mandatory_fields &= ~(1 << set_idx);
offset = eoffset;
- if(!(cset->flags & BER_FLAGS_NOOWNTAG) ) {
+ if (!(cset->flags & BER_FLAGS_NOOWNTAG) ) {
/* if we stripped the tag and length we should also strip the EOC is ind_len */
- if(ind_field == 1){
+ if (ind_field == 1) {
/* skip over EOC */
- if(show_internal_ber_fields){
+ if (show_internal_ber_fields) {
proto_tree_add_text(tree, tvb, offset, count, "SET FIELD EOC");
}
}
@@ -2907,10 +3155,17 @@ printf("SET dissect_old_ber_set(%s) calling subdissector\n",name);
}
}
- if(!cset->func) {
+ if (!cset->func) {
/* we didn't find a match */
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "unknown_field", "BER Error: Unknown field in SET class:%s(%d) tag:%d",val_to_str_const(ber_class,ber_class_codes,"Unknown"),ber_class,tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Unknown field in SET");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "unknown_field",
+ "BER Error: Unknown field in SET class:%s(%d) tag:%d",
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Unknown field in SET");
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
@@ -2919,39 +3174,44 @@ printf("SET dissect_old_ber_set(%s) calling subdissector\n",name);
}
}
- if(mandatory_fields) {
+ if (mandatory_fields) {
/* OK - we didn't find some of the elements we expected */
- for(set_idx = 0; (cset = &set[set_idx])->func && (set_idx < MAX_SET_ELEMENTS); set_idx++) {
-
- if(mandatory_fields & (1 << set_idx)) {
-
+ for (set_idx = 0; (cset = &set[set_idx])->func && (set_idx < MAX_SET_ELEMENTS); set_idx++) {
+ if (mandatory_fields & (1 << set_idx)) {
/* here is something we should have seen - but didn't! */
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, lenx, "missing_field",
- "BER Error: Missing field in SET class:%s(%d) tag:%d expected",
- val_to_str_const(cset->ber_class,ber_class_codes,"Unknown"),cset->ber_class,
- cset->tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Missing field in SET");
-
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, lenx, "missing_field",
+ "BER Error: Missing field in SET class:%s(%d) tag:%d expected",
+ val_to_str_const(cset->ber_class, ber_class_codes, "Unknown"),
+ cset->ber_class,
+ cset->tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Missing field in SET");
}
-
}
}
/* if we didnt end up at exactly offset, then we ate too many bytes */
if (offset != end_offset) {
tvb_ensure_bytes_exist(tvb, offset-2, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset-2, 2, "illegal_length", "BER Error: SET ate %d too many bytes", offset-end_offset);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: too many bytes in SET");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset-2, 2, "illegal_length",
+ "BER Error: SET ate %d too many bytes",
+ offset - end_offset);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: too many bytes in SET");
}
- if(ind){
+ if (ind) {
/* need to eat this EOC
end_offset = tvb_length(tvb);*/
end_offset += 2;
- if(show_internal_ber_fields){
- proto_tree_add_text(tree, tvb, end_offset-2,2 , "SET EOC");
+ if (show_internal_ber_fields) {
+ proto_tree_add_text(tree, tvb, end_offset-2, 2 , "SET EOC");
}
}
@@ -2969,125 +3229,130 @@ printf("SET dissect_old_ber_set(%s) calling subdissector\n",name);
int
dissect_ber_choice(asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_choice_t *choice, gint hf_id, gint ett_id, gint *branch_taken)
{
- gint8 ber_class;
- gboolean pc, ind, imp_tag = FALSE;
- gint32 tag;
- guint32 len;
+ gint8 ber_class;
+ gboolean pc, ind, imp_tag = FALSE;
+ gint32 tag;
+ guint32 len;
+ proto_tree *tree = parent_tree;
+ proto_item *item = NULL;
+ int end_offset, start_offset, count;
+ int hoffset = offset;
+ gint length, length_remaining;
+ tvbuff_t *next_tvb;
+ gboolean first_pass;
+ header_field_info *hfinfo;
const ber_choice_t *ch;
- proto_tree *tree=parent_tree;
- proto_item *item=NULL;
- int end_offset, start_offset, count;
- int hoffset = offset;
- header_field_info *hfinfo;
- gint length, length_remaining;
- tvbuff_t *next_tvb;
- gboolean first_pass;
#ifdef DEBUG_BER_CHOICE
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(tvb,offset)>3){
-printf("CHOICE dissect_ber_choice(%s) entered offset:%d len:%d %02x:%02x:%02x\n",name,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
-}else{
-printf("CHOICE dissect_ber_choice(%s) entered len:%d\n",name,tvb_length_remaining(tvb,offset));
+if (tvb_length_remaining(tvb, offset) > 3) {
+printf("CHOICE dissect_ber_choice(%s) entered offset:%d len:%d %02x:%02x:%02x\n", name, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("CHOICE dissect_ber_choice(%s) entered len:%d\n", name, tvb_length_remaining(tvb, offset));
}
}
#endif
- start_offset=offset;
- if(tvb_length_remaining(tvb,offset) == 0) {
- item = proto_tree_add_string_format(parent_tree, hf_ber_error, tvb, offset, 0, "empty_choice", "BER Error: Empty choice was found");
- expert_add_info_format(actx->pinfo, item, PI_MALFORMED, PI_WARN, "BER Error: Empty choice was found");
+ start_offset = offset;
+
+ if (tvb_length_remaining(tvb, offset) == 0) {
+ item = proto_tree_add_string_format(
+ parent_tree, hf_ber_error, tvb, offset, 0, "empty_choice",
+ "BER Error: Empty choice was found");
+ expert_add_info_format(
+ actx->pinfo, item, PI_MALFORMED, PI_WARN,
+ "BER Error: Empty choice was found");
return offset;
}
/* read header and len for choice field */
- offset=get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
- offset=get_ber_length(tvb, offset, &len, &ind);
+ offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
+ offset = get_ber_length(tvb, offset, &len, &ind);
end_offset = offset + len ;
/* Some sanity checks.
* The hf field passed to us MUST be an integer type
*/
- if(hf_id >= 0){
- hfinfo=proto_registrar_get_nth(hf_id);
- switch(hfinfo->type) {
+ if (hf_id >= 0) {
+ hfinfo = proto_registrar_get_nth(hf_id);
+ switch (hfinfo->type) {
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
case FT_UINT32:
break;
default:
- proto_tree_add_text(tree, tvb, offset, len,"dissect_ber_choice(): Was passed a HF field that was not integer type : %s",hfinfo->abbrev);
- fprintf(stderr,"dissect_ber_choice(): frame:%u offset:%d Was passed a HF field that was not integer type : %s\n",actx->pinfo->fd->num,offset,hfinfo->abbrev);
+ proto_tree_add_text(
+ tree, tvb, offset, len,
+ "dissect_ber_choice(): Was passed a HF field that was not integer type : %s",
+ hfinfo->abbrev);
+ g_warning("dissect_ber_choice(): frame:%u offset:%d Was passed a HF field that was not integer type : %s",
+ actx->pinfo->fd->num, offset, hfinfo->abbrev);
return end_offset;
}
}
-
-
/* loop over all entries until we find the right choice or
run out of entries */
ch = choice;
- if(branch_taken){
- *branch_taken=-1;
+ if (branch_taken) {
+ *branch_taken = -1;
}
first_pass = TRUE;
- while(ch->func || first_pass){
- if(branch_taken){
+ while (ch->func || first_pass) {
+ if (branch_taken) {
(*branch_taken)++;
}
/* we reset for a second pass when we will look for choices */
- if(!ch->func) {
+ if (!ch->func) {
first_pass = FALSE;
ch = choice; /* reset to the beginning */
- if(branch_taken){
- *branch_taken=-1;
+ if (branch_taken) {
+ *branch_taken = -1;
}
}
choice_try_again:
#ifdef DEBUG_BER_CHOICE
-printf("CHOICE testing potential subdissector class[%p]:%d:(expected)%d tag:%d:(expected)%d flags:%d\n",ch,ber_class,ch->ber_class,tag,ch->tag,ch->flags);
+printf("CHOICE testing potential subdissector class[%p]:%d:(expected)%d tag:%d:(expected)%d flags:%d\n", ch, ber_class, ch->ber_class, tag, ch->tag, ch->flags);
#endif
- if( (first_pass && (((ch->ber_class==ber_class)&&(ch->tag==tag))
- || ((ch->ber_class==ber_class)&&(ch->tag==-1)&&(ch->flags&BER_FLAGS_NOOWNTAG)))) ||
- (!first_pass && (((ch->ber_class == BER_CLASS_ANY) && (ch->tag == -1)))) /* we failed on the first pass so now try any choices */
- ){
- if(!(ch->flags & BER_FLAGS_NOOWNTAG)){
+ if ( (first_pass
+ && (((ch->ber_class == ber_class) && (ch->tag == tag))
+ || ((ch->ber_class == ber_class) && (ch->tag == -1) && (ch->flags & BER_FLAGS_NOOWNTAG))))
+ || (!first_pass && (((ch->ber_class == BER_CLASS_ANY) && (ch->tag == -1)))) /* we failed on the first pass so now try any choices */
+ ) {
+ if (!(ch->flags & BER_FLAGS_NOOWNTAG)) {
/* dissect header and len for field */
hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, start_offset, NULL, NULL, NULL);
hoffset = dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
- start_offset=hoffset;
- if (ind)
- {
- length = len-2;
- }
- else
- {
+ start_offset = hoffset;
+ if (ind) {
+ length = len - 2;
+ } else {
length = len;
- }
- }
- else
+ }
+ } else {
length = end_offset- hoffset;
+ }
/* create subtree */
- if(hf_id >= 0){
- if(parent_tree){
+ if (hf_id >= 0) {
+ if (parent_tree) {
item = proto_tree_add_uint(parent_tree, hf_id, tvb, hoffset, end_offset - hoffset, ch->value);
tree = proto_item_add_subtree(item, ett_id);
}
}
- length_remaining=tvb_length_remaining(tvb, hoffset);
- if(length_remaining>length)
- length_remaining=length;
+ length_remaining = tvb_length_remaining(tvb, hoffset);
+ if (length_remaining>length)
+ length_remaining = length;
#ifdef REMOVED
/* This is bogus and makes the OID_1.0.9506.1.1.cap file
@@ -3098,28 +3363,28 @@ printf("CHOICE testing potential subdissector class[%p]:%d:(expected)%d tag:%d:
* traces anyway.
* God, this file is a mess and it is my fault. /ronnie
*/
- if(first_pass)
- next_tvb=tvb_new_subset(tvb, hoffset, length_remaining, length);
+ if (first_pass)
+ next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, length);
else
next_tvb = tvb; /* we didn't make selection on this class/tag so pass it on */
#endif
- next_tvb=tvb_new_subset(tvb, hoffset, length_remaining, length);
+ next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, length);
#ifdef DEBUG_BER_CHOICE
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(next_tvb,0)>3){
-printf("CHOICE dissect_ber_choice(%s) calling subdissector start_offset:%d offset:%d len:%d %02x:%02x:%02x\n",name,start_offset,offset,tvb_length_remaining(next_tvb,0),tvb_get_guint8(next_tvb,0),tvb_get_guint8(next_tvb,1),tvb_get_guint8(next_tvb,2));
-}else{
-printf("CHOICE dissect_ber_choice(%s) calling subdissector len:%d\n",name,tvb_length(next_tvb));
+if (tvb_length_remaining(next_tvb, 0) > 3) {
+printf("CHOICE dissect_ber_choice(%s) calling subdissector start_offset:%d offset:%d len:%d %02x:%02x:%02x\n", name, start_offset, offset, tvb_length_remaining(next_tvb, 0), tvb_get_guint8(next_tvb, 0), tvb_get_guint8(next_tvb, 1), tvb_get_guint8(next_tvb, 2));
+} else {
+printf("CHOICE dissect_ber_choice(%s) calling subdissector len:%d\n", name, tvb_length(next_tvb));
}
}
#endif
@@ -3130,44 +3395,43 @@ printf("CHOICE dissect_ber_choice(%s) calling subdissector len:%d\n",name,tvb_le
imp_tag = FALSE;
if ((ch->flags & BER_FLAGS_IMPLTAG))
imp_tag = TRUE;
- count=ch->func(imp_tag, next_tvb, 0, actx, tree, *ch->p_id);
+ count = ch->func(imp_tag, next_tvb, 0, actx, tree, *ch->p_id);
#ifdef DEBUG_BER_CHOICE
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-printf("CHOICE dissect_ber_choice(%s) subdissector ate %d bytes\n",name,count);
+printf("CHOICE dissect_ber_choice(%s) subdissector ate %d bytes\n", name, count);
}
#endif
- if((count==0)&&(((ch->ber_class==ber_class)&&(ch->tag==-1)&&(ch->flags&BER_FLAGS_NOOWNTAG)) || !first_pass)){
+ if ((count == 0) && (((ch->ber_class == ber_class) && (ch->tag == -1) && (ch->flags & BER_FLAGS_NOOWNTAG)) || !first_pass)) {
/* wrong one, break and try again */
ch++;
#ifdef DEBUG_BER_CHOICE
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-printf("CHOICE dissect_ber_choice(%s) trying again\n",name);
+printf("CHOICE dissect_ber_choice(%s) trying again\n", name);
}
#endif
goto choice_try_again;
}
- if(!(ch->flags & BER_FLAGS_NOOWNTAG)){
- if(ind)
- {
+ if (!(ch->flags & BER_FLAGS_NOOWNTAG)) {
+ if (ind) {
/* we are traversing a indfinite length choice where we did not pass the tag length */
/* we need to eat the EOC */
- if(show_internal_ber_fields){
+ if (show_internal_ber_fields) {
proto_tree_add_text(tree, tvb, start_offset, count+2, "CHOICE EOC");
}
}
@@ -3176,10 +3440,10 @@ printf("CHOICE dissect_ber_choice(%s) trying again\n",name);
}
ch++;
}
- if(branch_taken){
+ if (branch_taken) {
/* none of the branches were taken so set the param
back to -1 */
- *branch_taken=-1;
+ *branch_taken = -1;
}
#ifdef REMOVED
@@ -3189,8 +3453,12 @@ printf("CHOICE dissect_ber_choice(%s) trying again\n",name);
/* oops no more entries and we still havent found
* our guy :-(
*/
- item = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "missing_choice_field", "BER Error: This choice field was not found.");
- expert_add_info_format(actx->pinfo, item, PI_MALFORMED, PI_WARN, "BER Error: This choice field was not found");
+ item = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "missing_choice_field",
+ "BER Error: This choice field was not found.");
+ expert_add_info_format(
+ actx->pinfo, item, PI_MALFORMED, PI_WARN,
+ "BER Error: This choice field was not found");
return end_offset;
#endif
@@ -3200,64 +3468,72 @@ printf("CHOICE dissect_ber_choice(%s) trying again\n",name);
int
dissect_ber_old_choice(asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_old_choice_t *choice, gint hf_id, gint ett_id, gint *branch_taken)
{
- gint8 ber_class;
- gboolean pc, ind;
- gint32 tag;
- guint32 len;
+ gint8 ber_class;
+ gboolean pc, ind;
+ gint32 tag;
+ guint32 len;
+ proto_tree *tree = parent_tree;
+ proto_item *item = NULL;
+ int end_offset, start_offset, count;
+ int hoffset = offset;
+ gint length, length_remaining;
+ tvbuff_t *next_tvb;
+ gboolean first_pass;
+ header_field_info *hfinfo;
const ber_old_choice_t *ch;
- proto_tree *tree=parent_tree;
- proto_item *item=NULL;
- int end_offset, start_offset, count;
- int hoffset = offset;
- header_field_info *hfinfo;
- gint length, length_remaining;
- tvbuff_t *next_tvb;
- gboolean first_pass;
#ifdef DEBUG_BER_CHOICE
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(tvb,offset)>3){
-printf("CHOICE dissect_ber_old_choice(%s) entered offset:%d len:%d %02x:%02x:%02x\n",name,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
-}else{
-printf("CHOICE dissect_ber_old_choice(%s) entered len:%d\n",name,tvb_length_remaining(tvb,offset));
+if (tvb_length_remaining(tvb, offset) > 3) {
+printf("CHOICE dissect_ber_old_choice(%s) entered offset:%d len:%d %02x:%02x:%02x\n", name, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("CHOICE dissect_ber_old_choice(%s) entered len:%d\n", name, tvb_length_remaining(tvb, offset));
}
}
#endif
- start_offset=offset;
-
- if(tvb_length_remaining(tvb,offset) == 0) {
- item = proto_tree_add_string_format(parent_tree, hf_ber_error, tvb, offset, 0, "empty_choice", "BER Error: Empty choice was found");
- expert_add_info_format(actx->pinfo, item, PI_MALFORMED, PI_WARN, "BER Error: Empty choice was found");
+ start_offset = offset;
+
+ if (tvb_length_remaining(tvb, offset) == 0) {
+ item = proto_tree_add_string_format(
+ parent_tree, hf_ber_error, tvb, offset, 0, "empty_choice",
+ "BER Error: Empty choice was found");
+ expert_add_info_format(
+ actx->pinfo, item, PI_MALFORMED, PI_WARN,
+ "BER Error: Empty choice was found");
return offset;
}
/* read header and len for choice field */
- offset=get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
- offset=get_ber_length(tvb, offset, &len, &ind);
+ offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
+ offset = get_ber_length(tvb, offset, &len, &ind);
end_offset = offset + len ;
/* Some sanity checks.
* The hf field passed to us MUST be an integer type
*/
- if(hf_id >= 0){
- hfinfo=proto_registrar_get_nth(hf_id);
- switch(hfinfo->type) {
+ if (hf_id >= 0) {
+ hfinfo = proto_registrar_get_nth(hf_id);
+ switch (hfinfo->type) {
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
case FT_UINT32:
break;
default:
- proto_tree_add_text(tree, tvb, offset, len,"dissect_ber_old_choice(): Was passed a HF field that was not integer type : %s",hfinfo->abbrev);
- fprintf(stderr,"dissect_ber_old_choice(): frame:%u offset:%d Was passed a HF field that was not integer type : %s\n",actx->pinfo->fd->num,offset,hfinfo->abbrev);
+ proto_tree_add_text(
+ tree, tvb, offset, len,
+ "dissect_ber_old_choice(): Was passed a HF field that was not integer type : %s",
+ hfinfo->abbrev);
+ g_warning("dissect_ber_old_choice(): frame:%u offset:%d Was passed a HF field that was not integer type : %s",
+ actx->pinfo->fd->num, offset, hfinfo->abbrev);
return end_offset;
}
}
@@ -3267,58 +3543,56 @@ printf("CHOICE dissect_ber_old_choice(%s) entered len:%d\n",name,tvb_length_rema
/* loop over all entries until we find the right choice or
run out of entries */
ch = choice;
- if(branch_taken){
- *branch_taken=-1;
+ if (branch_taken) {
+ *branch_taken = -1;
}
first_pass = TRUE;
- while(ch->func || first_pass){
- if(branch_taken){
+ while (ch->func || first_pass) {
+ if (branch_taken) {
(*branch_taken)++;
}
/* we reset for a second pass when we will look for choices */
- if(!ch->func) {
+ if (!ch->func) {
first_pass = FALSE;
ch = choice; /* reset to the beginning */
- if(branch_taken){
- *branch_taken=-1;
+ if (branch_taken) {
+ *branch_taken = -1;
}
}
choice_try_again:
#ifdef DEBUG_BER_CHOICE
-printf("CHOICE testing potential subdissector class[%p]:%d:(expected)%d tag:%d:(expected)%d flags:%d\n",ch,ber_class,ch->ber_class,tag,ch->tag,ch->flags);
+printf("CHOICE testing potential subdissector class[%p]:%d:(expected)%d tag:%d:(expected)%d flags:%d\n", ch, ber_class, ch->ber_class, tag, ch->tag, ch->flags);
#endif
- if( (first_pass && (((ch->ber_class==ber_class)&&(ch->tag==tag))
- || ((ch->ber_class==ber_class)&&(ch->tag==-1)&&(ch->flags&BER_FLAGS_NOOWNTAG)))) ||
- (!first_pass && (((ch->ber_class == BER_CLASS_ANY) && (ch->tag == -1)))) /* we failed on the first pass so now try any choices */
- ){
- if(!(ch->flags & BER_FLAGS_NOOWNTAG)){
+ if ( (first_pass
+ && (((ch->ber_class == ber_class) && (ch->tag == tag))
+ || ((ch->ber_class == ber_class) && (ch->tag == -1) && (ch->flags & BER_FLAGS_NOOWNTAG))))
+ || (!first_pass && (((ch->ber_class == BER_CLASS_ANY) && (ch->tag == -1)))) /* we failed on the first pass so now try any choices */
+ ) {
+ if (!(ch->flags & BER_FLAGS_NOOWNTAG)) {
/* dissect header and len for field */
hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, start_offset, NULL, NULL, NULL);
hoffset = dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
- start_offset=hoffset;
- if (ind)
- {
- length = len-2;
- }
- else
- {
+ start_offset = hoffset;
+ if (ind) {
+ length = len - 2;
+ } else {
length = len;
- }
- }
- else
+ }
+ } else {
length = end_offset- hoffset;
+ }
/* create subtree */
- if(hf_id >= 0){
- if(parent_tree){
+ if (hf_id >= 0) {
+ if (parent_tree) {
item = proto_tree_add_uint(parent_tree, hf_id, tvb, hoffset, end_offset - hoffset, ch->value);
tree = proto_item_add_subtree(item, ett_id);
}
}
- length_remaining=tvb_length_remaining(tvb, hoffset);
- if(length_remaining>length)
- length_remaining=length;
+ length_remaining = tvb_length_remaining(tvb, hoffset);
+ if (length_remaining>length)
+ length_remaining = length;
#ifdef REMOVED
/* This is bogus and makes the OID_1.0.9506.1.1.cap file
@@ -3329,28 +3603,28 @@ printf("CHOICE testing potential subdissector class[%p]:%d:(expected)%d tag:%d:
* traces anyway.
* God, this file is a mess and it is my fault. /ronnie
*/
- if(first_pass)
- next_tvb=tvb_new_subset(tvb, hoffset, length_remaining, length);
+ if (first_pass)
+ next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, length);
else
- next_tvb = tvb; /* we didn't make selection on this class/tag so pass it on */
+ next_tvb = tvb; /* we didn't make selection on this class/tag so pass it on */
#endif
- next_tvb=tvb_new_subset(tvb, hoffset, length_remaining, length);
+ next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, length);
#ifdef DEBUG_BER_CHOICE
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(next_tvb,0)>3){
-printf("CHOICE dissect_ber_old_choice(%s) calling subdissector start_offset:%d offset:%d len:%d %02x:%02x:%02x\n",name,start_offset,offset,tvb_length_remaining(next_tvb,0),tvb_get_guint8(next_tvb,0),tvb_get_guint8(next_tvb,1),tvb_get_guint8(next_tvb,2));
-}else{
-printf("CHOICE dissect_ber_old_choice(%s) calling subdissector len:%d\n",name,tvb_length(next_tvb));
+if (tvb_length_remaining(next_tvb, 0) > 3) {
+printf("CHOICE dissect_ber_old_choice(%s) calling subdissector start_offset:%d offset:%d len:%d %02x:%02x:%02x\n", name, start_offset, offset, tvb_length_remaining(next_tvb, 0), tvb_get_guint8(next_tvb, 0), tvb_get_guint8(next_tvb, 1), tvb_get_guint8(next_tvb, 2));
+} else {
+printf("CHOICE dissect_ber_old_choice(%s) calling subdissector len:%d\n", name, tvb_length(next_tvb));
}
}
#endif
@@ -3358,44 +3632,43 @@ printf("CHOICE dissect_ber_old_choice(%s) calling subdissector len:%d\n",name,tv
/* Assume that we have a malformed packet. */
THROW(ReportedBoundsError);
}
- count=ch->func(tree, next_tvb, 0, actx);
+ count = ch->func(tree, next_tvb, 0, actx);
#ifdef DEBUG_BER_CHOICE
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-printf("CHOICE dissect_ber_old_choice(%s) subdissector ate %d bytes\n",name,count);
+printf("CHOICE dissect_ber_old_choice(%s) subdissector ate %d bytes\n", name, count);
}
#endif
- if((count==0)&&(((ch->ber_class==ber_class)&&(ch->tag==-1)&&(ch->flags&BER_FLAGS_NOOWNTAG)) || !first_pass)){
+ if ((count == 0) && (((ch->ber_class == ber_class) && (ch->tag == -1) && (ch->flags & BER_FLAGS_NOOWNTAG)) || !first_pass)) {
/* wrong one, break and try again */
ch++;
#ifdef DEBUG_BER_CHOICE
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-printf("CHOICE dissect_ber_old_choice(%s) trying again\n",name);
+printf("CHOICE dissect_ber_old_choice(%s) trying again\n", name);
}
#endif
goto choice_try_again;
}
- if(!(ch->flags & BER_FLAGS_NOOWNTAG)){
- if(ind)
- {
+ if (!(ch->flags & BER_FLAGS_NOOWNTAG)) {
+ if (ind) {
/* we are traversing a indfinite length choice where we did not pass the tag length */
/* we need to eat the EOC */
- if(show_internal_ber_fields){
+ if (show_internal_ber_fields) {
proto_tree_add_text(tree, tvb, start_offset, count+2, "CHOICE EOC");
}
}
@@ -3404,7 +3677,7 @@ printf("CHOICE dissect_ber_old_choice(%s) trying again\n",name);
}
ch++;
}
- if(branch_taken){
+ if (branch_taken) {
/* none of the branches were taken so set the param
back to -1 */
*branch_taken=-1;
@@ -3417,8 +3690,12 @@ printf("CHOICE dissect_ber_old_choice(%s) trying again\n",name);
/* oops no more entries and we still havent found
* our guy :-(
*/
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "missing_choice_field", "BER Error: This choice field was not found.");
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: This choice field was not found");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "missing_choice_field",
+ "BER Error: This choice field was not found.");
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: This choice field was not found");
return end_offset;
#endif
@@ -3431,36 +3708,43 @@ printf("CHOICE dissect_ber_old_choice(%s) trying again\n",name);
int
dissect_ber_GeneralString(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, char *name_string, int name_len)
{
- gint8 ber_class;
- gboolean pc;
- gint32 tag;
- guint32 len;
- int end_offset;
- int hoffset;
- char str_arr[256];
- guint32 max_len;
- char *str;
+ gint8 ber_class;
+ gboolean pc;
+ gint32 tag;
+ guint32 len;
+ int end_offset;
+ int hoffset;
+ char str_arr[256];
+ guint32 max_len;
+ char *str;
proto_item *cause;
- str=str_arr;
- max_len=255;
- if(name_string){
- str=name_string;
- max_len=name_len;
+ str = str_arr;
+ max_len = 255;
+ if (name_string) {
+ str = name_string;
+ max_len = name_len;
}
hoffset = offset;
/* first we must read the GeneralString header */
- offset=dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
- offset=dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
- end_offset=offset+len;
+ offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
+ offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
+ end_offset = offset + len;
/* sanity check: we only handle Universal GeneralString*/
- if( (ber_class!=BER_CLASS_UNI)
- ||(tag!=BER_UNI_TAG_GENSTR) ){
+ if ( (ber_class != BER_CLASS_UNI)
+ || (tag != BER_UNI_TAG_GENSTR) ) {
tvb_ensure_bytes_exist(tvb, hoffset, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "generalstring_expected", "BER Error: GeneralString expected but class:%s(%d) %s tag:%d was unexpected", val_to_str_const(ber_class,ber_class_codes,"Unknown"), ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: GeneralString expected");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "generalstring_expected",
+ "BER Error: GeneralString expected but class:%s(%d) %s tag:%d was unexpected",
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: GeneralString expected");
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
@@ -3468,14 +3752,14 @@ dissect_ber_GeneralString(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int
return end_offset;
}
- if(len>=(max_len-1)){
- len=max_len-1;
+ if (len >= (max_len - 1)) {
+ len = max_len - 1;
}
tvb_memcpy(tvb, str, offset, len);
str[len]=0;
- if(hf_id >= 0){
+ if (hf_id >= 0) {
proto_tree_add_string(tree, hf_id, tvb, offset, len, str);
}
@@ -3483,44 +3767,53 @@ dissect_ber_GeneralString(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int
}
#endif
-int dissect_ber_constrained_restricted_string(gboolean implicit_tag, gint32 type, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, gint hf_id, tvbuff_t **out_tvb) {
- gint8 ber_class;
- gboolean pc;
- gint32 tag;
- guint32 len;
- int eoffset;
- int hoffset = offset;
+int
+dissect_ber_constrained_restricted_string(gboolean implicit_tag, gint32 type, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, gint hf_id, tvbuff_t **out_tvb) {
+ gint8 ber_class;
+ gboolean pc;
+ gint32 tag;
+ guint32 len;
+ int eoffset;
+ int hoffset = offset;
proto_item *cause;
#ifdef DEBUG_BER
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(tvb,offset)>3){
-printf("RESTRICTED STRING dissect_ber_octet string(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n",name,implicit_tag,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
-}else{
-printf("RESTRICTED STRING dissect_ber_octet_string(%s) entered\n",name);
+if (tvb_length_remaining(tvb, offset) > 3) {
+printf("RESTRICTED STRING dissect_ber_octet string(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n", name, implicit_tag, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("RESTRICTED STRING dissect_ber_octet_string(%s) entered\n", name);
}
}
#endif
- if(!implicit_tag) {
- offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
- offset = get_ber_length(tvb, offset, &len, NULL);
+ if (!implicit_tag) {
+ offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
+ offset = get_ber_length(tvb, offset, &len, NULL);
eoffset = offset + len;
/* sanity check */
- if( (ber_class!=BER_CLASS_UNI)
- ||(tag != type) ){
+ if ( (ber_class != BER_CLASS_UNI)
+ || (tag != type) ) {
tvb_ensure_bytes_exist(tvb, hoffset, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "string_expected", "BER Error: String with tag=%d expected but class:%s(%d) %s tag:%d was unexpected", type, val_to_str_const(ber_class,ber_class_codes,"Unknown"), ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: String expected");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "string_expected",
+ "BER Error: String with tag=%d expected but class:%s(%d) %s tag:%d was unexpected",
+ type,
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: String expected");
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
@@ -3542,19 +3835,19 @@ int
dissect_ber_GeneralString(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, char *name_string, guint name_len)
{
tvbuff_t *out_tvb = NULL;
- gint tvb_len;
+ gint tvb_len;
- offset = dissect_ber_restricted_string(FALSE, BER_UNI_TAG_GeneralString, actx, tree, tvb, offset, hf_id, (name_string)?&out_tvb:NULL);
+ offset = dissect_ber_restricted_string(FALSE, BER_UNI_TAG_GeneralString, actx, tree, tvb, offset, hf_id, (name_string) ? &out_tvb : NULL);
- if(name_string) {
+ if (name_string) {
/*
* XXX - do we want to just get what's left in the tvbuff
* if the full length isn't available in the tvbuff, or
* do we want to throw an exception?
*/
- if(out_tvb) {
+ if (out_tvb) {
tvb_len = tvb_length(out_tvb);
- if((guint)tvb_len >= name_len) {
+ if ((guint)tvb_len >= name_len) {
tvb_memcpy(out_tvb, (guint8*)name_string, 0, name_len-1);
name_string[name_len-1] = '\0';
} else {
@@ -3569,70 +3862,79 @@ dissect_ber_GeneralString(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int
/* 8.19 Encoding of an object identifier value.
*/
-int dissect_ber_object_identifier(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **value_tvb)
+int
+dissect_ber_object_identifier(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **value_tvb)
{
- gint8 ber_class;
- gboolean pc;
- gint32 tag;
- guint32 len;
- int eoffset;
- int hoffset;
- const char *str;
- proto_item *cause;
- header_field_info *hfi;
+ gint8 ber_class;
+ gboolean pc;
+ gint32 tag;
+ guint32 len;
+ int eoffset;
+ int hoffset;
+ const char *str;
+ proto_item *cause;
const gchar *name;
+ header_field_info *hfi;
#ifdef DEBUG_BER
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(tvb,offset)>3){
-printf("OBJECT IDENTIFIER dissect_ber_object_identifier(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n",name,implicit_tag,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
-}else{
-printf("OBJECT IDENTIFIER dissect_ber_object_identifier(%s) entered\n",name);
+if (tvb_length_remaining(tvb, offset) > 3) {
+printf("OBJECT IDENTIFIER dissect_ber_object_identifier(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n", name, implicit_tag, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("OBJECT IDENTIFIER dissect_ber_object_identifier(%s) entered\n", name);
}
}
#endif
- if(!implicit_tag) {
+ if (!implicit_tag) {
hoffset = offset;
/* sanity check */
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
eoffset = offset + len;
- if( (ber_class!=BER_CLASS_UNI)
- ||(tag != BER_UNI_TAG_OID) ){
+ if ( (ber_class != BER_CLASS_UNI)
+ || (tag != BER_UNI_TAG_OID) ) {
tvb_ensure_bytes_exist(tvb, hoffset, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "oid_expected", "BER Error: Object Identifier expected but class:%s(%d) %s tag:%d was unexpected", val_to_str_const(ber_class,ber_class_codes,"Unknown"), ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Object Identifier expected");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "oid_expected",
+ "BER Error: Object Identifier expected but class:%s(%d) %s tag:%d was unexpected",
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Object Identifier expected");
if (decode_unexpected) {
- proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
- dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
+ proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
+ dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
}
return eoffset;
}
} else {
- len=tvb_length_remaining(tvb,offset);
- eoffset=offset+len;
+ len = tvb_length_remaining(tvb, offset);
+ eoffset = offset+len;
}
- actx->created_item=NULL;
+ actx->created_item = NULL;
hfi = proto_registrar_get_nth(hf_id);
if (hfi->type == FT_OID) {
actx->created_item = proto_tree_add_item(tree, hf_id, tvb, offset, len, ENC_BIG_ENDIAN);
} else if (IS_FT_STRING(hfi->type)) {
str = oid_encoded2string(tvb_get_ptr(tvb, offset, len), len);
actx->created_item = proto_tree_add_string(tree, hf_id, tvb, offset, len, str);
- if(actx->created_item){
+ if (actx->created_item) {
/* see if we know the name of this oid */
name = oid_resolved_from_encoded(tvb_get_ptr(tvb, offset, len), len);
- if(name){
+ if (name) {
proto_item_append_text(actx->created_item, " (%s)", name);
}
}
@@ -3646,10 +3948,11 @@ printf("OBJECT IDENTIFIER dissect_ber_object_identifier(%s) entered\n",name);
return eoffset;
}
-int dissect_ber_object_identifier_str(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, const char **value_stringx)
+int
+dissect_ber_object_identifier_str(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, const char **value_stringx)
{
tvbuff_t *value_tvb = NULL;
- guint length;
+ guint length;
offset = dissect_ber_object_identifier(implicit_tag, actx, tree, tvb, offset, hf_id, (value_stringx) ? &value_tvb : NULL);
@@ -3668,45 +3971,46 @@ int dissect_ber_object_identifier_str(gboolean implicit_tag, asn1_ctx_t *actx, p
#define DEBUG_BER_SQ_OF
#endif
-static int dissect_ber_sq_of(gboolean implicit_tag, gint32 type, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
- gint8 classx;
- gboolean pcx, ind = FALSE, ind_field;
- gint32 tagx;
- guint32 lenx;
-
- proto_tree *tree = parent_tree;
- proto_item *item = NULL;
- proto_item *causex;
- int cnt, hoffsetx, end_offset;
+static int
+dissect_ber_sq_of(gboolean implicit_tag, gint32 type, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
+ gint8 classx;
+ gboolean pcx, ind = FALSE, ind_field;
+ gint32 tagx;
+ guint32 lenx;
+
+ proto_tree *tree = parent_tree;
+ proto_item *item = NULL;
+ proto_item *causex;
+ int cnt, hoffsetx, end_offset;
header_field_info *hfi;
- gint length_remaining;
- tvbuff_t *next_tvb;
+ gint length_remaining;
+ tvbuff_t *next_tvb;
#ifdef DEBUG_BER_SQ_OF
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(tvb,offset)>3){
-printf("SQ OF dissect_ber_sq_of(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n",name,implicit_tag,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
-}else{
-printf("SQ OF dissect_ber_sq_of(%s) entered\n",name);
+if (tvb_length_remaining(tvb,offset) > 3) {
+printf("SQ OF dissect_ber_sq_of(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n", name, implicit_tag, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("SQ OF dissect_ber_sq_of(%s) entered\n", name);
}
}
#endif
- if(!implicit_tag){
+ if (!implicit_tag) {
hoffsetx = offset;
/* first we must read the sequence header */
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &classx, &pcx, &tagx);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &lenx, &ind);
- if(ind){
- /* if the length is indefinite we dont really know (yet) where the
+ if (ind) {
+ /* if the length is indefinite we don't really know (yet) where the
* object ends so assume it spans the rest of the tvb for now.
*/
end_offset = offset + lenx;
@@ -3715,24 +4019,34 @@ printf("SQ OF dissect_ber_sq_of(%s) entered\n",name);
}
/* sanity check: we only handle Constructed Universal Sequences */
- if((classx!=BER_CLASS_APP)&&(classx!=BER_CLASS_PRI))
- if(!pcx
- ||(!implicit_tag&&((classx!=BER_CLASS_UNI)
- ||(tagx!=type)))) {
- tvb_ensure_bytes_exist(tvb, hoffsetx, 2);
- causex = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, lenx, (type==BER_UNI_TAG_SEQUENCE)?"set_of_expected":"sequence_of_expected", "BER Error: %s Of expected but class:%s(%d) %s tag:%d was unexpected",
- (type==BER_UNI_TAG_SEQUENCE)?"Set":"Sequence", val_to_str_const(classx,ber_class_codes,"Unknown"), classx, pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tagx);
- expert_add_info_format(actx->pinfo, causex, PI_MALFORMED, PI_WARN, "BER Error: %s Of expected",(type==BER_UNI_TAG_SEQUENCE)?"Set":"Sequence");
- if (decode_unexpected) {
- proto_tree *unknown_tree = proto_item_add_subtree(causex, ett_ber_unknown);
- dissect_unknown_ber(actx->pinfo, tvb, hoffsetx, unknown_tree);
+ if ((classx != BER_CLASS_APP) && (classx != BER_CLASS_PRI)) {
+ if (!pcx
+ || (!implicit_tag && ((classx != BER_CLASS_UNI)
+ || (tagx != type)))) {
+ tvb_ensure_bytes_exist(tvb, hoffsetx, 2);
+ causex = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, lenx,
+ (type == BER_UNI_TAG_SEQUENCE) ? "set_of_expected" : "sequence_of_expected",
+ "BER Error: %s Of expected but class:%s(%d) %s tag:%d was unexpected",
+ (type == BER_UNI_TAG_SEQUENCE) ? "Set" : "Sequence",
+ val_to_str_const(classx, ber_class_codes, "Unknown"),
+ classx, pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tagx);
+ expert_add_info_format(
+ actx->pinfo, causex, PI_MALFORMED, PI_WARN,
+ "BER Error: %s Of expected",
+ (type == BER_UNI_TAG_SEQUENCE) ? "Set":"Sequence");
+ if (decode_unexpected) {
+ proto_tree *unknown_tree = proto_item_add_subtree(causex, ett_ber_unknown);
+ dissect_unknown_ber(actx->pinfo, tvb, hoffsetx, unknown_tree);
+ }
+ return end_offset;
}
- return end_offset;
}
} else {
/* the tvb length should be correct now nope we could be comming from an implicit choice or sequence, thus we
read the items we match and return the length*/
- lenx=tvb_length_remaining(tvb,offset);
+ lenx = tvb_length_remaining(tvb, offset);
end_offset = offset + lenx;
}
@@ -3744,19 +4058,19 @@ printf("SQ OF dissect_ber_sq_of(%s) entered\n",name);
* dissecting a single item.
*/
/* XXX Do we really need to count them at all ? ronnie */
- if(tvb_length_remaining(tvb, offset)==tvb_reported_length_remaining(tvb, offset)){
- while (offset < end_offset){
+ if (tvb_length_remaining(tvb, offset) == tvb_reported_length_remaining(tvb, offset)) {
+ while (offset < end_offset) {
guint32 len;
- gint s_offset;
+ gint s_offset;
s_offset = offset;
- /*if(ind){ this sequence of was of indefinite length, if this is implicit indefinite impossible maybe
+ /*if (ind) { this sequence of was of indefinite length, if this is implicit indefinite impossible maybe
but ber dissector uses this to eat the tag length then pass into here... EOC still on there...*/
- if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0)){
+ if ((tvb_get_guint8(tvb, offset) == 0) && (tvb_get_guint8(tvb, offset+1) == 0)) {
break;
}
- /*}*/
+ /* } */
/* read header and len for next field */
offset = get_ber_identifier(tvb, offset, NULL, NULL, NULL);
@@ -3772,15 +4086,15 @@ printf("SQ OF dissect_ber_sq_of(%s) entered\n",name);
offset = hoffsetx;
/* create subtree */
- if(hf_id >= 0) {
+ if (hf_id >= 0) {
hfi = proto_registrar_get_nth(hf_id);
- if(parent_tree){
- if(hfi->type == FT_NONE) {
+ if (parent_tree) {
+ if (hfi->type == FT_NONE) {
item = proto_tree_add_item(parent_tree, hf_id, tvb, offset, lenx, ENC_BIG_ENDIAN);
proto_item_append_text(item, ":");
} else {
item = proto_tree_add_uint(parent_tree, hf_id, tvb, offset, lenx, cnt);
- proto_item_append_text(item, (cnt==1)?" item":" items");
+ proto_item_append_text(item, (cnt == 1) ? " item" : " items");
}
tree = proto_item_add_subtree(item, ett_id);
ber_check_items (cnt, min_len, max_len, actx, item);
@@ -3788,48 +4102,54 @@ printf("SQ OF dissect_ber_sq_of(%s) entered\n",name);
}
/* loop over all entries until we reach the end of the sequence */
- while (offset < end_offset){
- gint8 ber_class;
- gboolean pc;
- gint32 tag;
- guint32 len;
- int eoffset;
- int hoffset;
+ while (offset < end_offset) {
+ gint8 ber_class;
+ gboolean pc;
+ gint32 tag;
+ guint32 len;
+ int eoffset;
+ int hoffset;
proto_item *cause;
- gboolean imp_tag;
+ gboolean imp_tag;
hoffset = offset;
- /*if(ind){ this sequence was of indefinite length, if this is implicit indefinite impossible maybe
+ /*if (ind) { this sequence was of indefinite length, if this is implicit indefinite impossible maybe
but ber dissector uses this to eat the tag length then pass into here... EOC still on there...*/
- if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0)){
- if(show_internal_ber_fields){
+ if ((tvb_get_guint8(tvb, offset) == 0) && (tvb_get_guint8(tvb, offset+1) == 0)) {
+ if (show_internal_ber_fields) {
proto_tree_add_text(tree, tvb, hoffset, end_offset-hoffset, "SEQ OF EOC");
}
return offset+2;
}
/*}*/
/* read header and len for next field */
- offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
- offset = get_ber_length(tvb, offset, &len, &ind_field);
+ offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
+ offset = get_ber_length(tvb, offset, &len, &ind_field);
eoffset = offset + len;
/* Make sure we move forward */
if (eoffset <= hoffset)
THROW(ReportedBoundsError);
- if((ber_class==BER_CLASS_UNI)&&(tag==BER_UNI_TAG_EOC)){
+ if ((ber_class == BER_CLASS_UNI) && (tag == BER_UNI_TAG_EOC)) {
/* This is a zero length sequence of*/
hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
return eoffset;
}
/* verify that this one is the one we want */
- /* ahup if we are implicit then we return to the uper layer how much we have used */
- if(seq->ber_class!=BER_CLASS_ANY){
- if((seq->ber_class!=ber_class)
- ||(seq->tag!=tag) ){
- if(!(seq->flags & BER_FLAGS_NOTCHKTAG)) {
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "wrong_field", "BER Error: Wrong field in SQ OF(tag %u expected %u)",tag,seq->tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Wrong field in Sequence Of");
+ /* ahup if we are implicit then we return to the upper layer how much we have used */
+ if (seq->ber_class != BER_CLASS_ANY) {
+ if ((seq->ber_class != ber_class)
+ || (seq->tag != tag) ) {
+ if (!(seq->flags & BER_FLAGS_NOTCHKTAG)) {
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "wrong_field",
+ "BER Error: Wrong field in SQ OF(tag %u expected %u)",
+ tag,
+ seq->tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Wrong field in Sequence Of");
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
@@ -3841,12 +4161,12 @@ printf("SQ OF dissect_ber_sq_of(%s) entered\n",name);
}
}
- if(!(seq->flags & BER_FLAGS_NOOWNTAG) && !(seq->flags & BER_FLAGS_IMPLTAG)) {
+ if (!(seq->flags & BER_FLAGS_NOOWNTAG) && !(seq->flags & BER_FLAGS_IMPLTAG)) {
/* dissect header and len for field */
hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
hoffset = dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
}
- if((seq->flags == BER_FLAGS_IMPLTAG)&&(seq->ber_class==BER_CLASS_CON)) {
+ if ((seq->flags == BER_FLAGS_IMPLTAG) && (seq->ber_class == BER_CLASS_CON)) {
/* Constructed sequence of with a tag */
/* dissect header and len for field */
hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
@@ -3854,13 +4174,13 @@ printf("SQ OF dissect_ber_sq_of(%s) entered\n",name);
/* Function has IMPLICIT TAG */
}
- length_remaining=tvb_length_remaining(tvb, hoffset);
+ length_remaining = tvb_length_remaining(tvb, hoffset);
if (length_remaining>eoffset-hoffset)
- length_remaining=eoffset-hoffset;
+ length_remaining = eoffset-hoffset;
next_tvb = tvb_new_subset(tvb, hoffset, length_remaining, eoffset-hoffset);
imp_tag = FALSE;
- if(seq->flags == BER_FLAGS_IMPLTAG)
+ if (seq->flags == BER_FLAGS_IMPLTAG)
imp_tag = TRUE;
/* call the dissector for this field */
seq->func(imp_tag, next_tvb, 0, actx, tree, *seq->p_id);
@@ -3872,26 +4192,33 @@ printf("SQ OF dissect_ber_sq_of(%s) entered\n",name);
}
/* if we didnt end up at exactly offset, then we ate too many bytes */
- if(offset != end_offset) {
+ if (offset != end_offset) {
tvb_ensure_bytes_exist(tvb, offset-2, 2);
- causex =proto_tree_add_string_format(tree, hf_ber_error, tvb, offset-2, 2, "illegal_length", "BER Error: %s Of ate %d too many bytes",
- (type==BER_UNI_TAG_SEQUENCE)?"Set":"Sequence", offset-end_offset);
- expert_add_info_format(actx->pinfo, causex, PI_MALFORMED, PI_WARN, "BER Error:too many byte in %s",(type==BER_UNI_TAG_SEQUENCE)?"Set":"Sequence");
+ causex = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset-2, 2, "illegal_length",
+ "BER Error: %s Of ate %d too many bytes",
+ (type == BER_UNI_TAG_SEQUENCE) ? "Set" : "Sequence",
+ offset - end_offset);
+ expert_add_info_format(
+ actx->pinfo, causex, PI_MALFORMED, PI_WARN,
+ "BER Error:too many byte in %s",
+ (type == BER_UNI_TAG_SEQUENCE) ? "Set" : "Sequence");
}
return end_offset;
}
-static int dissect_ber_old_sq_of(gboolean implicit_tag, gint32 type, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_old_sequence_t *seq, gint hf_id, gint ett_id) {
- gint8 classx;
- gboolean pcx, ind = FALSE, ind_field;
- gint32 tagx;
- guint32 lenx;
+static int
+dissect_ber_old_sq_of(gboolean implicit_tag, gint32 type, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_old_sequence_t *seq, gint hf_id, gint ett_id) {
+ gint8 classx;
+ gboolean pcx, ind = FALSE, ind_field;
+ gint32 tagx;
+ guint32 lenx;
proto_tree *tree = parent_tree;
proto_item *item = NULL;
proto_item *causex;
- int cnt, hoffsetx, end_offset;
+ int cnt, hoffsetx, end_offset;
header_field_info *hfi;
/*gint length_remaining;*/
@@ -3899,27 +4226,27 @@ static int dissect_ber_old_sq_of(gboolean implicit_tag, gint32 type, asn1_ctx_t
{
const char *name;
header_field_info *hfinfo;
-if(hf_id>=0){
+if (hf_id >= 0) {
hfinfo = proto_registrar_get_nth(hf_id);
-name=hfinfo->name;
+name = hfinfo->name;
} else {
-name="unnamed";
+name = "unnamed";
}
-if(tvb_length_remaining(tvb,offset)>3){
-printf("SQ OF dissect_ber_old_sq_of(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n",name,implicit_tag,offset,tvb_length_remaining(tvb,offset),tvb_get_guint8(tvb,offset),tvb_get_guint8(tvb,offset+1),tvb_get_guint8(tvb,offset+2));
-}else{
-printf("SQ OF dissect_ber_old_sq_of(%s) entered\n",name);
+if (tvb_length_remaining(tvb, offset) > 3) {
+printf("SQ OF dissect_ber_old_sq_of(%s) entered implicit_tag:%d offset:%d len:%d %02x:%02x:%02x\n", name, implicit_tag, offset, tvb_length_remaining(tvb, offset), tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2));
+} else {
+printf("SQ OF dissect_ber_old_sq_of(%s) entered\n", name);
}
}
#endif
- if(!implicit_tag){
+ if (!implicit_tag) {
hoffsetx = offset;
/* first we must read the sequence header */
offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &classx, &pcx, &tagx);
offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &lenx, &ind);
- if(ind){
- /* if the length is indefinite we dont really know (yet) where the
+ if (ind) {
+ /* if the length is indefinite we don't really know (yet) where the
* object ends so assume it spans the rest of the tvb for now.
*/
end_offset = offset + lenx;
@@ -3928,24 +4255,35 @@ printf("SQ OF dissect_ber_old_sq_of(%s) entered\n",name);
}
/* sanity check: we only handle Constructed Universal Sequences */
- if((classx!=BER_CLASS_APP)&&(classx!=BER_CLASS_PRI))
- if(!pcx
- ||(!implicit_tag&&((classx!=BER_CLASS_UNI)
- ||(tagx!=type)))) {
- tvb_ensure_bytes_exist(tvb, hoffsetx, 2);
- causex = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, lenx, (type==BER_UNI_TAG_SEQUENCE)?"set_of_expected":"sequence_of_expected", "BER Error: %s Of expected but class:%s(%d) %s tag:%d was unexpected",
- (type==BER_UNI_TAG_SEQUENCE)?"Set":"Sequence", val_to_str_const(classx,ber_class_codes,"Unknown"), classx, pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tagx);
- expert_add_info_format(actx->pinfo, causex, PI_MALFORMED, PI_WARN, "BER Error: %s Of expected",(type==BER_UNI_TAG_SEQUENCE)?"Set":"Sequence");
- if (decode_unexpected) {
- proto_tree *unknown_tree = proto_item_add_subtree(causex, ett_ber_unknown);
- dissect_unknown_ber(actx->pinfo, tvb, hoffsetx, unknown_tree);
+ if ((classx != BER_CLASS_APP) && (classx != BER_CLASS_PRI)) {
+ if (!pcx
+ || (!implicit_tag && ((classx != BER_CLASS_UNI)
+ || (tagx != type)))) {
+ tvb_ensure_bytes_exist(tvb, hoffsetx, 2);
+ causex = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, lenx,
+ (type == BER_UNI_TAG_SEQUENCE) ? "set_of_expected" : "sequence_of_expected",
+ "BER Error: %s Of expected but class:%s(%d) %s tag:%d was unexpected",
+ (type == BER_UNI_TAG_SEQUENCE) ? "Set" : "Sequence",
+ val_to_str_const(classx, ber_class_codes, "Unknown"),
+ classx,
+ pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tagx);
+ expert_add_info_format(
+ actx->pinfo, causex, PI_MALFORMED, PI_WARN,
+ "BER Error: %s Of expected",
+ (type == BER_UNI_TAG_SEQUENCE) ? "Set" : "Sequence");
+ if (decode_unexpected) {
+ proto_tree *unknown_tree = proto_item_add_subtree(causex, ett_ber_unknown);
+ dissect_unknown_ber(actx->pinfo, tvb, hoffsetx, unknown_tree);
+ }
+ return end_offset;
}
- return end_offset;
}
} else {
/* the tvb length should be correct now nope we could be comming from an implicit choice or sequence, thus we
read the items we match and return the length*/
- lenx=tvb_length_remaining(tvb,offset);
+ lenx = tvb_length_remaining(tvb, offset);
end_offset = offset + lenx;
}
@@ -3957,15 +4295,15 @@ printf("SQ OF dissect_ber_old_sq_of(%s) entered\n",name);
* dissecting a single item.
*/
/* XXX Do we really need to count them at all ? ronnie */
- if(tvb_length_remaining(tvb, offset)==tvb_reported_length_remaining(tvb, offset)){
- while (offset < end_offset){
+ if (tvb_length_remaining(tvb, offset) == tvb_reported_length_remaining(tvb, offset)) {
+ while (offset < end_offset) {
guint32 len;
- gint s_offset;
+ gint s_offset;
s_offset = offset;
- if(ind){ /* this sequence of was of indefinite length, so check for EOC */
- if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0)){
+ if (ind) { /* this sequence of was of indefinite length, so check for EOC */
+ if ((tvb_get_guint8(tvb, offset) == 0) && (tvb_get_guint8(tvb, offset+1) == 0)) {
break;
}
}
@@ -3984,34 +4322,34 @@ printf("SQ OF dissect_ber_old_sq_of(%s) entered\n",name);
offset = hoffsetx;
/* create subtree */
- if(hf_id >= 0) {
+ if (hf_id >= 0) {
hfi = proto_registrar_get_nth(hf_id);
- if(parent_tree){
- if(hfi->type == FT_NONE) {
+ if (parent_tree) {
+ if (hfi->type == FT_NONE) {
item = proto_tree_add_item(parent_tree, hf_id, tvb, offset, lenx, ENC_BIG_ENDIAN);
proto_item_append_text(item, ":");
} else {
item = proto_tree_add_uint(parent_tree, hf_id, tvb, offset, lenx, cnt);
- proto_item_append_text(item, (cnt==1)?" item":" items");
+ proto_item_append_text(item, (cnt == 1) ? " item" : " items");
}
tree = proto_item_add_subtree(item, ett_id);
}
}
/* loop over all entries until we reach the end of the sequence */
- while (offset < end_offset){
- gint8 ber_class;
- gboolean pc;
- gint32 tag;
- guint32 len;
- int eoffset;
- int hoffset;
+ while (offset < end_offset) {
+ gint8 ber_class;
+ gboolean pc;
+ gint32 tag;
+ guint32 len;
+ int eoffset;
+ int hoffset;
proto_item *cause;
hoffset = offset;
- if(ind){ /*this sequence of was of indefinite length, so check for EOC */
- if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0)){
- if(show_internal_ber_fields){
+ if (ind) { /*this 'sequence of' was of indefinite length, so check for EOC */
+ if ((tvb_get_guint8(tvb, offset) == 0) && (tvb_get_guint8(tvb, offset+1) == 0)) {
+ if (show_internal_ber_fields) {
proto_tree_add_text(tree, tvb, hoffset, end_offset-hoffset, "SEQ OF EOC");
}
return offset+2;
@@ -4025,20 +4363,24 @@ printf("SQ OF dissect_ber_old_sq_of(%s) entered\n",name);
if (eoffset <= hoffset)
THROW(ReportedBoundsError);
- if((ber_class==BER_CLASS_UNI)&&(tag==BER_UNI_TAG_EOC)){
+ if ((ber_class == BER_CLASS_UNI) && (tag == BER_UNI_TAG_EOC)) {
/* This is a zero length sequence of*/
hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
return eoffset;
}
/* verify that this one is the one we want */
- /* ahup if we are implicit then we return to the uper layer how much we have used */
- if(seq->ber_class!=BER_CLASS_ANY){
- if((seq->ber_class!=ber_class)
- ||(seq->tag!=tag) ){
- if(!(seq->flags & BER_FLAGS_NOTCHKTAG)) {
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "wrong_field", "BER Error: Wrong field in SQ OF");
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: Wrong field in Sequence Of");
+ /* ahup if we are implicit then we return to the upper layer how much we have used */
+ if (seq->ber_class != BER_CLASS_ANY) {
+ if ((seq->ber_class != ber_class)
+ || (seq->tag != tag) ) {
+ if (!(seq->flags & BER_FLAGS_NOTCHKTAG)) {
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "wrong_field",
+ "BER Error: Wrong field in SQ OF");
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: Wrong field in Sequence Of");
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
@@ -4050,21 +4392,21 @@ printf("SQ OF dissect_ber_old_sq_of(%s) entered\n",name);
}
}
- if(!(seq->flags & BER_FLAGS_NOOWNTAG) && !(seq->flags & BER_FLAGS_IMPLTAG)) {
+ if (!(seq->flags & BER_FLAGS_NOOWNTAG) && !(seq->flags & BER_FLAGS_IMPLTAG)) {
/* dissect header and len for field */
hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
hoffset = dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
}
- if((seq->flags == BER_FLAGS_IMPLTAG)&&(seq->ber_class==BER_CLASS_CON)) {
+ if ((seq->flags == BER_FLAGS_IMPLTAG) && (seq->ber_class == BER_CLASS_CON)) {
/* Constructed sequence of with a tag */
/* dissect header and len for field */
hoffset = dissect_ber_identifier(actx->pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
hoffset = dissect_ber_length(actx->pinfo, tree, tvb, hoffset, NULL, NULL);
}
- /*length_remaining=tvb_length_remaining(tvb, hoffset);
- if (length_remaining>eoffset-hoffset)
- length_remaining=eoffset-hoffset;*/
+ /*length_remaining = tvb_length_remaining(tvb, hoffset);
+ if (length_remaining > (eoffset - hoffset))
+ length_remaining = eoffset - hoffset;*/
/* call the dissector for this field */
@@ -4076,73 +4418,93 @@ printf("SQ OF dissect_ber_old_sq_of(%s) entered\n",name);
offset = eoffset;
}
- /* if we didnt end up at exactly offset, then we ate too many bytes */
- if(offset != end_offset) {
+ /* if we didn't end up at exactly offset, then we ate too many bytes */
+ if (offset != end_offset) {
tvb_ensure_bytes_exist(tvb, offset-2, 2);
- causex =proto_tree_add_string_format(tree, hf_ber_error, tvb, offset-2, 2, "illegal_length", "BER Error: %s Of ate %d too many bytes",
- (type==BER_UNI_TAG_SEQUENCE)?"Set":"Sequence", offset-end_offset);
- expert_add_info_format(actx->pinfo, causex, PI_MALFORMED, PI_WARN, "BER Error:too many byte in %s",(type==BER_UNI_TAG_SEQUENCE)?"Set":"Sequence");
+ causex =proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset-2, 2, "illegal_length",
+ "BER Error: %s Of ate %d too many bytes",
+ (type == BER_UNI_TAG_SEQUENCE) ? "Set" : "Sequence",
+ offset-end_offset);
+ expert_add_info_format(
+ actx->pinfo, causex, PI_MALFORMED, PI_WARN,
+ "BER Error:too many byte in %s",
+ (type == BER_UNI_TAG_SEQUENCE) ? "Set" : "Sequence");
}
return end_offset;
}
-int dissect_ber_constrained_sequence_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
+int
+dissect_ber_constrained_sequence_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
return dissect_ber_sq_of(implicit_tag, BER_UNI_TAG_SEQUENCE, actx, parent_tree, tvb, offset, min_len, max_len, seq, hf_id, ett_id);
}
-int dissect_ber_sequence_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
+int
+dissect_ber_sequence_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
return dissect_ber_sq_of(implicit_tag, BER_UNI_TAG_SEQUENCE, actx, parent_tree, tvb, offset, NO_BOUND, NO_BOUND, seq, hf_id, ett_id);
}
-int dissect_ber_constrained_set_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
+int
+dissect_ber_constrained_set_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
return dissect_ber_sq_of(implicit_tag, BER_UNI_TAG_SET, actx, parent_tree, tvb, offset, min_len, max_len, seq, hf_id, ett_id);
}
-int dissect_ber_set_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
+int
+dissect_ber_set_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
return dissect_ber_sq_of(implicit_tag, BER_UNI_TAG_SET, actx, parent_tree, tvb, offset, NO_BOUND, NO_BOUND, seq, hf_id, ett_id);
}
-int dissect_ber_old_sequence_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_old_sequence_t *seq, gint hf_id, gint ett_id) {
+int
+dissect_ber_old_sequence_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_old_sequence_t *seq, gint hf_id, gint ett_id) {
return dissect_ber_old_sq_of(implicit_tag, BER_UNI_TAG_SEQUENCE, actx, parent_tree, tvb, offset, seq, hf_id, ett_id);
}
-int dissect_ber_old_set_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_old_sequence_t *seq, gint hf_id, gint ett_id) {
+int
+dissect_ber_old_set_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_old_sequence_t *seq, gint hf_id, gint ett_id) {
return dissect_ber_old_sq_of(implicit_tag, BER_UNI_TAG_SET, actx, parent_tree, tvb, offset, seq, hf_id, ett_id);
}
int
dissect_ber_GeneralizedTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id)
{
- char str[35];
- int tmp_int;
+ char str[35];
+ int tmp_int;
const guint8 *tmpstr;
- char *strptr;
- char first_delim[2];
- int first_digits;
- char second_delim[2];
- int second_digits;
- int ret;
- gint8 ber_class;
- gboolean pc;
- gint32 tag;
- guint32 len;
- int end_offset;
- int hoffset;
- proto_item *cause;
+ char *strptr;
+ char first_delim[2];
+ int first_digits;
+ char second_delim[2];
+ int second_digits;
+ int ret;
+ gint8 ber_class;
+ gboolean pc;
+ gint32 tag;
+ guint32 len;
+ int end_offset;
+ int hoffset;
+ proto_item *cause;
- if(!implicit_tag){
+ if (!implicit_tag) {
hoffset = offset;
- offset=dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
- offset=dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
- end_offset=offset+len;
+ offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
+ offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
+ end_offset = offset+len;
/* sanity check. we only handle universal/generalized time */
- if( (ber_class!=BER_CLASS_UNI)
- ||(tag!=BER_UNI_TAG_GeneralizedTime)){
+ if ( (ber_class != BER_CLASS_UNI)
+ || (tag != BER_UNI_TAG_GeneralizedTime)) {
tvb_ensure_bytes_exist(tvb, hoffset, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "generalized_time_expected", "BER Error: GeneralizedTime expected but class:%s(%d) %s tag:%d was unexpected", val_to_str_const(ber_class,ber_class_codes,"Unknown"), ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: GeneralizedTime expected");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "generalized_time_expected",
+ "BER Error: GeneralizedTime expected but class:%s(%d) %s tag:%d was unexpected",
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: GeneralizedTime expected");
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
@@ -4150,13 +4512,18 @@ dissect_ber_GeneralizedTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree
return end_offset;
}
} else {
- len=tvb_length_remaining(tvb,offset);
- end_offset=offset+len;
+ len = tvb_length_remaining(tvb, offset);
+ end_offset = offset+len;
}
- if (len < 14 || len > 23) {
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "illegal_length", "BER Error: GeneralizedTime invalid length: %u", len);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: GeneralizedTime invalid length");
+ if ((len < 14) || (len > 23)) {
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "illegal_length",
+ "BER Error: GeneralizedTime invalid length: %u",
+ len);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: GeneralizedTime invalid length");
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, offset, unknown_tree);
@@ -4164,20 +4531,25 @@ dissect_ber_GeneralizedTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree
return end_offset;
}
- tmpstr=tvb_get_ephemeral_string(tvb, offset, len);
+ tmpstr = tvb_get_ephemeral_string(tvb, offset, len);
strptr = str;
/* those fields are allways present */
strptr += g_snprintf(str, 20, "%.4s-%.2s-%.2s %.2s:%.2s:%.2s",
tmpstr, tmpstr+4, tmpstr+6, tmpstr+8,
tmpstr+10, tmpstr+12);
- first_delim[0]=0;
- second_delim[0]=0;
+ first_delim[0] = 0;
+ second_delim[0] = 0;
ret = sscanf( tmpstr, "%14d%1[.,+-Z]%4d%1[+-Z]%4d", &tmp_int, first_delim, &first_digits, second_delim, &second_digits);
/* tmp_int does not contain valid value bacause of overflow but we use it just for format checking */
if (ret < 1) {
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "invalid_generalized_time", "BER Error: GeneralizedTime invalid format: %s", tmpstr);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: GeneralizedTime invalid format");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "invalid_generalized_time",
+ "BER Error: GeneralizedTime invalid format: %s",
+ tmpstr);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: GeneralizedTime invalid format");
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, offset, unknown_tree);
@@ -4218,7 +4590,7 @@ dissect_ber_GeneralizedTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree
break;
}
- if(hf_id >= 0){
+ if (hf_id >= 0) {
proto_tree_add_string(tree, hf_id, tvb, offset, len, str);
}
@@ -4230,31 +4602,36 @@ dissect_ber_GeneralizedTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree
int
dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id)
{
- char outstr[33];
- char *outstrptr = outstr;
+ char outstr[33];
+ char *outstrptr = outstr;
const guint8 *instr;
- gint8 ber_class;
- gboolean pc;
- gint32 tag;
- guint32 len, i, n;
- int hoffset;
- proto_item *cause;
- proto_tree *error_tree;
- gchar *error_str = NULL;
+ gint8 ber_class;
+ gboolean pc;
+ gint32 tag;
+ guint32 len, i, n;
+ int hoffset;
+ proto_item *cause;
+ proto_tree *error_tree;
+ gchar *error_str = NULL;
- if(!implicit_tag){
+ if (!implicit_tag) {
hoffset = offset;
- offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
- offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
+ offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
+ offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL);
/* sanity check: we only handle UTCTime */
- if( (ber_class!=BER_CLASS_UNI) || (tag!=BER_UNI_TAG_UTCTime) ) {
+ if ( (ber_class != BER_CLASS_UNI) || (tag != BER_UNI_TAG_UTCTime) ) {
tvb_ensure_bytes_exist(tvb, hoffset, 2);
- cause = proto_tree_add_string_format(tree, hf_ber_error, tvb, offset, len, "utctime_expected",
- "BER Error: UTCTime expected but class:%s(%d) %s tag:%d was unexpected",
- val_to_str_const(ber_class,ber_class_codes,"Unknown"), ber_class,
- pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: UTCTime expected");
+ cause = proto_tree_add_string_format(
+ tree, hf_ber_error, tvb, offset, len, "utctime_expected",
+ "BER Error: UTCTime expected but class:%s(%d) %s tag:%d was unexpected",
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class,
+ pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: UTCTime expected");
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
@@ -4262,10 +4639,10 @@ dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, t
return offset+len;
}
} else {
- len = tvb_length_remaining(tvb,offset);
+ len = tvb_length_remaining(tvb, offset);
}
- if (len < 10 || len > 19) {
+ if ((len < 10) || (len > 19)) {
error_str = ep_strdup_printf("BER Error: UTCTime invalid length: %u", len);
instr = tvb_get_ephemeral_string(tvb, offset, len > 19 ? 19 : len);
goto malformed;
@@ -4274,8 +4651,8 @@ dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, t
instr = tvb_get_ephemeral_string(tvb, offset, len);
/* YYMMDDhhmm */
- for(i=0;i<10;i++) {
- if(instr[i] < '0' || instr[i] > '9') {
+ for (i=0; i<10; i++) {
+ if ((instr[i] < '0') || (instr[i] > '9')) {
error_str = "BER Error: malformed UTCTime encoding, "
"first 10 octets have to contain YYMMDDhhmm in digits";
goto malformed;
@@ -4285,10 +4662,10 @@ dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, t
outstrptr+= 14;
/* (ss)? */
- if(len >= 12) {
- if(instr[i] >= '0' && instr[i] <= '9') {
+ if (len >= 12) {
+ if ((instr[i] >= '0') && (instr[i] <= '9')) {
i++;
- if(instr[i] >= '0' && instr[i] <= '9') {
+ if ((instr[i] >= '0') && (instr[i] <= '9')) {
i++;
g_snprintf(outstrptr, 4, ":%.2s", instr+10);
outstrptr+=3;
@@ -4304,7 +4681,7 @@ dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, t
/* Z|([+-]hhmm) */
switch (instr[i]) {
case 'Z':
- if(len!=i+1) {
+ if (len != (i+1)) {
error_str = "BER Error: malformed UTCTime encoding, "
"there must be no further octets after \'Z\'";
goto malformed;
@@ -4314,13 +4691,13 @@ dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, t
break;
case '-':
case '+':
- if(len!=i+5) {
+ if (len != (i+5)) {
error_str = "BER Error: malformed UTCTime encoding, "
"4 digits must follow on \'+\' resp. \'-\'";
goto malformed;
}
- for(n=i+1;n<i+5;n++) {
- if(instr[n] < '0' || instr[n] > '9') {
+ for (n=i+1; n<i+5; n++) {
+ if ((instr[n] < '0') || (instr[n] > '9')) {
error_str = "BER Error: malformed UTCTime encoding, "
"4 digits must follow on \'+\' resp. \'-\'";
goto malformed;
@@ -4337,51 +4714,59 @@ dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, t
break;
}
- if(len!=i) {
- error_str = ep_strdup_printf("BER Error: malformed UTCTime encoding, "
- "%d unexpected character%s after %dth octet",
- len-i, (len==i-1?"s":""), i);
+ if (len != i) {
+ error_str = ep_strdup_printf(
+ "BER Error: malformed UTCTime encoding, %d unexpected character%s after %dth octet",
+ len - i,
+ (len == (i - 1) ? "s" : ""),
+ i);
goto malformed;
}
- if(hf_id >= 0){
+ if (hf_id >= 0) {
proto_tree_add_string(tree, hf_id, tvb, offset, len, outstr);
}
return offset+len;
malformed:
- if(hf_id >= 0){
+ if (hf_id >= 0) {
cause = proto_tree_add_string(tree, hf_id, tvb, offset, len, instr);
error_tree = proto_item_add_subtree(cause, ett_ber_unknown);
} else {
error_tree = tree;
}
- cause = proto_tree_add_string_format(error_tree, hf_ber_error, tvb, offset, len, "invalid_utctime", "%s", error_str);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: malformed UTCTime encoding");
+ cause = proto_tree_add_string_format(
+ error_tree, hf_ber_error, tvb, offset, len, "invalid_utctime",
+ "%s",
+ error_str);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: malformed UTCTime encoding");
return offset+len;
}
/* 8.6 Encoding of a bitstring value */
-int dissect_ber_constrained_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, const asn_namedbit *named_bits, gint hf_id, gint ett_id, tvbuff_t **out_tvb)
+int
+dissect_ber_constrained_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, const asn_namedbit *named_bits, gint hf_id, gint ett_id, tvbuff_t **out_tvb)
{
- gint8 ber_class;
- gboolean pc, ind;
- gint32 tag;
- guint32 len, byteno;
- guint8 pad=0, b0, b1, val, *bitstring;
- int end_offset;
- int hoffset;
+ gint8 ber_class;
+ gboolean pc, ind;
+ gint32 tag;
+ guint32 len, byteno;
+ guint8 pad = 0, b0, b1, val, *bitstring;
+ int end_offset;
+ int hoffset;
proto_item *item = NULL;
proto_item *cause;
proto_tree *tree = NULL;
- const asn_namedbit *nb;
const char *sep;
- gboolean term;
+ gboolean term;
+ const asn_namedbit *nb;
- if(!implicit_tag){
+ if (!implicit_tag) {
hoffset = offset;
/* read header and len for the octet string */
offset = dissect_ber_identifier(actx->pinfo, parent_tree, tvb, offset, &ber_class, &pc, &tag);
@@ -4396,12 +4781,19 @@ int dissect_ber_constrained_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, p
So here we relax it for APPLICATION tags. CONTEXT tags may
still cause a problem. */
- if(!implicit_tag && (ber_class!=BER_CLASS_APP)) {
- if( (ber_class!=BER_CLASS_UNI)
- ||(tag!=BER_UNI_TAG_BITSTRING) ){
+ if (!implicit_tag && (ber_class != BER_CLASS_APP)) {
+ if ( (ber_class != BER_CLASS_UNI)
+ || (tag != BER_UNI_TAG_BITSTRING) ) {
tvb_ensure_bytes_exist(tvb, hoffset, 2);
- cause = proto_tree_add_string_format(parent_tree, hf_ber_error, tvb, offset, len, "bitstring_expected", "BER Error: BitString expected but class:%s(%d) %s tag:%d was unexpected", val_to_str_const(ber_class,ber_class_codes,"Unknown"), ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tag);
- expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: BitString expected");
+ cause = proto_tree_add_string_format(
+ parent_tree, hf_ber_error, tvb, offset, len, "bitstring_expected",
+ "BER Error: BitString expected but class:%s(%d) %s tag:%d was unexpected",
+ val_to_str_const(ber_class, ber_class_codes, "Unknown"),
+ ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
+ tag);
+ expert_add_info_format(
+ actx->pinfo, cause, PI_MALFORMED, PI_WARN,
+ "BER Error: BitString expected");
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree);
@@ -4411,40 +4803,41 @@ int dissect_ber_constrained_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, p
}
} else {
pc=0;
- len=tvb_length_remaining(tvb,offset);
- end_offset=offset+len;
+ len = tvb_length_remaining(tvb, offset);
+ end_offset = offset+len;
}
actx->created_item = NULL;
- if(pc) {
+ if (pc) {
/* constructed */
/* TO DO */
} else {
/* primitive */
pad = tvb_get_guint8(tvb, offset);
- if(pad == 0 && len == 1) {
+ if ((pad == 0) && (len == 1)) {
/* empty */
proto_tree_add_item(parent_tree, hf_ber_bitstring_empty, tvb, offset, 1, ENC_BIG_ENDIAN);
} else {
/* padding */
proto_item *pad_item = proto_tree_add_item(parent_tree, hf_ber_bitstring_padding, tvb, offset, 1, ENC_BIG_ENDIAN);
if (pad > 7) {
- expert_add_info_format(actx->pinfo, pad_item, PI_UNDECODED, PI_WARN,
- "Illegal padding (0 .. 7): %d", pad);
+ expert_add_info_format(
+ actx->pinfo, pad_item, PI_UNDECODED, PI_WARN,
+ "Illegal padding (0 .. 7): %d", pad);
}
}
offset++;
len--;
- if(hf_id >= 0) {
+ if (hf_id >= 0) {
item = proto_tree_add_item(parent_tree, hf_id, tvb, offset, len, ENC_BIG_ENDIAN);
actx->created_item = item;
- if(ett_id != -1) {
+ if (ett_id != -1) {
tree = proto_item_add_subtree(item, ett_id);
}
}
- if(out_tvb) {
- if(len<=(guint32)tvb_length_remaining(tvb, offset)){
+ if (out_tvb) {
+ if (len <= (guint32)tvb_length_remaining(tvb, offset)) {
*out_tvb = tvb_new_subset(tvb, offset, len, len);
} else {
*out_tvb = tvb_new_subset_remaining(tvb, offset);
@@ -4452,14 +4845,14 @@ int dissect_ber_constrained_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, p
}
}
- if(named_bits) {
- sep = " (";
+ if (named_bits) {
+ sep = " (";
term = FALSE;
nb = named_bits;
bitstring = tvb_get_ephemeral_string(tvb, offset, len);
while (nb->p_id) {
- if(len > 0 && nb->bit < (8*len-pad)) {
+ if ((len > 0) && (nb->bit < (8*len-pad))) {
val = tvb_get_guint8(tvb, offset + nb->bit/8);
bitstring[(nb->bit/8)] &= ~(0x80 >> (nb->bit%8));
val &= 0x80 >> (nb->bit%8);
@@ -4472,38 +4865,40 @@ int dissect_ber_constrained_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, p
val = 0;
proto_tree_add_boolean(tree, *(nb->p_id), tvb, offset + len, 0, 0x00);
}
- if(val) {
- if(item && nb->tstr) {
+ if (val) {
+ if (item && nb->tstr) {
proto_item_append_text(item, "%s%s", sep, nb->tstr);
- sep = ", ";
+ sep = ", ";
term = TRUE;
}
} else {
- if(item && nb->fstr) {
+ if (item && nb->fstr) {
proto_item_append_text(item, "%s%s", sep, nb->fstr);
- sep = ", ";
+ sep = ", ";
term = TRUE;
}
}
nb++;
}
- if(term)
+ if (term)
proto_item_append_text(item, ")");
for (byteno = 0; byteno < len; byteno++) {
if (bitstring[byteno]) {
- expert_add_info_format(actx->pinfo, item, PI_UNDECODED, PI_WARN,
- "Unknown bit(s): 0x%s", bytes_to_str(bitstring, len));
+ expert_add_info_format(
+ actx->pinfo, item, PI_UNDECODED, PI_WARN,
+ "Unknown bit(s): 0x%s", bytes_to_str(bitstring, len));
break;
}
}
}
- if (pad > 0 && pad < 8 && len > 0) {
+ if ((pad > 0) && (pad < 8) && (len > 0)) {
guint8 bits_in_pad = tvb_get_guint8(tvb, offset + len - 1) & (0xFF >> (8-pad));
if (bits_in_pad) {
- expert_add_info_format(actx->pinfo, item, PI_UNDECODED, PI_WARN,
- "Bits set in padded area: 0x%02x", bits_in_pad);
+ expert_add_info_format(
+ actx->pinfo, item, PI_UNDECODED, PI_WARN,
+ "Bits set in padded area: 0x%02x", bits_in_pad);
}
}
@@ -4512,46 +4907,48 @@ int dissect_ber_constrained_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, p
return end_offset;
}
-int dissect_ber_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const asn_namedbit *named_bits, gint hf_id, gint ett_id, tvbuff_t **out_tvb)
+int
+dissect_ber_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const asn_namedbit *named_bits, gint hf_id, gint ett_id, tvbuff_t **out_tvb)
{
return dissect_ber_constrained_bitstring(implicit_tag, actx, parent_tree, tvb, offset, -1, -1, named_bits, hf_id, ett_id, out_tvb);
}
-int dissect_ber_bitstring32(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, int **bit_fields, gint hf_id, gint ett_id, tvbuff_t **out_tvb)
+int
+dissect_ber_bitstring32(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, int **bit_fields, gint hf_id, gint ett_id, tvbuff_t **out_tvb)
{
- tvbuff_t *tmp_tvb = NULL;
- proto_tree *tree;
- guint32 val;
- int **bf;
- header_field_info *hfi;
- const char *sep;
- gboolean term;
- unsigned int i, tvb_len;
+ tvbuff_t *tmp_tvb = NULL;
+ proto_tree *tree;
+ guint32 val;
+ int **bf;
+ header_field_info *hfi;
+ const char *sep;
+ gboolean term;
+ unsigned int i, tvb_len;
offset = dissect_ber_bitstring(implicit_tag, actx, parent_tree, tvb, offset, NULL, hf_id, ett_id, &tmp_tvb);
tree = proto_item_get_subtree(actx->created_item);
- if(bit_fields && tree && tmp_tvb) {
+ if (bit_fields && tree && tmp_tvb) {
/* tmp_tvb points to the actual bitstring (including any pad bits at the end.
* note that this bitstring is not neccessarily always encoded as 4 bytes
* so we have to read it byte by byte.
*/
- val=0;
- tvb_len=tvb_length(tmp_tvb);
- for(i=0;i<4;i++){
- val<<=8;
- if(i<tvb_len){
- val|=tvb_get_guint8(tmp_tvb,i);
+ val = 0;
+ tvb_len = tvb_length(tmp_tvb);
+ for (i=0; i<4; i++) {
+ val <<= 8;
+ if (i < tvb_len) {
+ val |= tvb_get_guint8(tmp_tvb, i);
}
}
- bf = bit_fields;
- sep = " (";
+ bf = bit_fields;
+ sep = " (";
term = FALSE;
while (*bf) {
if (**bf >= 0) {
proto_tree_add_boolean(tree, **bf, tmp_tvb, 0, tvb_len, val);
hfi = proto_registrar_get_nth(**bf);
- if(val & hfi->bitmask) {
+ if (val & hfi->bitmask) {
proto_item_append_text(actx->created_item, "%s%s", sep, hfi->name);
sep = ", ";
term = TRUE;
@@ -4559,11 +4956,11 @@ int dissect_ber_bitstring32(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree
}
bf++;
}
- if(term)
+ if (term)
proto_item_append_text(actx->created_item, ")");
}
- if(out_tvb)
+ if (out_tvb)
*out_tvb = tmp_tvb;
return offset;
@@ -4662,8 +5059,8 @@ static const value_string ber_T_encoding_vals[] = {
static const ber_choice_t T_encoding_choice[] = {
{ 0, &hf_ber_single_ASN1_type, BER_CLASS_CON, 0, 0, dissect_ber_T_single_ASN1_type },
- { 1, &hf_ber_octet_aligned , BER_CLASS_CON, 1, BER_FLAGS_IMPLTAG, dissect_ber_T_octet_aligned },
- { 2, &hf_ber_arbitrary , BER_CLASS_CON, 2, BER_FLAGS_IMPLTAG, dissect_ber_T_arbitrary },
+ { 1, &hf_ber_octet_aligned , BER_CLASS_CON, 1, BER_FLAGS_IMPLTAG, dissect_ber_T_octet_aligned },
+ { 2, &hf_ber_arbitrary , BER_CLASS_CON, 2, BER_FLAGS_IMPLTAG, dissect_ber_T_arbitrary },
{ 0, NULL, 0, 0, 0, NULL }
};
@@ -4679,10 +5076,10 @@ dissect_ber_T_encoding(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, asn
static const ber_sequence_t external_U_sequence[] = {
- { &hf_ber_direct_reference, BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_ber_OBJECT_IDENTIFIER },
- { &hf_ber_indirect_reference, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_ber_INTEGER },
+ { &hf_ber_direct_reference, BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_ber_OBJECT_IDENTIFIER },
+ { &hf_ber_indirect_reference, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_ber_INTEGER },
{ &hf_ber_data_value_descriptor, BER_CLASS_UNI, BER_UNI_TAG_ObjectDescriptor, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_ber_ObjectDescriptor },
- { &hf_ber_encoding , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_ber_T_encoding },
+ { &hf_ber_encoding, BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_ber_T_encoding },
{ NULL, 0, 0, 0, NULL }
};
static int
@@ -4694,7 +5091,7 @@ dissect_ber_external_U(gboolean implicit_tag, tvbuff_t *tvb, int offset, asn1_ct
}
int
-dissect_ber_external_type(gboolean implicit_tag, proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, gint hf_id, ber_callback func){
+dissect_ber_external_type(gboolean implicit_tag, proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, gint hf_id, ber_callback func) {
actx->external.u.ber.ber_callback = func;
@@ -4707,7 +5104,7 @@ dissect_ber_external_type(gboolean implicit_tag, proto_tree *tree, tvbuff_t *tvb
}
/* Experimental */
int
-dissect_ber_EmbeddedPDV_Type(gboolean implicit_tag, proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, gint hf_id, ber_callback func _U_){
+dissect_ber_EmbeddedPDV_Type(gboolean implicit_tag, proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, gint hf_id, ber_callback func _U_) {
offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
@@ -4731,7 +5128,7 @@ dissect_ber(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
col_set_str(pinfo->cinfo, COL_DEF_SRC, "BER encoded file");
- if(!decode_as_syntax) {
+ if (!decode_as_syntax) {
/* if we got here we couldn't find anything better */
col_set_str(pinfo->cinfo, COL_INFO, "Unknown BER");
@@ -4748,7 +5145,8 @@ dissect_ber(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
}
-gboolean oid_has_dissector(const char *oid) {
+gboolean
+oid_has_dissector(const char *oid) {
return(dissector_get_string_handle(ber_oid_dissector_table, oid) != NULL);
}
@@ -4990,7 +5388,7 @@ proto_register_ber(void)
ber_oid_dissector_table = register_dissector_table("ber.oid", "BER OID Dissectors", FT_STRING, BASE_NONE);
ber_syntax_dissector_table = register_dissector_table("ber.syntax", "BER Syntax Dissectors", FT_STRING, BASE_NONE);
- syntax_table=g_hash_table_new(g_str_hash, g_str_equal); /* oid to syntax */
+ syntax_table = g_hash_table_new(g_str_hash, g_str_equal); /* oid to syntax */
register_ber_syntax_dissector("ASN.1", proto_ber, dissect_ber_syntax);
@@ -5003,15 +5401,15 @@ proto_reg_handoff_ber(void)
guint i = 1;
dissector_handle_t ber_handle;
- oid_add_from_string("asn1","2.1");
- oid_add_from_string("basic-encoding","2.1.1");
+ oid_add_from_string("asn1", "2.1");
+ oid_add_from_string("basic-encoding", "2.1.1");
ber_handle = create_dissector_handle(dissect_ber, proto_ber);
dissector_add_uint("wtap_encap", WTAP_ENCAP_BER, ber_handle);
ber_decode_as_foreach(ber_add_syntax_name, &i);
- if(i > 1)
+ if (i > 1)
qsort(&syntax_names[1], i - 1, sizeof(value_string), cmp_value_string);
syntax_names[i].value = 0;
syntax_names[i].strptr = NULL;