This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Stack variables
- To: egcs at cygnus dot com
- Subject: Stack variables
- From: Rauli Ruohonen <raulir at fishy dot pp dot sci dot fi>
- Date: Sat, 17 Jan 1998 23:14:00 +0200 (EET)
- Reply-To: raulir at voimax dot voima dot jkl dot fi
I recently debugged a program (a version of paradise netrek server)
that had a small bug like this:
void foobaz(void)
{
char str[80];
str[0]=0;
while(something) { strcat(str,something_else); }
}
Since there were no checks, it eventually overwrote its stack. When I
debugged it with GDB, I just got a notification "SIGSEGV received", and
stack trace gave only one address: 0. Nothing else. Eventually I figured
it out, but I think that it shouldn't be this easy to screw your stack..
I usually use Electric Fence to debug programs, but in this case it was of
no use since it can't put an unmapped page before/after a stack variable.
After a while I thought of a simple solution: What about having a
debugging option in gcc that would allocate all stack variables with
malloc()? This would slow down the program, yes, but since it would be a
debugging option, it wouldn't matter.
I haven't even looked at gcc sources, so I probably wouldn't be able to
implement it, but it would be nice to see this in a future version of
egcs..