Odd .....

Bill Campbell linux-sxs
Fri Jun 16 11:07:04 PDT 2006


On Fri, Jun 16, 2006, 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 ?

The subject of this should probably have been ``The Joy of C''.
Memory allocation errors in C have always been a major source of
errors and security problems.

I think that gcc can be build with bounds checking which might
help in this case, but I don't know if bounds checking would do
any good when dealing with malloc'ed memory.

There are alternatives to malloc that provide checking to help
check and identify memory allocation issues, but it's been quite
a while since (a) I did a lot of C programming, and (b) had to
track down this type of error.

>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 ...
>
>
>-- 
>Ben Duncan   - Business Network Solutions, Inc. 336 Elton Road  Jackson MS, 39212
>"Never attribute to malice, that which can be adequately explained by stupidity"
>        - Hanlon's Razor
>
>_______________________________________________
>Linux-users mailing list ( Linux-users at linux-sxs.org )
>Unsub/Password/Etc: http://mail.linux-sxs.org/cgi-bin/mailman/listinfo/linux-users
>
>Need to chat further on this subject? Check out #linux-users on irc.linux-sxs.org !
>

-- 
Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

Those who cast the vote decide nothing.
Those who count the vote decide everything. (Joseph Stalin)



More information about the Linux-users mailing list