public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Stack variables
@ 1998-01-17 22:30 Rauli Ruohonen
  1998-01-20 10:07 ` Jeffrey A Law
  0 siblings, 1 reply; 4+ messages in thread
From: Rauli Ruohonen @ 1998-01-17 22:30 UTC (permalink / raw)
  To: egcs

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..

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1998-01-22  2:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-17 22:30 Stack variables Rauli Ruohonen
1998-01-20 10:07 ` Jeffrey A Law
1998-01-22  1:45   ` amylaar
1998-01-22  2:29   ` Marc Lehmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).