Why are variables stored on the stack?
- From: CJ <cj@xxxxxxxxxx>
- Date: Fri, 14 Mar 2008 21:58:57 +0100 (CET)
Hello:
We know that C programs are often vulnerable to buffer overflows which
overwrite the stack.
But my question is: Why does C insist on storing local variables on the
stack in the first place?
I can see two definite disadvantages with this:
1) deeply nested recursive calls to a function (especially if it defines
large local arrays) can easily overflow the stack
2) the problems described above of security vulnerabilities.
My solution would be for C instead to store its local variables on the
heap - effectively separating data from executable code.
What do people think?
.
- Follow-Ups:
- Re: Why are variables stored on the stack?
- From: Kenneth Brody
- Re: Why are variables stored on the stack?
- From: Stephen Sprunk
- Re: Why are variables stored on the stack?
- From: CJ
- Re: Why are variables stored on the stack?
- From: Rod Pemberton
- Re: Why are variables stored on the stack?
- From: Jack Klein
- Re: Why are variables stored on the stack?
- From: cr88192
- Re: Why are variables stored on the stack?
- From: Richard Tobin
- Re: Why are variables stored on the stack?
- From: Gordon Burditt
- Re: Why are variables stored on the stack?
- From: Ian Collins
- Re: Why are variables stored on the stack?
- From: Richard Heathfield
- Re: Why are variables stored on the stack?
- From: Eric Sosman
- Re: Why are variables stored on the stack?
- From: jacob navia
- Re: Why are variables stored on the stack?
- From: santosh
- Re: Why are variables stored on the stack?
- From: Willem
- Re: Why are variables stored on the stack?
- From: Flash Gordon
- Re: Why are variables stored on the stack?
- From: Harald van Dijk
- Re: Why are variables stored on the stack?
- Prev by Date: Re: sprintf behavies different than printf
- Next by Date: Re: math q
- Previous by thread: sprintf behavies different than printf
- Next by thread: Re: Why are variables stored on the stack?
- Index(es):
Relevant Pages
|