473,804 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ 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 3763
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.c om (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.c om (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*****@inspir e.net.nz> wrote in message news:<11******* *************** @l41g2000cwc.go oglegroups.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
3165
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 an integer. However, as soon as the function is complete, I get a segfault and the interpreter dies. If I run Python interactively, just calling the function causes a segfault. If I'm running a script, I can actually print out the return...
6
1988
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 suddenly segfaults. I'm sorry I can't tell exactly when, but I'm running an application that uses a few hundred deques where elements are appendleft()ed and pop()ed (simple queue). As the application is rather complex (and I didn't read about this...
0
1824
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 without issue? If not can you point me to a description of why. While updating objects on the screen I get a segfault after an indeterminate number of updates. It doesn't seem to matter how quickly the updates occur, but it does segfault faster...
5
5815
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 same place. This is a backtrace: Program received signal SIGSEGV, Segmentation fault. 0x00485f66 in std::__default_alloc_template<true, 0>::allocate(unsigned) () (gdb) bt
10
1958
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 beyond the file. At some point, I tried to mend that behavior using feof() but without success. The functionality is not harmed, but this has started to bug me. What am I missing here? Sometimes being a code duffer is frustrating!! lol!!! The...
162
6746
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. http://www.developerdotstar.com/community/node/291 This "teacher of C" demonstrates his prowess with a masterful display of incompetence in a 200-line program that travels as swiftly as possible to Segfault City.
3
2310
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( int w, int x, int y, int z, my_struct **results ) During its execution, foo initializes *results using calloc: ( *results ) = calloc( w+1, sizeof( my_struct ) );
10
1879
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 until it segfaults. This seems to be related to the strcmp with the NULL value. There are 2 comments below that indicate the segfaults. I guess the question is, when there is no match, how to I detect that and return without a segfault?
14
4970
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 thought is to start the app from a bash script that will check the return value of my wxPython app and could then launch a new app to help the user grok what happened and fix it. Do you think that's a good idea, or is there another way to...
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10351
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7638
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6866
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.