Added option (-C) to check for SIZE constraints in octet-string, integer,
authorstig <stig@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 18 Dec 2009 15:18:31 +0000 (15:18 +0000)
committerstig <stig@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 18 Dec 2009 15:18:31 +0000 (15:18 +0000)
enumerated, sequence-of and set-of types.

Added BER functions to check for SIZE constraints and give expert info warnings.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@31309 f5534014-38df-0310-8fa8-9805f1628bb7

epan/dissectors/packet-ber.c
epan/dissectors/packet-ber.h
tools/asn2wrs.py

index 2b0a2e6b842009376ea3e9b970045c00a11fd914..88e9343b56c749b1a43728ce6339d3e2969fd7dd 100644 (file)
@@ -319,6 +319,46 @@ void ber_set_filename(gchar *filename)
   }
 }
 
+static void
+ber_check_length (guint32 length, gint32 min_len, gint32 max_len, asn1_ctx_t *actx, proto_item *item)
+{
+  if (min_len != -1 && length < (guint32)min_len) {
+    expert_add_info_format(actx->pinfo, item, PI_PROTOCOL, PI_WARN, "Size constraint: string too short: %d (%d .. %d)", 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: string too long: %d (%d .. %d)", 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);
+  }
+}
+
+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);
+  }
+}
+
+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);
+  }
+}
+
 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;
@@ -670,8 +710,6 @@ call_ber_syntax_callback(const char *syntax, tvbuff_t *tvb, int offset, packet_i
        return 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, const ber_sequence_t *seq, gint hf_id, gint ett_id);
-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);
 
 /* 8.1 General rules for encoding */
 
@@ -947,7 +985,7 @@ reassemble_octet_string(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int o
 
 /* 8.7 Encoding of an octetstring value */
 int
-dissect_ber_octet_string(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **out_tvb) {
+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 class;
        gboolean pc, ind;
        gint32 tag;
@@ -1030,6 +1068,7 @@ printf("OCTET STRING dissect_ber_octet_string(%s) entered\n",name);
                if(hf_id >= 0) {
                        it = proto_tree_add_item(tree, hf_id, tvb, offset, length_remaining, FALSE);
                        actx->created_item = it;
+                       ber_check_length(length_remaining, min_len, max_len, actx, it);
                } else {
                        proto_item *pi;
 
@@ -1049,6 +1088,11 @@ printf("OCTET STRING dissect_ber_octet_string(%s) entered\n",name);
        return end_offset;
 }
 
+int
+dissect_ber_octet_string(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **out_tvb) {
+  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)
 {
        tvbuff_t *out_tvb = NULL;
@@ -1215,11 +1259,26 @@ printf("INTEGERnew dissect_ber_integer(%s) entered implicit_tag:%d \n",name,impl
                        }
                }
        }
-       
+
+       if(value){
+               *value=val;
+       }
+
+       return offset;
+}
+
+int
+dissect_ber_constrained_integer64(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint64 min_len, gint64 max_len, gint hf_id, gint64 *value)
+{
+       gint64 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);
+
        return offset;
 }
 
@@ -1236,6 +1295,20 @@ dissect_ber_integer(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, t
        return offset;
 }
 
+int
+dissect_ber_constrained_integer(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, gint hf_id, guint32 *value)
+{
+       gint64 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);
+
+       return offset;
+}
 
 int
 dissect_ber_boolean(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, gboolean *value)
@@ -3024,7 +3097,8 @@ dissect_ber_GeneralString(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int
        return end_offset;
 }
 #endif
-int dissect_ber_restricted_string(gboolean implicit_tag, gint32 type,  asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **out_tvb) {
+
+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 class;
        gboolean pc;
        gint32 tag;
@@ -3072,7 +3146,12 @@ printf("RESTRICTED STRING dissect_ber_octet_string(%s) entered\n",name);
        }
 
        /* 8.21.3 */
-       return dissect_ber_octet_string(implicit_tag, actx, tree, tvb, hoffset, hf_id, out_tvb);
+       return dissect_ber_constrained_octet_string(implicit_tag, actx, tree, tvb, hoffset, min_len, max_len, hf_id, out_tvb);
+}
+
+int dissect_ber_restricted_string(gboolean implicit_tag, gint32 type, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **out_tvb) 
+{
+       return dissect_ber_constrained_restricted_string(implicit_tag, type, actx, tree, tvb, offset, NO_BOUND, NO_BOUND, hf_id, out_tvb);
 }
 
 int
@@ -3206,7 +3285,7 @@ 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, const ber_sequence_t *seq, gint hf_id, gint ett_id) {
+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;
@@ -3322,6 +3401,7 @@ printf("SQ OF dissect_ber_sq_of(%s) entered\n",name);
                                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);
                }
        }
 
@@ -3632,12 +3712,20 @@ printf("SQ OF dissect_ber_old_sq_of(%s) entered\n",name);
        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) {
+       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) {
-       return dissect_ber_sq_of(implicit_tag, BER_UNI_TAG_SEQUENCE, actx, parent_tree, tvb, offset, seq, hf_id, 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) {
+       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) {
-       return dissect_ber_sq_of(implicit_tag, BER_UNI_TAG_SET, actx, parent_tree, tvb, offset, seq, hf_id, 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) {
index 8b80e76525971ad784cb35b676708e0eecdcb780..ce6f299a1219da72cf4ef9d7e18fb2d00b0ed5d6 100644 (file)
@@ -38,6 +38,11 @@ if (check_col(pinfo->cinfo, COL_INFO)){ \
 } \
 tvb_get_guint8(tvb, 9999);
 
+/* value for value and size constraints */
+#ifndef NO_BOUND
+#define NO_BOUND -1
+#endif
+
 typedef int (*ber_callback)(gboolean imp_tag, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
 typedef int (*ber_type_fn)(gboolean, tvbuff_t*, int, asn1_ctx_t *actx, proto_tree*, int);
 /* To be removed when the transition to the "New" type is complete */
@@ -107,13 +112,16 @@ extern int dissect_ber_length(packet_info *pinfo, proto_tree *tree, tvbuff_t *tv
 
 extern 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);
 
+extern 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);
 extern int dissect_ber_octet_string(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **out_tvb);
 extern 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);
 extern 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);
 
 extern int dissect_ber_integer64(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, gint64 *value);
+extern int dissect_ber_constrained_integer64(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint64 min_len, gint64 max_len, gint hf_id, gint64 *value);
 
 extern int dissect_ber_integer(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, guint32 *value);
+extern int dissect_ber_constrained_integer(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, gint hf_id, guint32 *value);
 
 extern int dissect_ber_null(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id);
 
@@ -178,6 +186,7 @@ extern int dissect_ber_old_choice(asn1_ctx_t *actx, proto_tree *parent_tree, tvb
 /* 
  * This function dissects a BER strings
  */
+extern 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);
 extern int dissect_ber_restricted_string(gboolean implicit_tag, gint32 type, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **out_tvb);
 extern 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);
 
@@ -189,8 +198,10 @@ extern int dissect_ber_object_identifier_str(gboolean implicit_tag, asn1_ctx_t *
 
 /* this function dissects a BER sequence of
  */
+extern 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);
 extern 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);
 
+extern 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);
 extern 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);
 
 /* To be removed when the transition to the "New" type is complete */
index 8899ddcb9f7e042ff0d80f98a2636bf9c54d000d..314415ce693094bf342a77b7cf228589e84dd0a7 100755 (executable)
@@ -3865,9 +3865,14 @@ class SequenceOfType (SeqOfType):
 
   def eth_type_default_body(self, ectx, tname):
     if (ectx.Ber()):
-      body = ectx.eth_fn_call('dissect_%(ER)s_sequence_of', ret='offset',
-                              par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s'),
-                                   ('%(TABLE)s', '%(HF_INDEX)s', '%(ETT_INDEX)s',),))
+      if (ectx.constraints_check and self.HasSizeConstraint()):
+        body = ectx.eth_fn_call('dissect_%(ER)s_constrained_sequence_of', ret='offset',
+                                par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s'),
+                                     ('%(MIN_VAL)s', '%(MAX_VAL)s', '%(TABLE)s', '%(HF_INDEX)s', '%(ETT_INDEX)s',),))
+      else:
+        body = ectx.eth_fn_call('dissect_%(ER)s_sequence_of', ret='offset',
+                                par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s'),
+                                     ('%(TABLE)s', '%(HF_INDEX)s', '%(ETT_INDEX)s',),))
     elif (ectx.Per() and not self.HasConstraint()):
       body = ectx.eth_fn_call('dissect_%(ER)s_sequence_of', ret='offset',
                               par=(('%(TVB)s', '%(OFFSET)s', '%(ACTX)s', '%(TREE)s', '%(HF_INDEX)s'),
@@ -3917,9 +3922,14 @@ class SetOfType (SeqOfType):
 
   def eth_type_default_body(self, ectx, tname):
     if (ectx.Ber()):
-      body = ectx.eth_fn_call('dissect_%(ER)s_set_of', ret='offset',
-                              par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s'),
-                                   ('%(TABLE)s', '%(HF_INDEX)s', '%(ETT_INDEX)s',),))
+      if (ectx.constraints_check and self.HasSizeConstraint()):
+        body = ectx.eth_fn_call('dissect_%(ER)s_constrained_set_of', ret='offset',
+                                par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s'),
+                                     ('%(MIN_VAL)s', '%(MAX_VAL)s', '%(TABLE)s', '%(HF_INDEX)s', '%(ETT_INDEX)s',),))
+      else:
+        body = ectx.eth_fn_call('dissect_%(ER)s_set_of', ret='offset',
+                                par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s'),
+                                     ('%(TABLE)s', '%(HF_INDEX)s', '%(ETT_INDEX)s',),))
     elif (ectx.Per() and not self.HasConstraint()):
       body = ectx.eth_fn_call('dissect_%(ER)s_set_of', ret='offset',
                               par=(('%(TVB)s', '%(OFFSET)s', '%(ACTX)s', '%(TREE)s', '%(HF_INDEX)s'),
@@ -4434,9 +4444,14 @@ class EnumeratedType (Type):
 
   def eth_type_default_body(self, ectx, tname):
     if (ectx.Ber()):
-      body = ectx.eth_fn_call('dissect_%(ER)s_integer', ret='offset',
-                              par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s', '%(HF_INDEX)s'),
-                                   ('%(VAL_PTR)s',),))
+      if (ectx.constraints_check and self.HasValueConstraint()):
+        body = ectx.eth_fn_call('dissect_%(ER)s_constrained_integer', ret='offset',
+                                par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s'),
+                                     ('%(MIN_VAL)s', '%(MAX_VAL)s', '%(HF_INDEX)s', '%(VAL_PTR)s',),))
+      else:
+        body = ectx.eth_fn_call('dissect_%(ER)s_integer', ret='offset',
+                                par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s', '%(HF_INDEX)s'), 
+                                     ('%(VAL_PTR)s',),))
     elif (ectx.Per()):
       body = ectx.eth_fn_call('dissect_%(ER)s_enumerated', ret='offset',
                               par=(('%(TVB)s', '%(OFFSET)s', '%(ACTX)s', '%(TREE)s', '%(HF_INDEX)s'),
@@ -4733,9 +4748,14 @@ class OctetStringType (Type):
 
   def eth_type_default_body(self, ectx, tname):
     if (ectx.Ber()):
-      body = ectx.eth_fn_call('dissect_%(ER)s_octet_string', ret='offset',
-                              par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s', '%(HF_INDEX)s'),
-                                   ('%(VAL_PTR)s',),))
+      if (ectx.constraints_check and self.HasSizeConstraint()):
+        body = ectx.eth_fn_call('dissect_%(ER)s_constrained_octet_string', ret='offset',
+                                par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s'),
+                                     ('%(MIN_VAL)s', '%(MAX_VAL)s', '%(HF_INDEX)s', '%(VAL_PTR)s',),))
+      else:
+        body = ectx.eth_fn_call('dissect_%(ER)s_octet_string', ret='offset',
+                                par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s', '%(HF_INDEX)s'), 
+                                     ('%(VAL_PTR)s',),))
     elif (ectx.Per()):
       if self.HasContentsConstraint():
         body = ectx.eth_fn_call('dissect_%(ER)s_octet_string_containing%(FN_VARIANT)s', ret='offset',
@@ -4778,10 +4798,16 @@ class RestrictedCharacterStringType (CharacterStringType):
 
   def eth_type_default_body(self, ectx, tname):
     if (ectx.Ber()):
-      body = ectx.eth_fn_call('dissect_%(ER)s_restricted_string', ret='offset',
-                              par=(('%(IMPLICIT_TAG)s', '%(STRING_TAG)s'),
-                                   ('%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s', '%(HF_INDEX)s'),
-                                   ('%(VAL_PTR)s',),))
+      if (ectx.constraints_check and self.HasSizeConstraint()):
+        body = ectx.eth_fn_call('dissect_%(ER)s_constrained_restricted_string', ret='offset',
+                                par=(('%(IMPLICIT_TAG)s', '%(STRING_TAG)s'),
+                                     ('%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s'),
+                                     ('%(MIN_VAL)s', '%(MAX_VAL)s', '%(HF_INDEX)s', '%(VAL_PTR)s',),))
+      else:
+        body = ectx.eth_fn_call('dissect_%(ER)s_restricted_string', ret='offset',
+                                par=(('%(IMPLICIT_TAG)s', '%(STRING_TAG)s'),
+                                     ('%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s', '%(HF_INDEX)s'),
+                                     ('%(VAL_PTR)s',),))
     elif (ectx.Per() and self.HasPermAlph()):
       body = ectx.eth_fn_call('dissect_%(ER)s_restricted_character_string', ret='offset',
                               par=(('%(TVB)s', '%(OFFSET)s', '%(ACTX)s', '%(TREE)s', '%(HF_INDEX)s'),
@@ -5098,9 +5124,14 @@ class IntegerType (Type):
 
   def eth_type_default_body(self, ectx, tname):
     if (ectx.Ber()):
-      body = ectx.eth_fn_call('dissect_%(ER)s_integer%(FN_VARIANT)s', ret='offset',
-                              par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s', '%(HF_INDEX)s'),
-                                   ('%(VAL_PTR)s',),))
+      if (ectx.constraints_check and self.HasValueConstraint()):
+        body = ectx.eth_fn_call('dissect_%(ER)s_constrained_integer%(FN_VARIANT)s', ret='offset',
+                                par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s'),
+                                     ('%(MIN_VAL)s', '%(MAX_VAL)s', '%(HF_INDEX)s', '%(VAL_PTR)s',),))
+      else:
+        body = ectx.eth_fn_call('dissect_%(ER)s_integer%(FN_VARIANT)s', ret='offset',
+                                par=(('%(IMPLICIT_TAG)s', '%(ACTX)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s', '%(HF_INDEX)s'), 
+                                     ('%(VAL_PTR)s',),))
     elif (ectx.Per() and not self.HasValueConstraint()):
       body = ectx.eth_fn_call('dissect_%(ER)s_integer%(FN_VARIANT)s', ret='offset',
                               par=(('%(TVB)s', '%(OFFSET)s', '%(ACTX)s', '%(TREE)s', '%(HF_INDEX)s', '%(VAL_PTR)s'),))
@@ -7503,6 +7534,7 @@ asn2wrs [-h|?] [-d dbg] [-b] [-p proto] [-c cnf_file] [-e] input_file(s) ...
   -k            : Keep intermediate files though single file output is used
   -L            : Suppress #line directive from .cnf file
   -D dir        : Directory for input_file(s) (default: '.')
+  -C            : Add check for SIZE constraints
   
   input_file(s) : Input ASN.1 file(s)
 
@@ -7524,7 +7556,7 @@ def eth_main():
   global lexer
   print "ASN.1 to Wireshark dissector compiler";
   try:
-    opts, args = getopt.getopt(sys.argv[1:], "h?d:D:buXp:FTo:O:c:I:eESs:kL");
+    opts, args = getopt.getopt(sys.argv[1:], "h?d:D:buXp:FTo:O:c:I:eESs:kLC");
   except getopt.GetoptError:
     eth_usage(); sys.exit(2)
   if len(args) < 1:
@@ -7550,6 +7582,7 @@ def eth_main():
   ectx.conform.suppress_line = False;
   ectx.output.outnm = None
   ectx.output.single_file = None
+  ectx.constraints_check = False;
   for o, a in opts:
     if o in ("-h", "-?"):
       eth_usage(); sys.exit(2)
@@ -7562,6 +7595,8 @@ def eth_main():
       ectx.justexpcnf = True
     if o in ("-D",):
       ectx.srcdir = a
+    if o in ("-C",):
+      ectx.constraints_check = True
     if o in ("-X",):
         warnings.warn("Command line option -X is obsolete and can be removed")
     if o in ("-T",):
@@ -7571,7 +7606,7 @@ def eth_main():
     ectx.conform.read(conf_to_read)
 
   for o, a in opts:
-    if o in ("-h", "-?", "-c", "-I", "-E", "-D", "-X", "-T"):
+    if o in ("-h", "-?", "-c", "-I", "-E", "-D", "-C", "-X", "-T"):
       pass  # already processed
     else:
       par = []