![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| segmentation fault | rockgal | High Level Programming | 8 | 12-05-2006 12:16 PM |
| Segmentation Fault | compbug | UNIX for Dummies Questions & Answers | 3 | 04-21-2006 10:43 AM |
| segmentation fault | wojtyla | High Level Programming | 3 | 02-19-2005 02:53 PM |
| Segmentation fault | jshaulis | AIX | 1 | 06-01-2004 04:16 PM |
| segmentation fault | omran | High Level Programming | 2 | 08-01-2003 08:19 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Why not a segmentation fault??
Hi,
Why I don't receive a segmentation fault in the following sample. int main(void) { char buff[10]; sprintf(buff,"Hello world"); printf("%s\n",buff); } If I define a buffer of 10 elements and I'm trying to put inside it twelve elements, Should I receive a sigsev signal??? Thanks in advance! |
|
||||
|
Actually, not quite.
SegFault (in this case) goes when the EIP register point's to a invalid memory address to execute, and just 2 bytes aren't enough to reach the EIP, however try with 500 chars , you should get your SegFault. |
|
||||
|
Thanks!
Hi Zarnick,
So, you mean that when I overwrite the return instruction pointer on the procedure stack I should receive a SegFault, but if I don't reach it I don't? and why not 2 bytes aren't enough?? Sorry, I don't want to be annoying! Thanks!! |
|
||||
|
I wouldn't know for sure why 2 bytes are just not enough, I think it's something to do with the pointers used to allocate the enough memory for your char[10] string. But I can be wrong on this one.
And at least from what I can remember, I never saw a segfault that wasn't about the EIP register being overruned, as always, I can be wrong. |
|
||||
|
Shamrock -
He is trying to create a SIGSEGV. To test some other code. This corrupts the stack on HPUX PA_RISC boxes, and then dumps core: Code:
#include <stdlib.h>
#include <string.h>
int main()
{
char buff[10]={0x0};
char *p=buff;
p-=20;
memset(p,0x0, sizeof(buff));
return 0;
}
|
|
||||
|
Thanks!
Hi All,
Certainly I'm fixing an application with this type of code and I've replaced the sprintf by snprintf function, but I have to explain to my boss why I'm doing it and I need to show him the application crashing. The original message in the printf function overcomes the boundaries only for 2 bytes and it doesn't crash, I don't know how to do it and I don't know if its behavior is deterministic or not. Thanks to all of you for your support!!!!! |
![]() |
| Bookmarks |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|