473,461 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

segfault handling

I am programming simple TCP server.
Some packets causes server to get segmentation fault.
Is it possible to handle segmentation fault and log that packet and
make server to continue running?
If possible can you provide me some example or tutorials please.

thanks,
parahat melayev
Nov 14 '05 #1
7 3744
Parahat Melayev wrote:
I am programming simple TCP server.
Some packets causes server to get segmentation fault.


Nope, packets do not cause the server to segfault. Bad packet
handling code does.
P.Krumins

Nov 14 '05 #2
On 2 Mar 2005 14:40:38 -0800, pa*****@gmail.com (Parahat Melayev)
wrote:
I am programming simple TCP server.
Some packets causes server to get segmentation fault.
Is it possible to handle segmentation fault and log that packet and
make server to continue running?
No, because your program is broken. Find out why some packets cause a
segfault.
If possible can you provide me some example or tutorials please.

thanks,
parahat melayev


--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 14 '05 #3
>I am programming simple TCP server.
Some packets causes server to get segmentation fault.
Is it possible to handle segmentation fault and log that packet and
make server to continue running?
Try fixing the original problem. Whatever caused the segfault
(buffer overflow?) may have mortally wounded the server so badly
it can't function properly again. You are also not guaranteed to
be able to restart after a segfault (and if you don't fix the bad
pointer or array subscript, you're likely to get another one almost
immediately anyway).
If possible can you provide me some example or tutorials please.


Learn how to use a debugger and read a stack trace. Also, try to
write a client that can consistently crash the server whenever you
want, so you can quickly reproduce the problem.

Another possibility is to keep restarting the server whenever it
dies. There's lots of ways to do this, from a shell while loop
to the 'daemontools' software, which lets you have better controls
over logging, taking the server down intentionally, etc.

Gordon L. Burditt
Nov 14 '05 #4
In article <5b**************************@posting.google.com >,
pa*****@gmail.com (Parahat Melayev) wrote:
I am programming simple TCP server.
Some packets causes server to get segmentation fault.
Is it possible to handle segmentation fault and log that packet and
make server to continue running?
If possible can you provide me some example or tutorials please.


If some packets cause a segmentation fault, then I bet someone could
create malicious packets that will take over your computer.

Find the reason for the segmentation fault and fix it.
Nov 14 '05 #5
Parahat Melayev wrote:
I am programming simple TCP server.
Some packets causes server to get segmentation fault.
Is it possible to handle segmentation fault and log that packet and
make server to continue running?
If possible can you provide me some example or tutorials please.


You could use setjmp() and longjmp() to detect SIGSEGV and
recover from it. See <setjmp.h> and <signal.h> .

Of course, it would be better to fix the code that causes
the segfault in the first place.

Nov 14 '05 #6
Old Wolf wrote:
Parahat Melayev wrote:
I am programming simple TCP server.
Some packets causes server to get segmentation fault.
Is it possible to handle segmentation fault and log that packet and
make server to continue running?
If possible can you provide me some example or tutorials please.
You could use setjmp() and longjmp() to detect SIGSEGV and
recover from it. See <setjmp.h> and <signal.h> .


If you're suggesting calling longjmp() from a signal
handler, you're asking for undefined behavior.

7.14.1.1 The signal function
/5/ [...] the behavior is undefined if the signal
handler refers to any object with static storage
duration [with one exception] or if the signal
handler calls any function in the standard library
[with three exceptions].

Since the handler can't safely refer to static-duration
objects, the jmp_buf cannot be a global variable, nor can
a pointer to the jmp_buf be a global, nor a pointer to a
pointer ... Hence, there's no defined way for the handler
to find the jmp_buf and pass it to longjmp().

... and even if it could find the jmp_buf, the handler
still couldn't safely call the longjmp() library function.
(Note that while setjmp() is a macro, longjmp() is described
as an actual function.)
Of course, it would be better to fix the code that causes
the segfault in the first place.


Yes, that's the path to take. As someone has already
observed, there is no reason to believe that the SIGSEGV is
the first thing the program has done wrong, it's just the
first error that was detected. All you know is that the
program went off the rails some time ago, and in light of
the knowledge that the program has run amok there's little
reason to trust anything its memory might now contain.

--
Eric Sosman
es*****@acm-dot-org.invalid

Nov 14 '05 #7
"Old Wolf" <ol*****@inspire.net.nz> wrote in message news:<11**********************@l41g2000cwc.googleg roups.com>...
Parahat Melayev wrote:
I am programming simple TCP server.
Some packets causes server to get segmentation fault.
Is it possible to handle segmentation fault and log that packet and
make server to continue running?
If possible can you provide me some example or tutorials please.


You could use setjmp() and longjmp() to detect SIGSEGV and
recover from it. See <setjmp.h> and <signal.h> .

Of course, it would be better to fix the code that causes
the segfault in the first place.


Thanks everybody,

of course in the first plase I want to find reason of segfault.

yes i found & read about signals from Stevens' UNP & APUE book.
now looking into <setjmp.h> ...
Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Nathaniel Echols | last post by:
I've written a function in C to perform protein sequence alignment. This works fine in a standalone C program. I've added the necessary packaging to use it in Python; it returns three strings and...
6
by: Stefan Behnel | last post by:
Hi! In Python 2.4b3, the deque is causing a segfault on two different machines I tested on. With deque, my program runs fine for a while (at least some tens of seconds up to minutes) and then...
0
by: dale | last post by:
Python newbie disclaimer on I am running an app with Tkinter screen in one thread and command-line input in another thread using raw_input(). First question - is this legal, should it run...
5
by: Vedran Vyroubal | last post by:
Hi all! I have a problem with STL string. My program segfaults after a period of time, it can run perfectly for days and than die after a week, and when it segfaults it doesn't have to be at the...
10
by: name | last post by:
When I started testing the algorithms for my wrap program, I threw together this snippet of code, which works quite well. Except that it (predictably) segfaults at the end when it tries to go...
162
by: Richard Heathfield | last post by:
I found something interesting on the Web today, purely by chance. It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm not sure which. ...
3
by: kj | last post by:
I am trying to diagnose a bug in my code, but I can't understand what's going on. I've narrowed things down to this: I have a function, say foo, whose signature looks something like: int foo(...
10
by: somebody | last post by:
There are two files below named search.c and search.h. In the for loop in search.c, the for loop never exits, even if mystruct.field1 has no match. Instead of exiting the for loop it keeps going...
14
by: Donn Ingle | last post by:
Yo, An app of mine relies on PIL. When PIL hits a certain problem font (for unknown reasons as of now) it tends to segfault and no amount of try/except will keep my wxPython app alive. My first...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.