Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-12-2009, 01:14 AM   #1
LQ Newbie
Registered: Aug 2006
Posts: 1

Rep: Reputation: 0

need to handle SIGSEGV error when pbuf size is less than size. inside lib.:
for (i = 0; i < size; i++)
pbuf[i] = i;
Old 09-12-2009, 01:32 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
need to prevent SIGSEGV error so pbuf size always >= than size
Old 09-12-2009, 03:10 PM   #3
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Please let me elaborate:

If you've got a "buffer overrun" (for example, if you write to element "6" of a 5-element array), then one of three things can happen:

1) Nothing
<= The "bad element" happens to be legal, unused memory.
It's exactly as though you had allocated a 6-element array.
You got lucky!

2) You get a SIGSEGV
<= The "bad element" happens to be illegal memory, and the system tells you about it (by crashing with a SIGSEGV error).
I would consider this case "lucky", too - the SIGSEGV gives you a clue that you've got a problem, and some good clues how to fix it.

3) You corrupt memory, but you *don't* get a SIGSEGV
<= Unfortunately, this is the most common scenario.
You're trashing memory (somebody else's data, a return address - it doesn't matter). Something bad - something VERY bad - has just happened.
But you don't know about it. The program might appear to run OK.

3) is the worst of all scenarios. If the program crashes (and it probably will), it will probably be in a place far removed and completely unrelated to where your buffer overrun occurred. This kind of buffer overrun can be *very* difficult to track down and correct.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
signals krishna_123 Linux - Kernel 1 09-24-2008 12:02 AM
!!! about signals !!! b2na Programming 4 02-04-2005 12:34 AM
!! about signals !!! b2na General 1 01-03-2005 04:37 PM
Signals Speek Programming 2 12-24-2004 04:58 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:36 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration