GOOSE Messages don't use the length field to perform the dissection.
authoretxrab <etxrab@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 5 Feb 2012 18:25:01 +0000 (18:25 +0000)
committeretxrab <etxrab@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 5 Feb 2012 18:25:01 +0000 (18:25 +0000)
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6734

 #BACKPORT:YES

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

asn1/goose/packet-goose-template.c
epan/dissectors/packet-goose.c

index 80cd0a478b792cfbc41ab15fb65c5836000ca321..609866ff103fa98031290cd5f99f269c87c04bab 100644 (file)
@@ -65,47 +65,41 @@ dissect_goose(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
 {
        int offset = 0;
        int old_offset;
-       guint16 data;
+       guint16 length;
        proto_item *item = NULL;
        proto_tree *tree = NULL;
        asn1_ctx_t asn1_ctx;
        asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
 
+       col_set_str(pinfo->cinfo, COL_PROTOCOL, PNAME);
+       col_clear(pinfo->cinfo, COL_INFO);
+
        if (parent_tree){
                item = proto_tree_add_item(parent_tree, proto_goose, tvb, 0, -1, ENC_NA);
                tree = proto_item_add_subtree(item, ett_goose);
-       }
-       col_set_str(pinfo->cinfo, COL_PROTOCOL, PNAME);
-       col_clear(pinfo->cinfo, COL_INFO);
 
-       /* APPID */
-       if (tree && tvb_reported_length_remaining(tvb, offset) >= 2) {
-               data = tvb_get_ntohs(tvb, offset);
-               proto_tree_add_uint(tree, hf_goose_appid, tvb, offset, 2, data);
-       }
-       /* Length */
-       if (tree && tvb_reported_length_remaining(tvb, offset) >= 4) {
-               data = tvb_get_ntohs(tvb, offset + 2);
-               proto_tree_add_uint(tree, hf_goose_length, tvb, offset + 2, 2, data);
-       }
-       /* Reserved 1 */
-       if (tree && tvb_reported_length_remaining(tvb, offset) >= 6) {
-               data = tvb_get_ntohs(tvb, offset + 4);
-               proto_tree_add_uint(tree, hf_goose_reserve1, tvb, offset + 4, 2, data);
-       }
-       /* Reserved 2 */
-       if (tree && tvb_reported_length_remaining(tvb, offset) >= 8) {
-               data = tvb_get_ntohs(tvb, offset + 6);
-               proto_tree_add_uint(tree, hf_goose_reserve2, tvb, offset + 6, 2, data);
-       }
 
-       offset = 8;
-       while (tree && tvb_reported_length_remaining(tvb, offset) > 0){
-               old_offset = offset;
-               offset = dissect_goose_GOOSEpdu(FALSE, tvb, offset, &asn1_ctx , tree, -1);
-               if (offset == old_offset) {
-                       proto_tree_add_text(tree, tvb, offset, -1, "Internal error, zero-byte GOOSE PDU");
-                       break;
+               /* APPID */
+               proto_tree_add_item(tree, hf_goose_appid, tvb, offset, 2, ENC_BIG_ENDIAN);
+
+               /* Length */
+               length = tvb_get_ntohs(tvb, offset + 2);
+               proto_tree_add_item(tree, hf_goose_length, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
+
+               /* Reserved 1 */
+               proto_tree_add_item(tree, hf_goose_reserve1, tvb, offset + 4, 2, ENC_BIG_ENDIAN);
+
+               /* Reserved 2 */
+               proto_tree_add_item(tree, hf_goose_reserve2, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
+
+               offset = 8;
+               while (offset < length){
+                       old_offset = offset;
+                       offset = dissect_goose_GOOSEpdu(FALSE, tvb, offset, &asn1_ctx , tree, -1);
+                       if (offset == old_offset) {
+                               proto_tree_add_text(tree, tvb, offset, -1, "Internal error, zero-byte GOOSE PDU");
+                               return;
+                       }
                }
        }
 }
index 12afd42c91f6f043577c033c67720f37fa6f8897..2dac5ed00e5e2ef71bd22f85b2ec117106a9adb8 100644 (file)
@@ -725,47 +725,41 @@ dissect_goose(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
 {
        int offset = 0;
        int old_offset;
-       guint16 data;
+       guint16 length;
        proto_item *item = NULL;
        proto_tree *tree = NULL;
        asn1_ctx_t asn1_ctx;
        asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
 
+       col_set_str(pinfo->cinfo, COL_PROTOCOL, PNAME);
+       col_clear(pinfo->cinfo, COL_INFO);
+
        if (parent_tree){
                item = proto_tree_add_item(parent_tree, proto_goose, tvb, 0, -1, ENC_NA);
                tree = proto_item_add_subtree(item, ett_goose);
-       }
-       col_set_str(pinfo->cinfo, COL_PROTOCOL, PNAME);
-       col_clear(pinfo->cinfo, COL_INFO);
 
-       /* APPID */
-       if (tree && tvb_reported_length_remaining(tvb, offset) >= 2) {
-               data = tvb_get_ntohs(tvb, offset);
-               proto_tree_add_uint(tree, hf_goose_appid, tvb, offset, 2, data);
-       }
-       /* Length */
-       if (tree && tvb_reported_length_remaining(tvb, offset) >= 4) {
-               data = tvb_get_ntohs(tvb, offset + 2);
-               proto_tree_add_uint(tree, hf_goose_length, tvb, offset + 2, 2, data);
-       }
-       /* Reserved 1 */
-       if (tree && tvb_reported_length_remaining(tvb, offset) >= 6) {
-               data = tvb_get_ntohs(tvb, offset + 4);
-               proto_tree_add_uint(tree, hf_goose_reserve1, tvb, offset + 4, 2, data);
-       }
-       /* Reserved 2 */
-       if (tree && tvb_reported_length_remaining(tvb, offset) >= 8) {
-               data = tvb_get_ntohs(tvb, offset + 6);
-               proto_tree_add_uint(tree, hf_goose_reserve2, tvb, offset + 6, 2, data);
-       }
 
-       offset = 8;
-       while (tree && tvb_reported_length_remaining(tvb, offset) > 0){
-               old_offset = offset;
-               offset = dissect_goose_GOOSEpdu(FALSE, tvb, offset, &asn1_ctx , tree, -1);
-               if (offset == old_offset) {
-                       proto_tree_add_text(tree, tvb, offset, -1, "Internal error, zero-byte GOOSE PDU");
-                       break;
+               /* APPID */
+               proto_tree_add_item(tree, hf_goose_appid, tvb, offset, 2, ENC_BIG_ENDIAN);
+
+               /* Length */
+               length = tvb_get_ntohs(tvb, offset + 2);
+               proto_tree_add_item(tree, hf_goose_length, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
+
+               /* Reserved 1 */
+               proto_tree_add_item(tree, hf_goose_reserve1, tvb, offset + 4, 2, ENC_BIG_ENDIAN);
+
+               /* Reserved 2 */
+               proto_tree_add_item(tree, hf_goose_reserve2, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
+
+               offset = 8;
+               while (offset < length){
+                       old_offset = offset;
+                       offset = dissect_goose_GOOSEpdu(FALSE, tvb, offset, &asn1_ctx , tree, -1);
+                       if (offset == old_offset) {
+                               proto_tree_add_text(tree, tvb, offset, -1, "Internal error, zero-byte GOOSE PDU");
+                               return;
+                       }
                }
        }
 }
@@ -1030,7 +1024,7 @@ void proto_register_goose(void) {
         "UtcTime", HFILL }},
 
 /*--- End of included file: packet-goose-hfarr.c ---*/
-#line 133 "../../asn1/goose/packet-goose-template.c"
+#line 127 "../../asn1/goose/packet-goose-template.c"
   };
 
   /* List of subtrees */
@@ -1058,7 +1052,7 @@ void proto_register_goose(void) {
     &ett_goose_Data,
 
 /*--- End of included file: packet-goose-ettarr.c ---*/
-#line 139 "../../asn1/goose/packet-goose-template.c"
+#line 133 "../../asn1/goose/packet-goose-template.c"
   };
 
        /* Register protocol */