problem with cgiutils.c on solaris 10?

Bob Ingraham bobi at netshel.net
Fri May 19 20:49:11 CEST 2006


The pointer arithmetic looks OK, but three things come to mind after
looking at the mmap_fgets function:

1. Potential memory-alignment-access issue

When I used to write for Solaris on SPARC platforms, I had to be careful
about non-word-aligned memory accesses, since they would cause SIGBUS
violations.

However, Brian's box looks like it's Solaris on x86 (seeing the cl and esi
register names...), so I'm not so sure that it applies, since x86 allows
non-word-aligned memory access.


2. Potential bug if last "line" in the file isn't new-line terminated.

I suppose that this is unlikely, but if it occurred, then the for-loop
would increment the x variable one byte past the file_size.  Then the
length calculation would be off and the memcpy would try to access one
byte beyond the mapped file space.


3. The parenthesis grouping for type-casting isn't quite
right/paranoid-enough (for me, anyway)

For example, the following line:

    if(*(char *)(temp_mmapfile->mmap_buf+x)=='\n')

should really be:

    if(*((char *)(temp_mmapfile->mmap_buf)+x)=='\n')


And,

    len=(int)x-temp_mmapfile->current_position+1;

should be:

    len=(int)(x-temp_mmapfile->current_position)+1;


And,

    memcpy(buf,(char
*)(temp_mmapfile->mmap_buf+temp_mmapfile->current_position),len);

should be:

    memcpy(buf,((char
*)(temp_mmapfile->mmap_buf)+temp_mmapfile->current_position),len);


Also, Brian, if you have the time, it would be helpful to see a couple of
other things in your stack trace:

- A dump of the values of the temp_mmapfile member variables.

- A dump of the values of the local variables: buf, len and x

Just my $0.02.

Bob


> Brian Peterson wrote:
>> I'm having a problem getting the avail.cgi and trend.cgi scripts working
>> on Solaris 10.  They both seem to seg fault while processing the archive
>> logs in a memcpy function found in cgiutils.c.  Has anyone else seen
>> this or know how to get around this problem?  The problem seems to exist
>> in 2.0 as well as 2.3.
>>
>> Here's a quick dbx trace of the seg fault.
>>
>> #244  dbx avail.cgi
>> For information about new features see `help changes'
>> To remove this message, put `dbxenv suppress_startup_message 7.5' in
>> your .dbxrcReading avail.cgi
>> Reading ld.so.1
>> Reading librt.so.1
>> Reading libc.so.1
>> Reading libaio.so.1
>> Reading libmd5.so.1
>> (dbx) run
>> Running: avail.cgi
>> (process id 8256)
>> Cache-Control: no-store
>> Pragma: no-cache
>> Last-Modified: Tue, 09 May 2006 23:39:55 GMT
>> Expires: Thu, 01 Jan 1970 00:00:00 GMT
>> Content-type: text/html
>>
> [snip]
>> signal SEGV (no mapping at the fault address) in _memcpy at 0xfeed43f2
>> 0xfeed43f2: _memcpy+0x0032:     movb     0x00000002(%esi),%cl
>> Current function is mmap_fgets
>> 1206           memcpy(buf,(char
>> *)(temp_mmapfile->mmap_buf+temp_mmapfile->current_position),len);
>> (dbx) where
>>   [1] _memcpy(0x8047780, 0x80661dd, 0x8774cc8, 0xfebd5fbe), at
>> 0xfeed43f2
>> =>[2] mmap_fgets(temp_mmapfile = 0x8147380), line 1206 in "cgiutils.c"
>>   [3] scan_log_file_for_archived_state_data(filename = 0x8047090
>> "/opt/nagios/var/archives/nagios-05-08-2006-00.log"), line 2911 in
>> "avail.c"
>>   [4] read_archived_state_data(), line 2878 in "avail.c"
>>   [5] main(argc = 1, argv = 0x80477c4), line 994 in "avail.c"
>>
>>
>> Brian Peterson
>> brian at kaostech.com
>>
>
> Is anyone else experiencing this problem?  Perhaps the problem lies with
> the pointer arithmetic, although I'm not sure.
>
>
> Ethan Galstad,
> Nagios Developer
> ---
> Email: nagios at nagios.org
> Website: http://www.nagios.org
>
>
> -------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Nagios-devel mailing list
> Nagios-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagios-devel
>




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the Developers mailing list