Re: segmentation fault
From: Sean Burke (foobar_at_mystery.org)
Date: 03/22/04
- Next message: Jo: "Re: maximum timeout on socket connection"
- Previous message: Paul Pluzhnikov: "Re: segmentation fault"
- In reply to: Tejas Kokje: "Re: segmentation fault"
- Next in thread: Rich Teer: "Re: segmentation fault"
- Reply: Rich Teer: "Re: segmentation fault"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 22 Mar 2004 04:52:53 GMT
Tejas Kokje <kokje@usc.edu> writes:
> sorry for the mistake
> please visit this link again to download the input file
> http://www-scf.usc.edu/~kokje/code.tar
>
> Experts please help me out.
>
> Regards,
> Tejas
>
>
>
>
>
>
> On Sun, 21 Mar 2004 18:44:24 -0800, Tejas Kokje wrote:
>
> > Hi,
> >
> > I am getting segmentation fault on solaris. I have written
> > code on Linux and I am trying to port it to solaris.
> >
> > I am giving the link to download my code which is giving segmentation
> > fault. Surprising thing is that the code is working perfectly fine on
> > Linux.
> >
> > http://www-scf.usc.edu/~kokje/code.tar
> >
> > This tar contains the following files
> >
> > master.c - contains main function
> > server2.c - contains the code for tcp server
> > child2.c - contains the code for tcp client and is also a udp server
> > readconfig.c - reads the configuration file s1.in
> > myheader.h - contains header declaration
> >
> > compile the prog using
> >
> > gcc -lsocket -lnsl master.c -o master
> >
> > run using
> > ./master < s1.in
> >
> >
> > This code works fine on linux but generates SIGSEGV on solaris.
> > Any help on this would be appreciated.
The problem is in readconfig.c, at line 41 where you allocate space
for router_prefixes:
current_config->router_prefixes=(struct prefix*)malloc(sizeof(struct prefix)*(current_config->NUM_ROUTERS));
The problem is that you don't allocate enough space, because
NUM_ROUTERS is 5, but there are six entries to scan, including
the "zero" entry that marks the end of the list.
So at line 92:
sscanf(buf,"%s %u",current_config->router_prefixes[counter2].ip_address,¤t_config->router_prefixes[counter2].mask);
when buf holds "0.0.0.0 0" and counter2 == 5, the sscanf
overflows the current_config->router_prefixes[] array, and trashes
the heap.
Solution - allocate router_prefixes for [NUM_ROUTERS+1].
-SEan
- Next message: Jo: "Re: maximum timeout on socket connection"
- Previous message: Paul Pluzhnikov: "Re: segmentation fault"
- In reply to: Tejas Kokje: "Re: segmentation fault"
- Next in thread: Rich Teer: "Re: segmentation fault"
- Reply: Rich Teer: "Re: segmentation fault"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|