Re: segmentation fault

From: Sean Burke (foobar_at_mystery.org)
Date: 03/22/04


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,&current_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



Relevant Pages

  • Re: segmentation fault
    ... please visit this link again to download the input file ... > I am getting segmentation fault on solaris. ... > 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 ...
    (comp.unix.programmer)
  • Re: Using tcl and Expect in AIX
    ... :uncompress: 0653-059 The input file contains bad data; ... What tool do you use to download? ... My first thought is that if you used ftp, and didn't tell ftp to use ...
    (comp.lang.tcl)
  • Re: tlbimp.exe
    ... Have same exact problem with tlbimb and SmartDocumentWrapper.dll (Vertigo ... Smart Docs). ... How would I find the input file for this? ... > Ideally you should download the Office primary interop assemblies ...
    (microsoft.public.dotnet.security)
  • sysinstall question
    ... While installing ports using sysinstall, will it download ... Tejas Kokje ... University of Southern California ...
    (comp.unix.bsd.freebsd.misc)