Re: Stack overflow..
- From: praveenraj1987@xxxxxxxxx
- Date: Sun, 31 May 2009 16:15:39 -0700 (PDT)
On Jun 1, 12:29 am, Tauno Voipio <tauno.voi...@xxxxxxxxxxxxx> wrote:
On May 31, 1:14 am, Nate Eldredge <n...@xxxxxxxxxx> wrote:
does stack issue a segmentation fault signal in unix/linux??It does on all the machines I tried. Why not try it on yours and see?
std::cout<<"b = "<<b<<" "<<&b;
<<std::endl<<"a0 = "<<a<<" "<<&a
<<std::endl<<"a1 = "<<a<<" "<<&a
<<std::endl<<"a2 = "<<a<<" "<<&a
<<std::endl<<"a3 = "<<a<<" "<<&a
/*b=a beyond that stack starts writing on memory that is beyond its
return address and other things.. do not to write above that..
even if u overwrite it and get segmentation fault..
that is because u have overwritten the return address and jump to that
memory after functin ends, gives u SEG FAULT..
or your code is trying to access memory that is not on stack and is on
different PAGE.. as by giving a very high aray bound..
which makes it point to past the stack area....
so it is valid to write any where on STACK..*/
<<std::endl<<"a-1 = "<<a[-1]<<" "<<&a[-1]
<<std::endl<<"a-2 = "<<a[-2]<<" "<<&a[-2]
<<std::endl<<"a-3 = "<<a[-1000]<<" "<<&a[-1000];
compiled withs gcc...
stack is growing downwards so i have used -ve subscript..
You are messing with the stack area outside the
allocated array boundaries.
yes, but can writing to stack area may lead to segmentation fault.
getting down to assembly.. as the ESP is pointed to some segment.. if
we write on to the stack then can it generate me SEGMENTATION FAULT
as if we try to access to stack area by some pointer and write it..
if we modify the return address then it may get me a SEGMENTATION
FAULT as jumping to the modified return address may get me to some
page that is wrong or not accessible..
yes, i know thats undefined by C++ standrds.
The compiled behaviour is *undefined* in this case.
but i posted this to know what really goes behind the scene. its
undefined because it may not be portable.. to all the systems..
but if i ask it to be specifically.. on GNU compiler and UNIX
There are no guarantees whatsoever which data you
clobbered. Please understand that the compilers will
do some operations with functions in compiler support
library, and they may use the stack are written to.
i agree, return address may be pushed with base pointer...
but writing to these memory should not get me SEGMENTATION FAULT
SIGSEGV signal should only be signaled by the OS to the application if
it accesses a wrong memory..
and i think even if i overwrite the return address then OS should not
but it should if after making the jump to the memory specified by
modified return address is in wrong segment..
SIGSEGV should not be issued for just writing to return address..
if it were to be issued on modifying return address then stack
overflow problem should not be there
tauno voipio (at) iki fi
- Re: Stack overflow..
- From: Tauno Voipio
- Re: Stack overflow..
- Prev by Date: Re: Stack overflow..
- Next by Date: Re: Stack overflow..
- Previous by thread: Re: Stack overflow..
- Next by thread: Re: Stack overflow..