Re: Using pointers across several network clients
- From: fjblurt@xxxxxxxxx
- Date: Wed, 5 Dec 2007 15:46:25 -0800 (PST)
On Dec 5, 12:19 pm, Andreas Wittmann <andreas.wittm...@xxxxxxx> wrote:
Hello NG!
The following situation:
I have a server (over network) application which allocates different
pointers to several data structures in it's own memory.
Some network clients should now be able to access those structures (At
least a handle to tell the server which structure to use for the internal
operations of the server).
My question:
Is it a clean design if i'm directly using the pointer of the server data
structures and treat them like a "data-handle" for the client? Some self-
written functions would operate on such "handles" and the server itself
also check's if the pointer's, which came from the clients, are valid
before using.
How can you know whether the pointers are valid? You can maybe check
that they don't point outside the program's address space (though this
is usually inconvenient and non-portable) but there's no way to know
that they actually point to an object of the desired type. A
malicious client might give you a pointer that points to something
totally different, that you don't want to mess with.
I know that different machines have different sizes for pointer's (int on
x86, ...) - but this doesn't matter, at least not for this project.
It's a question of time. I'm working on an existing, time-critical,
project and updates/bugfixes should be implemented as fast as possible.
But i don't wan't to produce unreadable code or security leaks.
Don't do this. It strikes me as dangerous and extremely ugly.
It should be quite simple to keep a table of your objects, with only
an index or key into the table being passed back and forth. It could
be a flat array, if there are a small number and you don't have to do
a lot of adding and deleting, or it could be something like C++'s
std::map. I bet it will take you less time to implement than it did
to write your post and read the replies.
.
- Follow-Ups:
- Re: Using pointers across several network clients
- From: David Schwartz
- Re: Using pointers across several network clients
- References:
- Using pointers across several network clients
- From: Andreas Wittmann
- Using pointers across several network clients
- Prev by Date: Re: Extracting data symbols from an archive using dlsym
- Next by Date: Re: select() question, avoiding blocks on read/write
- Previous by thread: Re: Using pointers across several network clients
- Next by thread: Re: Using pointers across several network clients
- Index(es):
Relevant Pages
|