LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

Rep: Reputation: 0
signals


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
paulsm4
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
paulsm4
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.
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:15 PM.

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