Ethereal-dev: Re: RE: [Ethereal-dev] problem in new dissector added

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: ronnie sahlberg <ronniesahlberg@xxxxxxxxx>
Date: Thu, 7 Apr 2005 15:42:59 +1000
you are dereferencing an uninitialized pointer:
e_myip *myh;
...
myh->myip_num = tvb_get_ntohl(tvb, 0);


you should run ethereal inside gdb to verify what other bugs there are.


On 6 Apr 2005 03:29:05 -0000, bunty <bunty123_4@xxxxxxxxxxxxxx> wrote:
> 
> 
> Hello,
>         Thanks for reply. Sorry for not stating problem in detail. Following
> are 4 changes i made to ethereal-0.10.10 sourcecode. Sorry i dont know how
> to create patch.
> My packet structure is ETHER + MYIP + IP + TCP/UDP/ICMP headers
>         Please kindly check my implementation for why its producing
> segmentation fault.
> 
> 1) add new type ETHERTYPE_MYIP to etypes.h
> 2)Changes to packet-ethertype.c => Added new ether protocol ID and written
> case to handle no. of that packets.
> *****************************************************
>   {ETHERTYPE_MYIP,          "MYIP"               },
> 
>   case ETHERTYPE_MYIP:
>       ld->myip++;
>       capture_myip(pd, offset, len, ld);
>       break;
> 
> 
> 3)New header packet-myip.h 
> *******************************************************************
> #ifndef __PACKET_MYIP_H__
> #define __PACKET_MYIP_H__
> 
> typedef struct _e_mymyip
>     {
>     guchar  *myip_text;
>     guint32  myip_num;
> 
> } e_myip;
> 
> void capture_myip(const guchar *, int, int, packet_counts *);
> 
> /* Export the DSCP value-string table for other protocols */
> extern const value_string dscp_vals[];
> 
> #endif
> 
> 
> 4)New header packet-myip.c 
> *****************************************************************
> #ifdef HAVE_CONFIG_H
> # include "config.h"
> #endif
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <glib.h>
> #include <epan/packet.h>
> #include <epan/prefs.h>
> #include <epan/ipproto.h>
> #include "etypes.h"
> #include "packet-myip.h"
> #include "packet-ip.h"
> 
> void proto_reg_handoff_myip(void);
> static int proto_myip = -1;
> static gint ett_myip = -1;
> static int hf_myip_num = -1;
> static unsigned char* hf_myip_text = -1;
> static void dissect_myip(tvbuff_t *, packet_info *, proto_tree *);
> static dissector_table_t myip_dissector_table;
> static dissector_handle_t data_handle;
> 
> 
> void capture_myip(const guchar *pd, int offset, int len, packet_counts *ld)
> {
> capture_ip(pd,offset+8,len,ld);
> }
> 
> 
> static void dissect_myip(tvbuff_t *tvb, packet_info *pinfo, proto_tree
> *tree)
> {
> proto_tree      *myh_tree;
> proto_item      *volatile myti = NULL;
> e_myip *myh;
> guint8    nxt;
> guint16 num;
> guchar *str;
> tvbuff_t  *next_tvb;
> int        offset = 0;
> 
>      if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
>           col_set_str(pinfo->cinfo, COL_PROTOCOL, "MYIP");
> if (check_col(pinfo->cinfo, COL_INFO))
>           col_clear(pinfo->cinfo, COL_INFO);
> 
> myh->myip_num = tvb_get_ntohl(tvb, 0);
> num=myh->myip_num;
> 
> if(tree)
> {
> myti = proto_tree_add_item(tree, proto_myip, tvb, 0, num, FALSE);
> myh_tree = proto_item_add_subtree(myti, ett_myip);
> 
> proto_tree_add_uint_format(myh_tree, hf_myip_num, tvb,
> offset, 1,num,
>         "Sequence no: %u", num);
> }
> 
> myh->myip_text = tvb_get_string(tvb, 4,4);
> str=myh->myip_text;
> 
> if(tree)
> {
> myti = proto_tree_add_string(myh_tree, hf_myip_text, tvb,0, 0, "");
> 
> }
>   next_tvb = tvb_new_subset(tvb, 8, -1, -1);
> 
>   if (!dissector_try_port(myip_dissector_table, 8 ,
> next_tvb, pinfo, tree)) {
>   call_dissector(data_handle,next_tvb, pinfo, tree);
>   }
> 
> }
> 
> 
> 
> 
> void proto_register_myip(void)
> {
>   module_t *myip_module;
> 
>      static hf_register_info hf[] = {
>           { &hf_myip_text,
>           { "myip_text",          "myip.text", FT_STRING, BASE_HEX, NULL,
> 0x0,"", HFILL }},
>           { &hf_myip_num,
>           { "myip_num",          "myip.num", FT_UINT32, BASE_DEC, NULL,
> 0x0,"", HFILL }}
> };
>      static gint *ett[] = {
>           &ett_myip,
>      };
> 
>      proto_myip = proto_register_protocol("My Internet Protocol","MYIP",
> "myip");
>      proto_register_field_array(proto_myip, hf,
> array_length(hf));
>      proto_register_subtree_array(ett, array_length(ett));
>            myip_dissector_table = register_dissector_table("myip.proto",
>          "MYIP protocol", FT_UINT8, BASE_DEC);    
> 
>         myip_module = prefs_register_protocol(proto_myip,
> proto_reg_handoff_myip);
> 
> register_dissector("myip", dissect_myip, proto_myip);
> }
> void proto_reg_handoff_myip(void)
> {
>      dissector_handle_t myip_handle;
>      data_handle = find_dissector("data");
>         myip_handle = find_dissector("myip");
>      dissector_add("ethertype", ETHERTYPE_MYIP, myip_handle);
> }
> 
> 
> regards,
> bunty.
> On Tue, 05 Apr 2005 Francisco Alcoba(TS/EEM) wrote :
> 
> >Hi,
> >
> >Unless you have checked the option "update packet list in real time" the
> packets are dissected
> >only when the capture stops, so any problem the dissector has will show up
> then. The best way
> >to find out what is happening is, in my experience, to start ethereal in
> debug mode. You might
> >be using uninitialized pointers, incorrectly called functions, whatever;
> the fact that is shows in
> >the protocol list does not mean the dissector is 100% bug free.
> >
> >I can only speak for myself, but I find it very difficult to understand
> code without knowing what it
> >is trying to do -in this case, without knowing what packet it is trying to
> dissect-. And, of course,
> >the more defined a problem is the easiest to offer suggestions -i.e. it is
> easier to suggest an
> >answer to "why in this line of code I use this function with this arguments
> and the result is not
> >what I expected" than to "why is my code not working?"-.
> >
> >Regards,
> >
> >  Francisco
> >
> >-----Original Message-----
> > From: ethereal-dev-bounces@xxxxxxxxxxxx
> [mailto:ethereal-dev-bounces@xxxxxxxxxxxx]
> >Sent: martes, 05 de abril de 2005 18:22
> >To: ethereal-dev@xxxxxxxxxxxx
> >Subject: [Ethereal-dev] problem in new dissector added
> >
> >
> >
> >
> >Hello,
> >      I added new dissector. I already mailed that on forum but unable to
> get reply for that from anyone. I tried then to implement on my own and get
> successfully added to list of protocols(dont know whether its correct 
> implemented or not?).
> >      Curretly i am facing problem that when i try to capture packets,
> capture windows shows packet captured but when i stop it then accidently
> ethereal stops working giving segmentation fault. What is the reason i am
> getting segmentation fault?
> >        Hope this time i will get response from list.
> >Thanks in advance.
> >regards,
> >bunty.
> >
> >
> >
> >  <http://clients.rediff.com/signature/track_sig.asp>
> >
> >_______________________________________________
> >Ethereal-dev mailing list
> >Ethereal-dev@xxxxxxxxxxxx
> >http://www.ethereal.com/mailman/listinfo/ethereal-dev
> 
> 
> 
> 
>  
> _______________________________________________
> Ethereal-dev mailing list
> Ethereal-dev@xxxxxxxxxxxx
> http://www.ethereal.com/mailman/listinfo/ethereal-dev
> 
> 
>