How can you “avoid” SIGSEGV?

I am writing a client-server application in which the client has a specific memory address on the server side.

If something went wrong, and the server needs to re-establish the address that the client is already invalid. When using a function using this invalid information, SIGSEGV will be sent to the server, as the address may not be the same.

How can a server protect itself from SIGSEGV and continue to accept connections and function normally? Is there a way to not destroy the server when this happens?

Many thanks.

+4
source share
3 answers

The client should not send the memory address to the server, period. If the client needs a link to the server’s resources, the server must provide it with some kind of descriptor that the server can translate to an address, but which is not dereferenced.

In your case, rebooting the server probably made the client call invalid. The server should notice this and return a well-understood error code to the client telling it to get a new resource descriptor.

+12
source

Manage the join table in which the pointer is stored. If the server ever reboots, it will rebuild the new table. The client only knows the index (or key or something else) 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 easily collapse the server.

0
source

Instead of using a pointer, use an array or map index. This can lead to reuse of indexes, but it is easy enough to detect and ignore highly invalid indexes.

0
source

Source: https://habr.com/ru/post/1305042/


All Articles