Re: SIGSEGV, where are you?
From: Juergen Brauckmann (brauckmann@trustcenter.de)Date: 02/12/02
- Previous message: Claes Nyberg: "SIGSEGV, where are you?"
- In reply to: Claes Nyberg: "SIGSEGV, where are you?"
- Next in thread: Casper ***: "Re: SIGSEGV, where are you?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Tue, 12 Feb 2002 18:09:13 +0100 From: Juergen Brauckmann <brauckmann@trustcenter.de> To: Claes Nyberg <md0claes@mdstud.chalmers.se>
Claes Nyberg wrote:
>
> $ cat test.c
> int main(int argc,char *argv[]) {
> char buf[256];
>
> strcpy(buf,argv[1]);
> exit(1);
> }
> $ gcc -o test test.c
> $ ./test `perl -e'print "a" x 1000'`; echo $?
> 1
> $
>
> What does the call to exit add to save
> the program from a SIGSEGV?
strcpy(buf,argv[1]) smashes the stack. The return address on the stack
gets overwritten, so that an explicit or implicit return out of the main
function goes into wonderland.
But if you use exit(1) to finish the programm, another function (exit())
is called which never returns, and the overwritten return address of the
main function is not used.
Juergen
- Previous message: Claes Nyberg: "SIGSEGV, where are you?"
- In reply to: Claes Nyberg: "SIGSEGV, where are you?"
- Next in thread: Casper ***: "Re: SIGSEGV, where are you?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]