2016-07-28 6 views
2

Ich habe eine einfache Wireshark Dissektor, die folgenden Fehler Warnung auslöst, wenn es gegen eine Erfassung ausgeführt wird:Wireshark C Dissektor Fehler beim Unterbaum fülle

13:04:12   Warn Dissector bug, protocol usbserial, in packet 353: /wireshark/epan/proto.c:5504: 
failed assertion "idx >= 0 && idx < num_tree_types" 

Die Protokoll Registrierungsfunktion wie folgt aussieht:

static gint ett_myproto = -1; 

void 
proto_register_myproto(void) 
{ 
    /* Set up field array */ 
    static hf_register_info hf[] = { 
     { &hf_myproto_payload, 
      {"Payload", "myproto.payload", FT_BYTES, BASE_NONE, NULL, 
       0x0, NULL, HFILL }}, 
    }; 

    /* Register protocol */ 
    proto_myproto = proto_register_protocol("My Protocol", "myproto", "myproto"); 
    /* Register protocol fields */ 
    proto_register_field_array(proto_myproto, hf, array_length(hf)); 

    /* Register the dissector */ 
    register_dissector("myproto", dissect_myproto, proto_myproto); 
} 

Dissektor hat einige allgemeine munging von Daten, aber der Kern des Gebietes Problem zu sein scheint:

static int 
dissect_myproto(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, 
     void *data _U_) 
{ 
    proto_item *ti; 
    proto_tree *myproto_tree; 

    /* Create top tree and add to the item */ 
    ti = proto_tree_add_protocol_format(tree, proto_myproto, tvb, 0, -1, 
      "My Protocol"); 
    myproto_tree = proto_item_add_subtree(ti, ett_myproto); 

    proto_tree_add_bytes_format(myproto_tree, hf_myproto_payload, 
      tvb, 0, payload_len, 
      NULL, "Payload"); 
} 

Was muss ich tun, damit das Protokoll den Unterbaum korrekt füllt?

Antwort

2

Das Problem hier ist ein Fehler beim Registrieren der Teilbaum als Teil einer Teilbaum-Array (Hinweis von here).

Dies wird in der Protokoll-Registrierungsfunktion durchgeführt und erfordert „Verpackung“ die Unterstruktur Variablen (von denen es hier nur eine ist: ett_myproto) in ein Array, und dann das Array Registrierung proto_register_subtree_array mit:

static gint ett_myproto = -1; 

void 
proto_register_myproto(void) 
{ 
    /* Set up field array */ 
    static hf_register_info hf[] = { 
     .... 
    }; 

    /* Register protocol */ 
    proto_myproto = proto_register_protocol("My Protocol", "myproto", "myproto"); 
    /* Register protocol fields */ 
    proto_register_field_array(proto_myproto, hf, array_length(hf)); 

    /* Setup and register all protocol subtrees */ 
    static gint *ett[] = { 
     &ett_myproto, 
    }; 

    proto_register_subtree_array(ett, array_length(ett)); 

    /* Register the dissector */ 
    register_dissector("myproto", dissect_myproto, proto_myproto); 
} 

Die Variablen ett sind Indizes, die sich auf GUI-Informationen über den Status des Teilbaums beziehen (z. B. erweitert oder nicht).

+0

Im Allgemeinen können solche Probleme leicht beim Vergleich mit dem Beispiel-Dissektorcode unter [doc/packet-PROTOABBREV.c] (https://github.com/wireshark/wireshark/blob/master/doc/packet-PROTOABBREV.c) abgefangen werden) – Lekensteyn