Odd .....

Roger Oberholtzer roger
Sun Jun 18 23:37:31 PDT 2006


On Fri, 2006-06-16 at 10:03 -0500, Ben Duncan wrote:
> In one of my test C programs, malloc'd a 2048 byte memory page.
> I decided to see if I could segfault it (testing a thery)
> and it did NOT segfault ... what Am I doing wrong, or is this
> just how things works ... And is there a way to test for
> any of these buffer overruns ?

I use two tools that check different things:

efence. It does hardware memory allocation so that any bad access causes
a fault it can capture. Very powerful. It can even be used with already
compiled programs. Some distros include this.

smartalloc. This checks for memory leaks. It requires that the program
be compiled with it. Does a nice on-demand summary of outstanding memory
allocations.

> 
> ie:
> 
> char *buffer_ptr ;
> char TEST_STRING [ ] = "TEST STRING" ;
> 
> buffer_ptr = malloc (2048) ;
> ... do some stuff putting things in the buffer ...
> buffer_ptr = buffer_ptr + 2096 ;
> memcpy ( buffer_ptr, TEST_STRING, sizeof (TEST_STRING ) ) ;
> 
> And I got no segfault doing this ...

A seg fault is not guaranteed. It depends on what the memory is that is
after the allocated memory. If it belongs to your process, then you will
not get a fault.

> 
> 
-- 
Roger Oberholtzer

OPQ Systems AB
Ramb?ll Sverige AB
Kapellgr?nd 7
P.O. Box 4205
SE-102 65 Stockholm, Sweden

Tel: Int +46 8-615 60 20
Fax: Int +46 8-31 42 23




More information about the Linux-users mailing list