views:

134

answers:

3

Hi, I'm writing a client-server app, in which the client has a determined memory address from the server side.

If something goes wrong and the server needs to be reestarted the address the client has is not valid anymore. When using a function using that invalid info a SIGSEGV will be sent to the server as the address may not be its anymore.

How can the server protect itself from a SIGSEGV and continue accepting connections and operating normally? Is there any way not to crash the server when this happens?

Thank you very much.

+11  A: 

The client should not send a memory address to the server, period. If the client needs a reference to server resources, the server should provide it with some sort of handle that the server can translate to an address, but which isn't directly dereferenced.

In your case, the server restart has probably rendered the client's handle invalid. The server should notice this and return a well-understood error code to the client telling it to get a new resource handle.

JSBangs
Spot on. Passing pointers server to client and vice versa is quite insane :)
MarkR
Exactly. In this case, the server acts like a kernel as far as VMM goes. It must maintain a list of what handles point to what real addresses.
Tim Post
A: 

Manage a table of connection, where the pointer is stored. If ever the server restarts, it rebuild a fresh table. The client only knows the index (or key or whatever) of its connection.

The context is not specified, but sending a pointer to the client can be a big security hole as the client can crash the server very easily.

philippe
A: 

Instead of using a pointer, use an index of an array or map. This may result in indexes being reused, but it's easy enough to detect and ignore grossly invalid indexes.

Ignacio Vazquez-Abrams